Skip to content

allOf pulls in incorrect $ref value #1129

@owenconti

Description

@owenconti

Say we have two definitions: Pet and Cat. Cat extends Pet using the allOf function.

After swagger-js parses the spec, the resulting definition for Cat contains a $ref property with the value of PATH/Pet, instead of the expected value of PATH/Cat.

This results in swagger-ui displaying the wrong name and tooltips for models that were built using allOf, as seen in the screenshots below:

This screenshot shows the name of the model, and its $ref value. Note that the Cat model has an incorrect $ref value.

screen shot 2017-09-09 at 12 57 39 pm

This screenshot shows the incorrect value of the tooltip when hovering the Cat model name.

screen shot 2017-09-09 at 12 57 08 pm

This screenshot shows the incorrect name of the model and incorrect value of the tooltip for the Cat model, which is inside a oneOf option of the Animal model.

screen shot 2017-09-09 at 12 57 23 pm

The issue is happening with OAS 2.0 and OAS 3.0 specs.

openapi: 3.0.0
info:
  version: 0.0.0
  title: test
paths: {}
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
      required:
        - name
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            meowVolume:
              type: string
              enum:
              - loud
              - quiet
    Animal:
      type: object
      properties:
        pet:
          $ref: '#/components/schemas/Pet'
        cat:
          $ref: '#/components/schemas/Cat'
swagger: "2.0"
info:
  version: 0.0.0
  title: test
paths: {}
definitions:
  Pet:
    type: object
    properties:
      name:
        type: string
    required:
      - name
  Cat:
    allOf:
      - $ref: '#/definitions/Pet'
      - type: object
        properties:
          meowVolume:
            type: string
            enum:
            - loud
            - quiet
  Animal:
    type: object
    properties:
      pet:
        $ref: '#/definitions/Pet'
      cat:
        $ref: '#/definitions/Cat'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions