Bundling leads to self-referencing component schemas
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
@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).
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.
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.
@tatomyr I reassigned it to me as I have some progress on it already.
@RomanHotsiy what's the progress so far on this? and how can I help?
@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
Should be fixed in v1.0.0-beta.127.