swagger-api / swagger-api/swagger-ui

Incorrect "Could not resolve reference" error displayed.

Open
#9,630 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
Content & configuration

I've reduced my large multi-file spec down to the bare minimum that demonstrates this issue:

Save as swagger_test.yaml:

openapi: 3.0.3
info:
  version: 1.0.0
  title: Title

paths:
  "/path1":
    $ref: './swagger_test_path1.yaml#/paths/%2Fpath1'

  "/path2":
    $ref: './swagger_test_path2.yaml#/paths/%2Fpath2'

Save as swagger_test_path1.yaml:

openapi: 3.0.3
info:
  version: 1.0.0
  title: Title

paths:
  "/path1":
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rsp:
                  $ref: './swagger_test_schemas.yaml#/components/schemas/WSPath1Response'

      responses:
        204:
          description: Success

Save as swagger_test_path2.yaml:

openapi: 3.0.3
info:
  version: 1.0.0
  title: Title

paths:
  "/path2":
    get:
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: "#/components/schemas/WSResult"

    delete:
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    $ref: "#/components/schemas/WSResult"

components:
  schemas:
    WSResult:
      type: object
      properties:
        details:
          $ref: './swagger_test_schemas.yaml#/components/schemas/WSResultDetails'

Save as swagger_test_schemas.yaml:

openapi: 3.0.3
info:
  version: 1.0.0
  title: Title
paths: {}

components:
  schemas:
    WSBaseResultDetails:
      type: object
      properties:
        info:
          type: string

    WSResultDetails:
      allOf:
        - $ref: "#/components/schemas/WSBaseResultDetails"
        - type: object
          properties:
            status:
              $ref: "#/components/schemas/WSStatus"

    WSStatus:
      type: object
      properties:
        text:
          type: string

    WSPath1Response:
      type: object
      properties:
        data:
          type: string
Describe the bug you're encountering

image

The spec renders correctly, but the above errors are reported.

Note that if I change the openapi version to 3.1, these errors are not displayed. However, the render time of my large multi-file spec is about 6 seconds when specifying openapi 3.0.3, but about 2.5 minutes when specifying openapi 3.1, so moving to 3.1 is not practical at this point.

To reproduce...

Open swagger_test.yaml defined above using swagger-ui 5.11.7

Expected behavior

References are resolved and spec is rendered correctly, so "Unresolved reference" errors should not be displayed.

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 loading swagger_test.yaml and its three referenced YAML files in Swagger UI 5.11.7 with OpenAPI 3.0.3, then compare the reported errors with the correctly rendered specification. Trace the reference-resolution path used for encoded path fragments and nested external references. Done means the specification renders without incorrect unresolved-reference errors while retaining the expected behavior for OpenAPI 3.1.

Written by the indexing model from the issue text.

Assessment

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