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

Bundling leads to self-referencing component schemas #290

Closed
glen-84 opened this issue May 5, 2021 · 7 comments · Fixed by #1080
Closed

Bundling leads to self-referencing component schemas #290

glen-84 opened this issue May 5, 2021 · 7 comments · Fixed by #1080
Assignees
Labels
p2 Type: Bug Something isn't working

Comments

@glen-84
Copy link

glen-84 commented May 5, 2021

Describe the bug

When using the bundle command, the schemas in components.schemas reference themselves, instead of being dereferenced.

Example from output:

components:
  schemas:
    User:
      $ref: '#/components/schemas/User'
    Country:
      $ref: '#/components/schemas/Country'
    Game:
      $ref: '#/components/schemas/Game'

To Reproduce

I don't have a small reproduction, as our API is large (28k lines when bundled using another tool).

I can send the spec on request, via a private channel.

Expected behavior

I expected the component schemas to be dereferenced.

Logs

n/a

OpenAPI definition

(see above)

openapi-cli Version(s)

1.0.0-beta.44

Node.js Version(s)

14.16.1

Additional context

n/a

@adamaltman
Copy link
Member

@glen-84 did you try the --dereferenced option? Besides that, this seems like a bug anyway.

https://redoc.ly/docs/cli/commands/#bundle

openapi bundle --dereferenced

It may be helpful if you can share your definition -- our email is team at redoc.ly (and please include a link to this issue).

@glen-84
Copy link
Author

glen-84 commented May 13, 2021

With --dereferenced I get:

Detected circular reference which can't be converted to JSON.

When using YAML, it completes without error, but the schemas seem to reference request and response values. This might be because of the way that our spec is structured: Paths reference separate files, the separate files reference separate files for schemas, and components.schemas references those same schemas. It may be the case that things would work better if components.schemas were bundled first, before paths, but I'm not sure.

I'm using swagger-parser for now, but I've emailed the spec in case it's useful.

Thanks.

@SusanneKrause
Copy link

I had the same issue. We currently try different ways to split and structure our YAML file.

In our case the problem was that we referenced a file with a list of definitions that also contains references.
For example in the main yaml the parameters section contains a reference to the file _index.yaml.

Snippet of main yaml

components:
  schemas:
    $ref: ./models/_index.yaml
  responses:
    $ref: ../common/models/responses.v1.yaml
  parameters:
    $ref: ./parameters/_index.yaml

The _index.yaml contains the list to all parameters with references to the respective parameter definition.
In the path definitions we reference to the parameter file e.g. /query-parameters.yaml#/modelId

Snippet of parameters/_index.yaml

modelId
  $ref: './query-parameters.yaml#/modelPKs'
startDate:
  $ref: './query-parameters.yaml#/startDate'
endDate:
  $ref: './query-parameters.yaml#/endDate'

Maybe this helps.

@RomanHotsiy
Copy link
Member

@tatomyr I reassigned it to me as I have some progress on it already.

@mauris
Copy link

mauris commented Apr 28, 2022

@RomanHotsiy what's the progress so far on this? and how can I help?

@adamaltman
Copy link
Member

@mauris I think the issue is with the invalid way to split the YAML file:

components:
  schemas:
    $ref: ./models/_index.yaml
  responses:
    $ref: ../common/models/responses.v1.yaml
  parameters:
    $ref: ./parameters/_index.yaml

See this issue for more details: #658

@tatomyr
Copy link
Contributor

tatomyr commented May 25, 2023

Should be fixed in v1.0.0-beta.127.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants