I generate an OpenAPI
json from a Java REST service, in a class. It's method returns a java.util.Map
.
@Operation(description = "Retourne les communes du Code Officiel Geographique en vigueur une année particulière.")
@RequestMapping(value = "/communes", method=RequestMethod.GET)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Communes présentes sur le territoire cette année là, sous la forme d'une Map<String, Commune>.",
content = {@Content(schema = @Schema(implementation = Map.class))}
),
@ApiResponse(responseCode = "500", description = "Un incident est survenu durant l'extraction des communes.")
}
)
public Map<String, Commune> obtenirCommunes(
@Parameter(name = "anneeCOG", description = "Année du Code Officiel Géographique.", example = "2019")
@RequestParam(name="anneeCOG") int anneeCOG) throws TechniqueException {
CodeOfficielGeographique cog = this.cogService.obtenirCodeOfficielGeographique(this.session, anneeCOG);
return cog.getCommunesAsMap();
}
But the json produced doesn't describe a Map for return type for my method:
"/cog/communes":{
"get":{"tags":["cog-controller"],
"description":"Retourne les communes du Code Officiel Geographique en vigueur une année particulière.",
"operationId":"obtenirCommunes", "parameters":
[{"name":"anneeCOG","in":"query",
"description":"Année du Code Officiel Géographique.",
"required":true,"schema":{"type":"integer","format":"int32"},"example":2019}],
"responses":{"500":{"description":"Un incident est survenu durant l'extraction des communes.",
"content":{"*/*":{"schema":{"type":"object","additionalProperties":{"$ref":"#/components/schemas/Commune"}}}}},
"200":{"description":"Communes présentes sur le territoire cette année là, sous la forme d'une Map<String, Commune>.",
"content":{"*/*":{"schema":{"type":"string"}}}}}}}
instead, it returns a "schema":{"type":"string"}
.
What have I done wrong?
Is it the content = {@Content(schema = @Schema(implementation = Map.class))}
I have put along with responseCode = "200"
that is wrong?
Am I lacking an annotation?
This annotation was responsible of my trouble.
@ApiResponse(responseCode = "200", description = "Communes présentes sur le territoire cette année là, sous la forme d'une Map<String, Commune>.",
content = {@Content(schema = @Schema(implementation = Map.class))}
),
The content:
content = {@Content(schema = @Schema(implementation = Map.class))}
has to be removed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.