我正试图从@RequestMapping("/api/object/")
public interface IObjectController {
@RequestMapping(path = "v1/{param}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.OK)
ObjectDto getObjectByParamV1(@PathVariable("param") String code);
}
(OpenAPI 2)迁移到springfox-swagger2
(OpenAPI 3),以生成庞大的文档。
这是示例路线:
springdoc
Swagger生成在Null key for a Map not allowed in JSON (use a converting NullKeySerializer?)
(through reference chain: io.swagger.v3.oas.models.OpenAPI["paths"]->
io.swagger.v3.oas.models.Paths["/api/object/v1/{param}"]->io.swagger.v3.oas.models.PathItem["get"]->
io.swagger.v3.oas.models.Operation["responses"]->io.swagger.v3.oas.models.responses.ApiResponses["null"])
上工作得很好,但是在responses: class ApiResponses {
{null=class ApiResponse {
description: default response
headers: null
content: class Content {
{*/*=class MediaType {
schema: class ComposedSchema {
class Schema {
type: null
format: null
$ref: null
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
allOf: null
anyOf: null
oneOf: [class Schema {
type: object
format: null
$ref: null
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}, class StringSchema {
class Schema {
type: string
format: null
$ref: null
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
}]
}
examples: null
example: null
encoding: null
}}
}
links: null
extensions: null
$ref: null
}, 200=class ApiResponse {
description: OK
headers: null
content: class Content {
{application/json=class MediaType {
schema: class Schema {
type: null
format: null
$ref: #/components/schemas/ObjectDto
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
examples: null
example: null
encoding: null
}}
}
links: null
extensions: null
$ref: null
}}
extensions: null
}
下却遇到了以下问题:
ApiResponse
实际上,OpenAPI尝试序列化以下对象:
ApiResponses
如您所见,null
中有一个空的MapSerializer.serialize()
对象,它奇怪地具有一个// What is this _suppressNulls ?!
// _suppressableValue IS null, but is not suppressed
if ((_suppressableValue != null) || _suppressNulls) {
serializeOptionalFields(value, gen, provider, _suppressableValue);
}
键,然后序列化在jackon的@Operation
中失败了:
@ApiResponse
无论我使用了多少Swagger注释(null
,添加suppressNull
...),此MapSerializer.serializeOptionalFields()
ApiResponse仍然存在。我不明白这是从哪里来的,特别是null
仅影响值,而不影响键。
如何删除此{{1}}键的ApiResponse?
答案 0 :(得分:4)
原因似乎是在异常处理程序上@ExceptionHandler上没有@ResponseStatus。
解决方法是添加以便在招摇的文档中显示它。
已经存在的问题已得到解决:
此修复程序将在v1.3.8上可用。
答案 1 :(得分:-1)
使用v1.3.4似乎对我来说很好。我当时使用的是v1.3.3,升级到最新的v1.3.7时遇到了麻烦。
我认为罪魁祸首是https://github.com/springdoc/springdoc-openapi/issues/597的解决方法