swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Enum values missing in OpenAPI 3.1 schema

Open jochenberger opened this issue 1 year ago • 2 comments

I'm using 2.2.28. I have the following classes:

    class Question {
        @ArraySchema(schema = @Schema(description = "The answer to the question"))
        public Set<Option> answer;
    }

    enum Option {
        A, B, C, D
    }

The OpenAPI 3 schema looks like this:

Question:
type: object
properties:
  answer:
    uniqueItems: true
    type: array
    items:
      type: string
      description: The answer to the question
      enum:
      - A
      - B
      - C
      - D

When I switch to OpenAPI 3.1, I get:

Question:
type: object
properties:
  answer:
    type: array
    items:
      description: The answer to the question
    uniqueItems: true

I can work around this by adding implementation = Option.class to the inner @Schema annotation, e.g. @ArraySchema(schema = @Schema(description = "The answer to the question", implementation = Option.class)).

jochenberger avatar Jan 17 '25 16:01 jochenberger

Probably related to #4802

jochenberger avatar Jan 17 '25 16:01 jochenberger

This seems to be specific to ArraySchema.

jochenberger avatar Jan 17 '25 16:01 jochenberger

If I omit the schema = @Schema(description = "The answer to the question"), the enum values are present. Still an issue in 2.2.34 btw.

jochenberger avatar Jul 31 '25 07:07 jochenberger

Hi @jochenberger! I’ve reviewed your PR and it does indeed restore enum and ref support in OAS 3.1 for ArraySchemas.
I have created a PR based on yours to confirm that your changes also fix the refs issue you had created earlier.

Thank you for your input!

ewaostrowska avatar Aug 07 '25 10:08 ewaostrowska

Is there any way to add the Bug label to existing issues? It looks as if the issue list could use some categorization.

jochenberger avatar Aug 19 '25 06:08 jochenberger

I fixed this in https://github.com/swagger-api/swagger-core/pull/4944.

jochenberger avatar Aug 25 '25 07:08 jochenberger