Skip to content

Do not resolve $refs in property examples #6628

Open
@hkosova

Description

@hkosova

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: any
  • Method of installation: any
  • Swagger-UI version: 3.36.2
  • Swagger/OpenAPI version: 2.0, 2.0

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  title: $ref in a property example
  version: 1.0.0

paths:
  /foo:
    get:
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyObject'

components:
  schemas:
    MyObject:
      type: object
      properties:
        prop:
          type: object
          example:
            $ref: '#/components/examples/StringExample'

  examples:
    StringExample:
      value: test

Describe the bug you're encountering

Even though the example keyword does not support $ref, Swagger UI attempts to resolve those $refs when generating examples.

$refs should only be resolved when used directly under examples.<name> in OAS3 definitions.

Expected behavior

Response example appears as follows, with $ref treated as a literal property in the example object.

{
  "prop": {
    "$ref": "#/components/examples/StringExample"
  }
}

Actual behavior

Response example appears as

{
  "prop": {
    "value": "test"
  }
}

Additional context or thoughts

Related issues with $refs in examples:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions