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

Spec with nested use of allOf doesn't render example request properly #10236

Open
jessicasiu opened this issue Dec 9, 2024 · 0 comments
Open

Comments

@jessicasiu
Copy link

jessicasiu commented Dec 9, 2024

Q&A (please complete the following information)

  • OS: Windows
  • Browser: Chrome
  • Version: 131.0.6778.87
  • Method of installation: pnpm
  • Swagger-UI version: 5.18.2
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

Example yaml with issue:

openapi: 3.0.0
info:
  title: spec with issue
  version: 1.0
paths:
  /holidays/holidayEmployees:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/HolidayEmployee"
        required: true
      responses:
        "200":
          description: success
components:
  schemas:
    HolidayWorker:
      properties:
        holiday:
          type: string
          example: Christmas
    HolidayEmployee:
      required:
        - employee
      type: object
      allOf:
        - $ref: "#/components/schemas/HolidayWorker"
      properties:
        employee:
          allOf:
            - $ref: "#/components/schemas/Employee"
            - properties:
                relationship:
                  enum:
                    - Self
                  example: Self
    Employee:
      required:
        - lastName
      type: object
      allOf:
        - $ref: "#/components/schemas/Person"
    Person:
      type: object
      properties:
        firstName:
          type: string
          example: Santa
        lastName:
          type: string
          example: Claus

Example yaml with workaround:

openapi: 3.0.0
info:
  title: spec with workaround
  version: 1.0
paths:
  /holidays/holidayEmployees:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/HolidayEmployee"
        required: true
      responses:
        "200":
          description: success
components:
  schemas:
    HolidayWorker:
      properties:
        holiday:
          type: string
          example: Christmas
    HolidayEmployee:
      required:
        - employee
      type: object
      properties:
        employee:
          allOf:
            - $ref: "#/components/schemas/Employee"
            - properties:
                relationship:
                  enum:
                    - Self
                  example: Self
      allOf:
        - $ref: "#/components/schemas/HolidayWorker"
    Employee:
      required:
        - lastName
      type: object
      allOf:
        - $ref: "#/components/schemas/Person"
    Person:
      type: object
      properties:
        firstName:
          type: string
          example: Santa
        lastName:
          type: string
          example: Claus

Swagger-UI configuration options: nothing special in particular, it's reproducible at https://editor-next.swagger.io/

Describe the bug you're encountering

When using a yaml definition such as the one provided above, the rendered example value for the request doesn't display all of the example values. In the example yaml with issue, note that the schema HolidayEmployee uses the allOf keyword and then also has a property employee that uses allOf, which in turn is referencing Employee, which uses the allOf keyword to reference Person.

When HolidayEmployee is defined in this order, in the example value for the POST /holidays/holidayEmployees endpoint, firstName and lastName properties from the Person schema are missing. If HolidayEmployee is instead defined like in the yaml work workaround example, with the properties defined before using the allOf keyword, then the example value shown by SwaggerUI shows all of the values.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io/
  2. Paste the example yaml with issue from above
  3. Expand the POST /holidays/holidayEmployees endpoint
  4. Observe the example request value shown
  5. Paste the example yaml with workaround from above
  6. Expand the POST /holidays/holidayEmployees endpoint
  7. Observe the example request value shonw

Expected behavior

Expect the displayed example request value to look the same regardless of the order in which allOf and properties are defined.

Screenshots

Example request value using spec with issue
image

Example request value using spec with workaround
image

Additional context or thoughts

Although I've shown a workaround by reordering how the schema is defined, this isn't a viable workaround in our actual application because the spec we're displaying is generated in a way that we do not have control over. Since the definition is valid either way, we would expect the displayed example value to be the same in both cases.

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

No branches or pull requests

1 participant