I'm using
<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>
For generating client-stubs via openapi-specs and generating my own openapi docoumentation.
I do have an API, lets call it just API-1, which I'm using within my project.
This API does provide an enum, simpfified this one:
@Schema(enumAsRef=true)
public enum SomethingEnum {
A,
B,
C
}
API one does provide an openapi-specification, there the enum is included as schema and referenced. That is all fine.
This enum I'm using in API-2. I let all models from API-1 generate with the openapi-generator-maven-plugin.
API-2 does provide an openapi specification, which looks simplified like this:
{
"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"
}
}
}
}
}
And here is the problem: The SomethingEnum is not referenced via an Schema.
It should rather look like this:
{
"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 ": {
"$ref": "#/components/schemas/SomethingEnum "
},
"id": {
"type": "string"
}
}
},
"SomethingEnum": {
"type": "string",
"enum": [
"A",
"B",
"C",
]
}
}
}
How can I achieve this? Is there a way I can either
- configure the openapi-generator-maven-plugin to annote generated enums automatically with
@Schema(enumAsRef=true)
- configure springdoc somehow
?
I hope my problem is clear. Thanks for every suggestion.
question from:
https://stackoverflow.com/questions/65847832/springdoc-openapi-publish-enum-as-reference-when-enum-comes-from-generated-code