Skip to content

Override description for items in array schema #4802

Closed

Description

@jochenberger

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.

Activity

  1. jochenberger commented on Dec 4, 2024

    @jochenberger
    ContributorAuthor

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

  2. jochenberger commented on Dec 4, 2024

    @jochenberger
    ContributorAuthor

    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
  3. jochenberger commented on Dec 5, 2024

    @jochenberger
    ContributorAuthor

    See also #4753

  4. jochenberger commented on Dec 6, 2024

    @jochenberger
    ContributorAuthor

    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.

  5. jochenberger commented on Jan 17, 2025

    @jochenberger
    ContributorAuthor

    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.

  6. jochenberger commented on May 14, 2025

    @jochenberger
    ContributorAuthor

    Same result with 2.2.31.

  7. jochenberger commented on Jul 31, 2025

    @jochenberger
    ContributorAuthor

    Might be fixed with #4944

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions