Skip to content

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

Open
@buzzerrookie

Description

@buzzerrookie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions