Skip to content

fix: output for recursive refs - #229

Merged
AlexVarchuk merged 1 commit into
mainfrom
fix/recursive-refs-output
Oct 21, 2026
Merged

AlexVarchuk merged 1 commit into
mainfrom
fix/recursive-refs-output

Conversation

@AlexVarchuk

Copy link
Copy Markdown
Contributor

What/Why/How?

Fixes a regression from 1.7.8: a recursive $ref inside allOf was sampled as null instead of {}. It happens in OpenAPI 3.0 and 3.1.

openapi: 3.0.0
components:
  schemas:
    MenuItem:
      type: object
      properties:
        name:
          type: string
        friend:
          allOf:
            - $ref: '#/components/schemas/MenuItem'

Sample of MenuItem:

Version Result
1.7.6 { "name": "string", "friend": { "name": "string", "friend": {} } }
1.7.8 { "name": "string", "friend": { "name": "string", "friend": null } }

In 1.7.8, allOf passes a $ref item to traverse as the same object each time, so the identity-based cycle check catches it before the $ref cycle check runs. Since inferType({ $ref }) has no type, the result is null. Passing a copy ({ ...subSchema }) restores the $ref cycle check, which returns {}. The 1.7.8 change stays: no type is added to $ref items.

Reference

Found by the Redoc visual e2e test in https://github.com/Redocly/redocly/pull/30990

Testing

  • New test: a recursive $ref inside allOf samples as {} in OpenAPI 3.0 and 3.1.
  • Compared against 1.7.6 on 38 real specs (10,002 samples): identical with every spec forced to 3.0; with real versions only the intended $ref sibling changes remain.

Check yourself

  • Code is linted
  • Tested
  • All new/updated code is covered with tests

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@AlexVarchuk
AlexVarchuk marked this pull request as ready for review October 20, 2026 07:25
@AlexVarchuk
AlexVarchuk requested a review from a team as a code owner October 20, 2026 07:25
@AlexVarchuk
AlexVarchuk merged commit 801792b into main Oct 21, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants