[英]A java method returning a java.util.Map generates a String return in openapi instead of a Map
I generate an OpenAPI
json from a Java REST service, in a class.我从 Java REST 服务中生成
OpenAPI
json,在 ZA2F2ED4F8EBC2CBB4C21A29 It's method returns a java.util.Map
.它的方法返回
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:但是生成的 json 没有描述 Map 用于我的方法的返回类型:
"/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"}
.相反,它返回一个
"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?是
content = {@Content(schema = @Schema(implementation = Map.class))}
我和responseCode = "200"
一起放错了吗?
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.必须删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.