swagger-api / swagger-api/swagger-ui

Rendering of nested objects break when using `allOf` in the main schema

Open
#8,374 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Windows/OSX/Ubuntu
  • Browser: Edge
  • Version: Version 109.0.1518.78 (Official build) (64-bit)
  • Method of installation: npm (but also happens in online editor)
  • Swagger-UI version: v4.15.5
  • Swagger/OpenAPI version: OpenApi 3.0.1
Content & configuration

Broken example Swagger/OpenAPI definition:

openapi: 3.0.1
info:
  title: Testapi
  version: v1
paths: {}
components:
  schemas:
    SubjectBase:
      type: object
      properties:
        naam:
          type: string
          nullable: true
    TestSubject:
      required:
        - $type
      type: object
      allOf:
        - $ref: '#/components/schemas/SubjectBase'
      properties:
        sum:
          allOf:
            - $ref: '#/components/schemas/PeriodicGegevenAmount'
          description: One time payment
          nullable: true
      additionalProperties: false
      description: Test class
      discriminator:
        propertyName: $type
    Percentage:
      required:
        - amount
      type: object
      properties:
        amount:
          maximum: 100
          minimum: -100
          type: number
          format: double
      additionalProperties: false
    Periodic:
      required:
        - $type
        - einddatum
        - ingangsdatum
      type: object
      properties:
        startdate:
          type: string
          format: date
        enddate:
          type: string
          format: date
      additionalProperties: false
      discriminator:
        propertyName: $type
    PeriodicAmount:
      required:
        - $type
      type: object
      allOf:
        - $ref: '#/components/schemas/Periodic'
      properties:
        factor:
          allOf:
            - $ref: '#/components/schemas/Percentage'
          nullable: true
      additionalProperties: false
      discriminator:
        propertyName: $type
    PeriodicGegevenAmount:
      required:
        - isWaardevast
        - periodieken
      type: object
      properties:
        periodieken:
          type: array
          items:
            $ref: '#/components/schemas/PeriodicAmount'
        isWaardevast:
          type: boolean
      additionalProperties: false
      description: The amount and period to which this amount applies

Working example Swagger/OpenAPI definition:

openapi: 3.0.1
info:
  title: Testapi
  version: v1
paths: {}
components:
  schemas:
    SubjectBase:
      type: object
      properties:
        naam:
          type: string
          nullable: true
    TestSubject:
      required:
        - $type
      type: object
      allOf:
        - $ref: '#/components/schemas/SubjectBase'
      properties:
        sum:
          allOf:
            - $ref: '#/components/schemas/PeriodicGegevenAmount'
          description: One time payment
          nullable: true
      additionalProperties: false
      description: Test class
      discriminator:
        propertyName: $type
    Percentage:
      required:
        - amount
      type: object
      properties:
        amount:
          maximum: 100
          minimum: -100
          type: number
          format: double
      additionalProperties: false
    Periodic:
      required:
        - $type
        - einddatum
        - ingangsdatum
      type: object
      properties:
        startdate:
          type: string
          format: date
        enddate:
          type: string
          format: date
      additionalProperties: false
      discriminator:
        propertyName: $type
    PeriodicAmount:
      required:
        - $type
      type: object
      allOf:
        - $ref: '#/components/schemas/Periodic'
      properties:
        factor:
          allOf:
            - $ref: '#/components/schemas/Percentage'
          nullable: true
      additionalProperties: false
      discriminator:
        propertyName: $type
    PeriodicGegevenAmount:
      required:
        - isWaardevast
        - periodieken
      type: object
      properties:
        periodieken:
          type: array
          items:
            $ref: '#/components/schemas/PeriodicAmount'
        isWaardevast:
          type: boolean
      additionalProperties: false
      description: The amount and period to which this amount applies
Describe the bug you're encountering

When using the first YAML which contains an allOf to SubjectBase in TestSubject you will need see the properties correctly when you open periodieken in sum (see also screenshot).

To reproduce...

Steps to reproduce the behavior:

  1. Go to 'https://editor.swagger.io/'
  2. Paste in the YAML
  3. Open the schema TestSubject and keep opening until you come across the property factor
  4. See that properties are not being rendered
Expected behavior

You should see the properties of nested objects like in the working screenshot.

Screenshots

Not working:
swagger-ui-factor-not-showing

Working:
swagger-ui-factor-showing

Additional context or thoughts

This might have broken before 4.15.5 . We recently got a new customer which was looking at the swagger and then we discovered it has broken. A year ago it still worked.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in https://editor.swagger.io/ by pasting the broken YAML and opening TestSubject through sum, periodieken, and factor. Trace the schema-rendering path for nested allOf references and compare it with the working YAML. Done means the nested object properties render in the broken example as they do in the working example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.