swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.48k stars 8.96k forks source link

$ref not being rendered in response example #8308

Open ygurin opened 1 year ago

ygurin commented 1 year ago

Q&A (please complete the following information)

Content & configuration

The swagger content and configuration is split among multiple files, see repository github.com/ygurin/swagger-bug-demo.

The structure of the project looks like so:

.
├── Dockerfile
├── openapi
│   ├── components
│   │   ├── examples
│   │   │   └── foo
│   │   │       └── getFooResponse.json
│   │   ├── headers
│   │   │   ├── channel.yaml
│   │   │   └── key.yaml
│   │   └── schemas
│   │       └── foo
│   │           └── get-foo-response-schema.json
│   ├── openapi.yaml
│   └── paths
│       └── foo
│           └── foo.yaml
└── README.md

9 directories, 8 files

This is the main openapi.yaml file:

openapi: 3.0.0
info:
  version: '1'
  title: ''
  description: 'Demo of a bug in swagger'
paths:
  /api/foo:
    $ref: 'paths/foo/foo.yaml'

points to paths/foo/foo.yaml

get:
      tags:
        - foo
      summary: Get a list of foo
      description: |
        Get a list of Foo
      operationId: account
      parameters:
        - $ref: ../../components/headers/key.yaml
        - $ref: ../../components/headers/channel.yaml
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "../../components/schemas/foo/get-foo-response-schema.json"
              examples:
                response:
                  value:
                    $ref: "../../components/examples/foo/getFooResponse.json"
        "404":
          description: Not found
        "410":
          description: error

Describe the bug you're encountering

The $ref described in the example: does not render. Instead, it displays the $ref string.

To reproduce...

Steps to reproduce the behaviour:

  1. Download the repository found here
  2. Build the docker container docker build -t foo:v1 .
  3. Run the docker container docker run --rm -p 80:8080 -e API_URL="openapi/openapi.yaml" foo:v1
  4. Access http://localhost/

Expected behavior

Swagger UI renders the referenced example in the response.

Screenshots

Screenshot from 2022-11-25 19-05-40

Additional context or thoughts

I'm currently using an extension in VScode called OpenAPI (Swagger) Editor. This uses a version of Swagger-UI.

It seems to render the example with no issues, see the screenshot below: Screenshot from 2022-11-25 19-09-27

raygpt commented 1 year ago

any updates on this?!

ygurin commented 1 year ago

@raygpt Nope got nowhere with this. Abandoned this and didn't use $ref.