Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve reference if used more than once #221

Open
carlosli888 opened this issue May 12, 2023 · 4 comments
Open

Unable to resolve reference if used more than once #221

carlosli888 opened this issue May 12, 2023 · 4 comments

Comments

@carlosli888
Copy link

Description

I am encountering errors in the OpenAPI SwaggerUI preview if any schema references another schema more than once. What I mean is if I have more than one property that references the same schema file, I get a Resolver error because it is unable to resolve the reference.

version

4.16.6

OpenAPI file(s)
# openapi.yaml
openapi: 3.0.2  
info:
  title: API Test
  version: 0.1.0
servers: 
  - url: 'https://localhost:3000/api/v1'

paths:
  /test:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: ./product-line.yaml
# product-line.yaml
title: Product Line
type: object
properties:
  gen1:
    $ref: ./widget.yaml
  gen2:
    $ref: ./widget.yaml
# widget.yaml
title: Widget
type: object
properties:
  id: 
    type: string
    format: uuid
  name: 
    type: string
required:
  - id
  - name
Steps to reproduce
  1. Create the 3 yaml files containing the content above.
  2. Open VSCode with the OpenAPI (Swagger) Editor installed (v4.16.6).
  3. Open the folder containing the 3 files from step 1.
  4. Select the openapi.yaml file.
  5. Open the API Preview (e.g., Shift+Alt+P).
  6. Notice that no errors are shown.
  7. Expand the Product Line schema.
  8. Notice that the top of the preview has Resolver error.
  9. Attempt to expand the second property (i.e., gen2).
  10. Notice that it is unable to render the referenced schema even if it is the same one as the first (gen1) property.
Additional Info

If only one of gen1 or gen2 properties are defined, then it works fine. The example and reproduction shown is a simplified example. This issue was initially discovered with a more complicated setup that also made use of oneOf. This means that the reference does not have to appear in the same file. It can appear anywhere in the tree. For example:

  • We want to look at the schema for a geometry.
  • The geometry type is described in a geometry.yaml file and uses oneOf to indicate that it can be either a point, line, or polygon. Each of those types of shapes are defined in their own respective files.
  • Each shape is defined using position to represent the vertices. The position is defined in its own file.
  • Because the position type is indirectly referenced multiple times, the same resolver error is encountered.
@ak1394
Copy link
Collaborator

ak1394 commented May 12, 2023

Thanks for your feedback, and especially for providing the detailed example. I'll update the ticket once there is ETA for a fix.

@houserx-austin
Copy link

I am running into the same issue. I am on version 4.21.1. Any updates here?

@mayorovp
Copy link

Same issue on v4.25.1.
Is there any progress? Preview is unusable now.

@ak1394
Copy link
Collaborator

ak1394 commented Apr 10, 2024

There is no update on this unfortunately. We expect to do a next release, probably some time this month and once we done with it I might have time to look at this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants