swagger-api / swagger-api/swagger-ui

Rendering of references to properties depends on the order of clicks in the UI

Open
#10,444 0 comments 1 reaction 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
  • OS: macOS
  • Browser: chrome
  • Version: 136
  • Method of installation: npm
  • Swagger-UI version: 5.21.0
  • Swagger/OpenAPI version: 3.0
Content & configuration

I have a minimal spec to reproduce this behaviour. The spec contains a schema (Test) that is referencing another schema (TestRef). TestRef contains two properties; value which is just a simple type and valueRef which is referencing value.
Based on the order in which I expand the schemas in the UI, the UI produces different results.

I noticed this behaviour when using the swagger-ui-react library, but it can also be observed on https://editor.swagger.io and https://editor-next.swagger.io/.

Example Swagger/OpenAPI definition:

openapi: 3.0.4
info:
  version: 0.0.1
  title: Test
  description: Test
paths: {}
components:
  schemas:
    Test:
      $ref: "#/components/schemas/TestRef"
    TestRef:
      type: object
      properties:
        value:
          type: number
        valueRef:
          $ref: "#/components/schemas/TestRef/properties/value"

Swagger-UI configuration options:

SwaggerUI({
  spec=`<insert spec from above>`
})
Describe the bug you're encountering

When clicking on Test, the value property is rendered correctly as a number. But the valueRef property is not rendered as a number but instead just displays the reference, e.g. https://editor.swagger.io/#/components/schemas/TestRef/properties/value.

When instead clicking on TestRef and then clicking on Test, both properties are correctly rendered as number.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io
  2. Insert the example spec from above
  3. Reload the page
  4. Click on the schema Test
  5. Observe how valueRef is not rendered as a number
  6. Reload the page
  7. Click on the schema TestRef
  8. Click on the schema Test
  9. Observe how valueRef in rendered properly
Expected behavior

The behaviour of how refs are rendered should not depend on the order of clicks in the UI.

Screenshots

Behavior when clicking Test:
Click Test

Behavior when clicking TestRef and then Test:
Click TestRef then Test

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 with the minimal OpenAPI definition in the issue and reproduce the schema rendering sequence in Swagger UI: open Test first, then reload and open TestRef before Test. Trace how the UI resolves the property reference and add a regression check covering both click orders. Done means valueRef renders as number consistently rather than displaying the reference URL.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.