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

How to use fetch in custom examples? #6027

Closed
verilog15 opened this issue May 21, 2020 · 3 comments
Closed

How to use fetch in custom examples? #6027

verilog15 opened this issue May 21, 2020 · 3 comments

Comments

@verilog15
Copy link

Q&A (please complete the following information)

  • Swagger-UI version: 3.0.1
  • Swagger/OpenAPI version: OpenAPI 3.0

How can we help?

I'm trying to understand how custom examples work. I have a route: /collection/type/{typeName}
which returns all of the values per the typeName (JSON). I would like to add an example in the 200 status or in the body so the input is user and the output is all of the users (JSON's Array). I didn't see an option of "input" in the docs. Also, I don't want it to be custom (written by me), I want it to fetch the data by itself without adding a $ref. For example if the input is user then it will do the GET request and get the data. Is it something that is possible using Swagger?

@hkosova
Copy link
Contributor

hkosova commented Jun 24, 2020

OAS3 examples keyword can use externalValue to specify an URL containing an external example value. But Swagger UI does not support externalValue yet, this is tracked in #5433.

openapi: 3.0.3
info:
  title: externalValue example
  version: 1.0.0
servers:
  - url: https://myserver.com
paths:
  /collection/type/{typeName}:
    get:
      parameters:
        - in: path
          name: typeName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {}
              examples:
                userTypes:
                  description: The example value should be fetched from this URL
                  externalValue: https://myserver.com/collection/type/user

@verilog15
Copy link
Author

Thank you @hkosova. Is it known when externalValue will be supported in Swagger UI?

@hkosova
Copy link
Contributor

hkosova commented Jul 20, 2020

@verilog15 There's no ETA for this yet. Please follow #5433 for status updates.

@hkosova hkosova closed this as completed Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants