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

No way to specify a SchemaType.ARRAY items example schema #445

Open
tiagomistral opened this issue Sep 4, 2020 · 1 comment
Open

No way to specify a SchemaType.ARRAY items example schema #445

tiagomistral opened this issue Sep 4, 2020 · 1 comment
Labels

Comments

@tiagomistral
Copy link

tiagomistral commented Sep 4, 2020

..unless Im missing something.

I want to configure the example that will be present in an array.
As in the case below I want the example to be 'MONDAY':

components:
  schemas:
    Pojo:
      properties:
        weekDays:
          type: array
          description: |-
            Restriction week days.
            Values - [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]
          items:
            type: string
            example: "MONDAY"

To achieve this I try:

@JsonbProperty("weekDays")
@Schema(name="weekDays", type = SchemaType.ARRAY, implementation = String.class,  example = "MONDAY",
            description="Restriction week days.\nValues - [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY]")
private Set<DayOfWeek> weekDays = Collections.emptySet();

But the example is not at the item level as I need it, but at the weekDays property level.

How can I generate an items example?

Azquelt pushed a commit to Azquelt/microprofile-open-api that referenced this issue Mar 17, 2022
Maven plugin for SmallRye Open API
@MikeEdgar
Copy link
Member

Something like this should work.

@Schema(name = "DayOfWeek", example = "MONDAY")
enum DayOfWeek {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

@Schema(name = "Pojo")
class Pojo {
    Set<DayOfWeek> weekDays;
}

When using the SmallRye OpenAPI implementation the resulting schemas look like this:

"components" : {
  "schemas" : {
    "DayOfWeek" : {
      "enum" : [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY" ],
      "type" : "string",
      "example" : "MONDAY"
    },
    "Pojo" : {
      "type" : "object",
      "properties" : {
        "weekDays" : {
          "uniqueItems" : true,
          "type" : "array",
          "items" : {
            "$ref" : "#/components/schemas/DayOfWeek"
          }
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants