无法呈现此定义。提供的定义未指定有效的版本字段。
请指出有效的Swagger或OpenAPI版本字段。支持的版本字段是大写字母:“ 2.0”以及与openapi相匹配的字段:3.0.n(例如,openapi:3.0.0)。
我需要在哪里插入正确的版本来停止以下错误。Swagger编辑器工作正常,但是在启动特定项目时收到此错误。非常感谢
我从 Springfox Swagger 迁移到 Springdoc OpenApi。我在有关 springdoc 的配置中添加了几行:
springdoc:
pathsToMatch: /api/**
api-docs:
path: /api-docs
swagger-ui:
path: /swagger-ui.html
Run Code Online (Sandbox Code Playgroud)
在配置类中MainConfig.kt我有以下代码:
val customGson: Gson = GsonBuilder()
.registerTypeAdapter(LocalDateTime::class.java, DateSerializer())
.registerTypeAdapter(ZonedDateTime::class.java, ZonedDateSerializer())
.addSerializationExclusionStrategy(AnnotationExclusionStrategy())
.enableComplexMapKeySerialization()
.setPrettyPrinting()
.create()
override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
converters.add(GsonHttpMessageConverter(customGson))
}
Run Code Online (Sandbox Code Playgroud)
当我访问 http://localhost:8013/swagger-ui.html (在我的配置中server.port: 8013)时,页面不会重定向到swagger-ui/index.html?url=/api-docs&validatorUrl=. 但这不是我的主要问题:)。当我访问时,swagger-ui/index.html?url=/api-docs&validatorUrl=我得到了包含以下信息的页面:
无法呈现此定义 提供的定义未指定有效的版本字段。 请指明有效的 Swagger 或 OpenAPI 版本字段。支持的版本字段包括 swagger: "2.0" 和那些匹配 openapi: 3.0.n 的字段(例如 openapi: 3.0.0)。
但是当我访问 http://localhost:8013/api-docs 时,我得到了这个结果:
"{\"openapi\":\"3.0.1\",\"info\":{(...)}}"
Run Code Online (Sandbox Code Playgroud)
我尝试使用默认配置,并评论了configureMessageConverters()方法,结果\api-docs现在看起来像正常的 JSON:
Unable to render this …