swagger-api / swagger-api/swagger-ui

Issue with rendering allOf when components is defined before paths

Open
#8,291 1 comment 2 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: macOS
  • Browser:chrome
  • Version: 107.0.5304.87
  • Method of installation: dist assets
  • Swagger-UI version: 4.15.5
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Example Swagger/OpenAPI definition:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
servers:
  - url: /
    
components:
  schemas:
    Pet:
      allOf:
        - $ref: '#/components/schemas/createPet'
      required:
        - id
      properties:
        id:
          type: integer
    createPet:
      required:
        - name
      properties:
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
  responses:
    listPets:
      description: An array of pets
      content:
        application/json:    
          schema:
            $ref: "#/components/schemas/Pets"
    getPet:
      description: An array of pets
      content:
        application/json:    
          schema:
            $ref: "#/components/schemas/Pet"

paths:
  /pets:
    get:
      summary: List all pets
      responses:
        '200':
          "$ref": "#/components/responses/listPets"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          "$ref": "#/components/responses/getPet"

Swagger-UI configuration options:

  window.ui = SwaggerUIBundle({
    url: "http://url.com/swagger.json",
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  });
Describe the bug you're encountering

When the paths key is defined after the components key, the allOf $ref properties are not rendered properly

To reproduce...

Steps to reproduce the behavior:

  1. Go to 'swagger editor'
  2. Paste in example YAML
  3. Open /pets
  4. See that only the id field is visible
Expected behavior

All the fields of the $ref should be visible

Screenshots

image

Should be:
image

Additional context or thoughts

This issue is also defined in #5194 and should be fixed in an older version, but seems to be broken (again)?

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 Swagger Editor using the provided OpenAPI YAML, then compare rendering when components appears before paths versus after it. Trace Swagger UI's allOf and $ref rendering or resolution entry points; done means the /pets response displays both the inherited name and tag fields as well as id.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.