Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Schema is processed without enum when implementation and allowableValues exist at the same time #4711

Open
buzzerrookie opened this issue Jul 18, 2024 · 0 comments · May be fixed by #4712
Open
Assignees

Comments

@buzzerrookie
Copy link

I'm using springdoc in a spring boot application. I have a controller method which its only parameter is annotated with @Schema(implementation = String.class, allowableValues = {"foo", "bar"})
When I check /v3/api-docs, I found there was no enum field for the test parameter in /test endpoint. I did some debugging into the source code and found there may be a bug in the getSchema method in AnnotationsUtils class of module swagger-core-jakarta.
At line 1719, the method resolveSchemaFromType returns a StringSchema without enum, maybe an additional condition schemaAnnotation.allowableValues().length != 0 should be checked.

{ "openapi": "3.0.1", "info": { "title": "OpenAPI definition", "version": "v0" }, "servers": [ { "url": "http://localhost:9090", "description": "Generated server url" } ], "paths": { "/test": { "post": { "tags": [ "hello-controller" ], "summary": "Test schema", "operationId": "test", "parameters": [ { "name": "test", "in": "query", "description": "test request parameter", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "OK", "content": { "*/*": { "schema": { "type": "string" } } } } } } }, "/test2": { "post": { "tags": [ "hello-controller" ], "summary": "Test2 schema", "operationId": "test2", "parameters": [ { "name": "test", "in": "query", "description": "test request parameter", "required": true, "schema": { "type": "string", "enum": [ "foo", "bar" ] } } ], "responses": { "200": { "description": "OK", "content": { "*/*": { "schema": { "type": "string" } } } } } } } }, "components": {} }
Demo application:
springdoc-demo.zip

Spring Boot: 3.3.1
springdoc-openapi-starter-webmvc-ui: 2.6.0
swagger-core-jakarta: 2.2.22

buzzerrookie added a commit to buzzerrookie/swagger-core that referenced this issue Jul 18, 2024
@buzzerrookie buzzerrookie linked a pull request Jul 18, 2024 that will close this issue
@micryc micryc self-assigned this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants