Redocly / Redocly/redocly-cli

$ref recursive/indefinite resolving for examples

Open
#1,101 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

p3 Type: Bug
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Describe the bug
If

  • examples (in our case for responses) are added from a separate file with e.g.
        example:
          $ref: '../../dir/otherdir/example.data.get.json'
    
  • and those example responses themselves contain a $ref like
       {
              "field": {
                      "$ref": "https://www.some-url.dev/api/data?cursor=eyJvZmZzZXQiOjUwLCJsaW1pdCI6NTB9"
               }
       }
    

the bundle/lint also tries to resolve those references - which is basically wrong, as they are part of the response, not part of the spec!
In our case, with the pagination cursor being part of the response, that resulted in an (potentially indefinite) loop and the redocly-cli was requesting those API requests from our staging server, paginating over and over...

Note: using the configuration setting resolve.doNotResolveExamples: true does not help here, because it will then not embed our example response into the bundled file, because it resolves not even the first encountered $ref, wich is referring to our local example file.

Expected behavior
If a $ref in an example json file is encountered, do not try to resolve it.

Or: add a configuration like doNotRecursivelyResolveExamples or config something like recursiveExampleResolvingDepth: 1 to prevent that behaviour.

Additional context
Redocly cli version used: 1.0.0-beta.126

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 tracing how bundling and linting handle the local example reference and then nested $ref values in the example response. Compare this behavior with resolve.doNotResolveExamples and verify that the local example is embedded while nested response references are left untouched, without repeated requests or recursion.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.