swagger-api / swagger-api/swagger-ui

Using $ref to refer to a parameter under a path item object does not work

Open
#5,249 4 comments 4 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: Ubuntu 18.04.1 LTS
  • Browser: Chrome, Firefox
  • Swagger-UI version: 3.20.6
  • Swagger/OpenAPI version: OpenApi 3.0
Content & configuration

In openapi.yaml:

...
paths:
  /v1/users/{userId}:
    $ref: ./paths/user.yaml

In paths/user.yaml:

parameters:
  - $ref: ../components/parameters/UserId.yaml
put:
  requestBody:
    $ref: ../components/requestBodies/PutUser.yaml
  responses:
    '201':
      $ref: ../components/responses/UserPutResponse.yaml

get:
  responses:
    '200':
      $ref: ../components/responses/User.yaml

In components/parameters/UserId.yaml:

name: userId
in: path
required: true
description: A user's user id.
schema:
  type: string

It displays fine if placed as a parameter directly under the operation in paths/user.yaml:

put:
  parameters:
    - $ref: ../components/parameters/UserId.yaml
...

It also displays fine if the Path Item Object has not been imported. In openapi.yaml:

...
paths:
  /v1/users/{userId}:
    parameters:
      - $ref: ./components/parameters/UserId.yaml
    put:
      requestBody:
        $ref: ./components/requestBodies/PutUser.yaml
      responses:
        '201':
          $ref: ./components/responses/UserPutResponse.yaml
    get:
      responses:
        '200':
          $ref: ./components/responses/User.yaml
Describe the bug you're encountering

Path parameters do not show up if imported as part of a Path Item Object if that Path Item Object has itself been imported via $ref.

Path parameters do show up when placed in a Path Item Object if it is not $refed, or if it is in an Operation object.

No error is appearing in the console or at the top of the page. However, I can make an error appear by changing the $ref: to point to ../components/nonsense/UserId.yaml, implying that the issue is not an inability to find the correct file.

Expected behavior

Parameters should display correctly in all cases:

  • When placed directly in a Path Item Object
  • When imported via $ref in a Path Item Object
  • When placed directly in an Operation object
  • When imported via $ref in an Operation

Currently all but the second bullet point works.

Screenshots

image

Additional context or thoughts

Possibly related to #641?

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

Start by reproducing the issue with the OpenAPI 3.0 files shown in openapi.yaml, paths/user.yaml, and components/parameters/UserId.yaml, then trace Swagger UI's handling of nested Path Item Object $refs. Done means the UserId path parameter renders when the Path Item Object itself is imported, while the existing direct and operation-level cases continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.