Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI3: Response shows example generated from schema instead of example given #4415

Closed
fbrunet99 opened this issue Apr 5, 2018 · 4 comments

Comments

@fbrunet99
Copy link

OpenAPI 3: When a response shows an example, it shows one generated from the schema. It does not show the example that was given under content/type/response/value.

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? OpenAPI 3.0
Which Swagger-UI version? 3.13.2
How did you install Swagger-UI? Git clone
Which browser & version? Chrome Latest
Which operating system? MacOS Sierra

Demonstration API definition

openapi: 3.0.0
servers:
  - url: 'https://__host__/'
info:
  description: Test API
  version: '1.0'
  title: Test API
  contact:
    name: Sample Person
    email: [email protected]
tags:
  - name: Test API with Schema
    description: Test API with Schema
paths:
  /myApi/v1/associates/documents:
    get:
      operationId: some guid
      responses:
        '200':
          description: Returns documents
          content:
            '*.*':
              schema:
                $ref: ./schemas/documents_schema.json
            application/json:
              examples:
                response:
                  value: ./examples/document_sample.json
      description: Returns documents
      tags:
        - Test API with Schema
      summary: Test API with Schema

Expected Behavior

Expect the sample to be shown under the example tab in the response.

Current Behavior

A sample that has been generated from the schema is shown. This will show generic types such as "string" as a value rather than a realistic value as used in a sample.

Possible Solution

In core/components/response.jsx, the examples selector (response.get("examples") ) does not pick up all possible examples so subsequent code falls back to a generated version.

This can possibly fixed by modifying response.jsx at about line 108 (inside the "if isOAS3" block) to look a little harder for the examples. Like this:

      if (!examples && content) {
        examples = content.find((data, key) => {
          return data.get("examples")
        })
      }

Context

We need to provide examples with realistic values rather than generic generated ones.

@hkosova
Copy link
Contributor

hkosova commented Apr 6, 2018

Support for media type examples is being tracked in #3437.

A couple of notes:

  1. *.* does not look like a valid media type, did you mean */*?
  2. value is for inline examples only. To reference an external example you need to use externalValue:
              examples:
                response:
                  externalValue: ./examples/document_sample.json

@fbrunet99
Copy link
Author

  1. Yes . is a typo. It should be / (or application/json)

@webron
Copy link
Contributor

webron commented Apr 8, 2018

Going to close this one out in favor of #3437 - as @hkosova kindly pointed out, it's an unimplemented feature.

@webron webron closed this as completed Apr 8, 2018
@lock
Copy link

lock bot commented Jul 2, 2019

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants