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

Activity

added a commit that references this issue on Jul 18, 2024

fix swagger-api#4711: check allowableValues for enum

6a591f2
self-assigned this
on Sep 11, 2024
removed their assignment
on Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @buzzerrookie@micryc

      Issue actions

        @Schema is processed without enum when implementation and allowableValues exist at the same time · Issue #4711 · swagger-api/swagger-core