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

BUG @Schema annotation is propagated from a property to the class defined in @Schema#implementation #4800

Open
OllieKosh opened this issue Nov 28, 2024 · 0 comments
Labels
3.1 spec support Related to OpenAPI 3.1 Bug P2

Comments

@OllieKosh
Copy link

OllieKosh commented Nov 28, 2024

Problem

When Schema#implementation is defined on a property, all information specified through @Schema is propagated to the schema created for the type defined in Schema#implementation. However this information should only be used when generating the property schema. I am using Open API 3.1. This problem was introduced after upgrading from 2.2.22 to 2.2.25.

Expected behavior

@Schema annotation is processed on the property level, but not used in schema generation for the class specified in Schema#implementation of that property.

For example if I have the following DTO

public class Example {
    @Schema(implementation = MyEnum.class, description = "My description", defaultValue = "yes")
    private String whyYes;
    //getters, setters
}

and MyEnum class looks like this

enum MyEnum {
    yes, no
}

the generated contract for the two components is expected to look like this

  schemas:
    Example:
      type: object
      properties:
        whyYes:
          description: My description
          $ref: "#/components/schemas/MyEnum"
          default: "yes"
    MyEnum:
      type: `string`
      enum:
      - "yes"
      - "no"

However current behavior propagates the schema annotation (and the properties from that schema annotation, in this case description and defaultValue) to the underlying object, which is incorrect

  schemas:
    Example:
      type: object
      properties:
        whyYes:
          description: My description
          $ref: "#/components/schemas/MyEnum"
          default: "yes"
    MyEnum:
      type: string
      description: My description
      default: "yes"
      enum:
      - "yes"
      - "no"

Note that if @Schema#implementation was not specified this problem would not occur.

Reproducer

Add something similar to the provided example above (if using enum, set enums to be resolved as references) to this test class (which was created to test the solutions for this issue).

Investigation

While previously @Schema and @ArraySchema annotations were not added to the annotation list, which is then added to the type of the property to be processed, this change introduced the behavior where it actually gets added to the list of annotations which are passed to the underlying object. This does not seem to be the right solution, since the class for the property should be agnostic of the @Schema/@ArraySchema annotations on the field where it is used.

@OllieKosh OllieKosh changed the title BUG @Schema annotation is propagated to the class of the field on which it is annotated when @Schema#implementation is defined BUG @Schema annotation is propagated from a property to the class defined in @Schema#implementation Nov 28, 2024
@ponelat ponelat added P2 3.1 spec support Related to OpenAPI 3.1 Bug labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.1 spec support Related to OpenAPI 3.1 Bug P2
Projects
None yet
Development

No branches or pull requests

2 participants