question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundling leads to self-referencing component schemas

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
adamaltmancommented, Apr 28, 2022

@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

2reactions
SusanneKrausecommented, May 14, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema Bundling Finally Formalised
Existing tooling developers have created their own approaches to bundling JSON Schema and OpenAPI documents, but that can lead to errors.
Read more >
Unify reference and bundling behavior with JSON Schema #649
An alternative to the first point could be to only port the bundling behavior from JSON Schema and skip referencing one.
Read more >
Only You Can Bring Modern OpenAPI Bundling to JavaScript
Seeing as OpenAPI v3. 1 and JSON Schema are now entirely compatible, this means OpenAPI has inherited that standardized bundling method. All ...
Read more >
Structuring a complex schema — Understanding JSON ...
Let's assume a schema is referenced using the URI https://example.com/schemas/address and the following schema is retrieved. { "type": "object", "properties" ...
Read more >
Bundle - FHIR v5.0.0-cibuild
"$ref": "Meta.schema.json#/definitions/Meta" }, "implicitRules": { "description": "A reference to a set of rules that were followed when the resource was ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found