Skip to content

Recursive $refs in example not resolving #2472

@lorenzo-arena

Description

@lorenzo-arena

Describe the bug

I'm trying to define and reuse some "example" defined in yaml files for multiple models, but redocly doesn't seems to resolve them correctly.

To Reproduce

Consider this openapi.yaml file:

openapi: 3.0.0
info:
  title: Test device API
  version: "0.0.1"
  description: |
    This is a test description.

servers:
  - url: /
    description: Server

paths:
  /test:
    get:
      tags:
        - Test
      summary: Test endpoint
      operationId: getTest
      responses:
        "200":
          description: The test response
          content:
            application/json:
              schema:
                $ref: ./TestSchema.yaml
              example:
                $ref: ./TestSchemaExample.yaml

components:
  schemas:
    TestSchema:
      $ref: ./TestSchema.yaml

TestSchema.yaml

type: object
properties:
  testField:
    $ref: ./TestField.yaml
  anotherField:
    $ref: ./AnotherField.yaml

TestField.yaml

type: string
description: Test String
example: "Test"

AnotherField.yaml

type: string
description: Test String
example: "Another"

I'd like to define

TestSchemaExample.yaml

testField:
  $ref: ./TestFieldExample.yaml
anotherField: "AnotherExample"

TestFieldExample.yaml

"Test"

Running

$ redocly bundle openapi.yaml --output dist/openapi.yaml --ext yaml

Results in

openapi: 3.0.0
info:
  title: Test device API
  version: 0.0.1
  description: |
    This is a test description.
servers:
  - url: /
    description: Server
paths:
  /test:
    get:
      tags:
        - Test
      summary: Test endpoint
      operationId: getTest
      responses:
        '200':
          description: The speaker preset
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestSchema'
              example:
                testField:
                  $ref: ./TestFieldExample.yaml
                anotherField: AnotherExample
components:
  schemas:
    TestSchema:
      type: object
      properties:
        testField:
          $ref: '#/components/schemas/TestField'
        anotherField:
          $ref: '#/components/schemas/AnotherField'
    TestField:
      type: string
      description: Test String
      example: Test
    AnotherField:
      type: string
      description: Test String
      example: Another

And the file $ref is kept for the testField example.

Expected behavior

I'd like testField in the example to resolve the assigned ref.

Redocly version(s)

2.12.5

Node.js version(s)

v22.15.0

OS, environment

Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions