Skip to content

Conversation

@vadyvas
Copy link
Contributor

@vadyvas vadyvas commented Oct 28, 2025

What/Why/How?

What: Stop resolving $ref inside Examples.value and dataValue (oas3.2) during bundling. Only resolve when the Example itself is a Reference Object, not when a $ref appears inside the literal value.
Why: Per OpenAPI spec and Redocly refs guide, Examples.value must be treated literally; resolving $ref there is incorrect.

openapi: 3.2.0
info:
  title: Test API
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                example:
                  $ref: example.json # should resolve
              examples:
                Test:
                  value:
                    $ref: example.json # should NOT resolve

Reference

Fixes #1371

Testing

Added new unit and e2e tests

Screenshots (optional)

Check yourself

  • Code changed? - Tested with Redoc/Realm/Reunite (internal)
  • All new/updated code is covered by tests
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update considered

Security

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

🦋 Changeset detected

Latest commit: 2374fda

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch
@redocly/respect-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

Command Mean [s] Min [s] Max [s] Relative
redocly lint resources/rebilly.yaml 1.438 ± 0.017 1.412 1.465 1.01 ± 0.02
redocly-next lint resources/rebilly.yaml 1.427 ± 0.020 1.395 1.464 1.00

@vadyvas vadyvas marked this pull request as ready for review October 28, 2025 13:41
@vadyvas vadyvas requested review from a team as code owners October 28, 2025 13:41
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 78.78% (🎯 78%) 5849 / 7424
🟢 Statements 78.21% (🎯 78%) 6044 / 7727
🟢 Functions 81.88% (🎯 81%) 1202 / 1468
🟢 Branches 71.05% (🎯 70%) 4050 / 5700
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/types/index.ts 97.29% 92.3% 100% 97.29% 122
packages/core/src/types/oas3.ts 75.36% 31.81% 66.66% 75.36% 342, 349, 458-461, 492-516
packages/core/src/types/oas3_2.ts 52% 0% 0% 52% 39-126
Generated in workflow #7985 for commit 2374fda by the Vitest Coverage Report Action

@vadyvas vadyvas force-pushed the fix/examples-value-ref-resolution branch from d3789e6 to cfe2086 Compare October 30, 2025 14:01
@vadyvas vadyvas force-pushed the fix/examples-value-ref-resolution branch from a391a25 to 84cdccb Compare November 4, 2025 16:40
"@redocly/openapi-core": patch
---

Fixed an issue where the content of `$ref`s inside `Examples.value` was erroneously resolved during bundling and linting.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fixed an issue where the content of `$ref`s inside `Examples.value` was erroneously resolved during bundling and linting.
Fixed an issue where the content of `$ref`s inside example values was erroneously resolved during bundling and linting.

@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also affects the CLI behaviour, so please mention it here as well.

- doNotResolveExamples
- boolean
- When running `lint`, set this option to `true` to avoid resolving `$ref` fields in examples. Resolving `$ref`s in other parts of the API is unaffected.
- Set this option to `true` to prevent resolving `$ref` fields in `Example`. This affects both `lint` and `bundle` commands. Resolving `$ref`s in other parts of the API description is unaffected.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't affect the Example type, only singular example properties.

type: boolean
description: >-
You can stop `lint` from resolving `$refs` in examples by setting this configuration option to `true`.
Set this option to `true` to prevent resolving `$ref` fields in `Example`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@vadyvas vadyvas force-pushed the fix/examples-value-ref-resolution branch from 8c79eb4 to 0e4303b Compare November 6, 2025 10:43
Comment on lines 15 to 20
id:
type: integer
name:
type: string
active:
type: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id:
type: integer
name:
type: string
active:
type: boolean
$ref:
type: string

@@ -0,0 +1,4 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove plz.

@vadyvas vadyvas force-pushed the fix/examples-value-ref-resolution branch from 0e4303b to 2374fda Compare November 7, 2025 17:33
@vadyvas vadyvas merged commit bc7ebb1 into main Nov 7, 2025
45 of 46 checks passed
@vadyvas vadyvas deleted the fix/examples-value-ref-resolution branch November 7, 2025 17:41
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.

Redocly CLI incorrectly resolves $refs in examples

4 participants