如何解决springdoc-openapi:当枚举来自生成的代码时发布枚举作为参考
我正在使用
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
</dependency>
用于通过 openapi-specs 生成客户端存根并生成我自己的 openapi 文档。
我确实有一个 API,姑且称之为 API-1,我在我的项目中使用它。
这个 API 确实提供了一个枚举,简化了这个:
@Schema(enumAsRef=true)
public enum SomethingEnum {
A,B,C
}
API 确实提供了一个 openapi 规范,其中枚举被包含为架构并被引用。没关系。
我在 API-2 中使用的这个枚举。我让 API-1 中的所有模型都使用 openapi-generator-maven-plugin 生成。
API-2 确实提供了一个 openapi 规范,它看起来像这样简化:
{
"paths": {
"/request": {
"get": {
"tags": [
"requests"
],"operationId": "getSomething","responses": {
"200": {
"description": "OK","content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Something"
}
}
}
}
}
}
}
},"schemas": {
"Something": {
"type": "object","properties": {
"somethingEnum": {
"type": "array","items": {
"type": "string","enum": [
"A","B","C"
]
}
},"id": {
"type": "string"
}
}
}
}
}
这里是问题所在:SomethingEnum 不是通过架构引用的。 它应该看起来像这样:
{
"paths": {
"/request": {
"get": {
"tags": [
"requests"
],"properties": {
"SomethingEnum ": {
"$ref": "#/components/schemas/SomethingEnum "
},"id": {
"type": "string"
}
}
},"SomethingEnum": {
"type": "string","enum": [
"A","C",]
}
}
}
我怎样才能做到这一点?有没有办法
- 将 openapi-generator-maven-plugin 配置为使用
@Schema(enumAsRef=true)
自动注释生成的枚举 - 以某种方式配置 springdoc ?
我希望我的问题很清楚。感谢您的每一个建议。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。