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

Override description for items in array schema #4802

Open
jochenberger opened this issue Dec 4, 2024 · 5 comments
Open

Override description for items in array schema #4802

jochenberger opened this issue Dec 4, 2024 · 5 comments
Labels
3.1 spec support Related to OpenAPI 3.1 Bug P3

Comments

@jochenberger
Copy link

jochenberger commented Dec 4, 2024

I'm using OpenAPI 3.1.

I have the following classes:

    class Street {
        @ArraySchema(schema = @Schema(implementation = House.class, description = "A house in a street"))
        public List<House> houses;
    }

    @Schema(description = "A house")
    class House {
        public String number;
    }

The generated YAML looks like this:

Street:
type: object
properties:
  houses:
    type: array
    items:
      $ref: "#/components/schemas/House"

House:
type: object
description: A house
properties:
  number:
    type: string

The description for the items is not included.

If I remove the implementation = House.class from the inner schema definition, I get

Street:
type: object
properties:
  houses:
    type: array
    items:
      description: A house in a street

House:
type: object
description: A house
properties:
  number:
    type: string

Now the description is there, but the $ref is gone.
I'd expect the item definition to contain both the $ref and the description in both cases.

@jochenberger
Copy link
Author

FTR, If I use OpenAPI 3.0, I only get the $ref in both cases, with and without the implementation = House.class.

@jochenberger
Copy link
Author

For single-valued properties, the description can be set.
For example,

    class Street {
        @Schema(description = "The elected leader")
        public Person spokesPerson;
    }

results in

Street:
type: object
properties:
  spokesPerson:
    $ref: "#/components/schemas/Person"
    description: The elected leader

@jochenberger
Copy link
Author

See also #4753

@jochenberger
Copy link
Author

jochenberger commented Dec 6, 2024

If seems to work if I use @ArraySchema(schema = @Schema(allOf = House.class, description = "A house in a street"))
I end up with

...
    type: array
    items:
      description: A house in a street
      allOf:
        - $ref: "#/components/schemas/House"

which is correct but unnecessarily complicated in OpenAPI 3.1.

@jochenberger
Copy link
Author

With 2.2.28, I get the correct result with @ArraySchema(schema = @Schema(implementation = House.class, description = "A house in a street")), but it still does not work without the implementation = House.class. I think that this should be determined by the library.

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 P3
Projects
None yet
Development

No branches or pull requests

2 participants