redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Multiple parameters examples

Open antonkomarev opened this issue 7 years ago • 11 comments

Screenshot from 2019-03-19 23-59-01

Currently ReDoc supports only one example per parameter, add many examples support if it is possible, please.

antonkomarev avatar Mar 19 '19 21:03 antonkomarev

where to add the query parameter and how to use it

rshiva73173 avatar Jun 14 '19 14:06 rshiva73173

@antonkomarev there is examples field on parameter object.

Is this what you mean?

RomanHotsiy avatar Jun 20 '19 15:06 RomanHotsiy

Yes. I've checked it one more time, it can has many enum values, but examples are always limited to one value. I've edited spec in Restlet GUI and it allows to add many examples which are displayed on service, but in fact in generated spec file it has only one x-example per parameter.

      parameters:
      - name: "include[type]"
        in: "query"
        required: false
        type: "string"
        enum:
        - "FirstType"
        - "SecondType"
        - "ThirdType"
        x-example: "FirstType"

antonkomarev avatar Jun 20 '19 16:06 antonkomarev

I just ran into this as well. There's a nice overview under "Parameter Examples" https://swagger.io/docs/specification/adding-examples/.

I'm trying to document examples for query parameters that match a specific pattern:

  parameters:
    - name: created
      in: query
      description: Date when foo was created.
      required: false
      schema:
        type: string
        pattern: '(gte|lte|equals):\d{4}-\d{2}-\d{2}'
      examples:
        gte:
          value: 'gte:2019-05-10'
          summary: 'Filter foo when created >= 2019-05-10'
        lte:
          value: 'lte:2019-05-10'
          summary: '...'

padge avatar Jun 20 '19 22:06 padge

@antograssiot seems to use OpenAPI 2 which didn't have examples on parameters. They were added in OpenAPI 3

I think we can render multiple examples. It may looks like:


Field description here Examples: gte:2019-05-10 - Filter foo when created >= 2019-05-10 lte:2019-05-10 - ....


PR would be appreciated. It shouldn't be complicated

RomanHotsiy avatar Jun 21 '19 07:06 RomanHotsiy

I guess you wanted to ping @antonkomarev instead of me 😂

antograssiot avatar Jun 21 '19 08:06 antograssiot

Oops 🙈. Sorry for bothering

RomanHotsiy avatar Jun 21 '19 08:06 RomanHotsiy

Would be nice to see this feature :+1:

nadar avatar Jun 09 '20 14:06 nadar

Would be nice to see this feature 👍

+1

bdhaak avatar Jun 18 '20 14:06 bdhaak

This seems to be added in 2.0.0-rc.48, but I'm not sure if it works.

I tried to generate a bundle using redoc-cli but it fails. I've been able to reproduce the issue using the Petstore OpenAPI spec by adding a parameter example.

Defining one example for the parameter works as expected:

  '/pet/{petId}':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      parameters:
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          schema:
            type: integer
            format: int64
          example: 123

Specifying multiple fails:

  '/pet/{petId}':
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      parameters:
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          schema:
            type: integer
            format: int64
          examples:
            TestExample: 456
            TestExample2: 789

Not completely sure if this is valid OpenAPI. Using something like this also does not work:

TestExample: 
  $ref: '#/components/schemas/Test'

Output:

# redoc-cli bundle openapi.yml 
Prerendering docs
ReferenceError: name is not defined
    at /Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:9404:124
    at mapValues (/Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:7269:24)
    at new FieldModel (/Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:9404:29)
    at /Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:9741:50
    at Array.map (<anonymous>)
    at OperationModel.get (/Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:9741:15)
    at OperationModel.get (/Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:8600:42)
    at Object.children (/Users/xxx/.config/yarn/global/node_modules/redoc/bundles/redoc.lib.js:14129:97)
    at ReactDOMServerRenderer.render (/Users/xxx/.config/yarn/global/node_modules/react-dom/cjs/react-dom-server.node.development.js:3635:55)
    at ReactDOMServerRenderer.read (/Users/xxx/.config/yarn/global/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29)

I'm using redoc-cli version 0.10.2 on MacOS 10.15.7 with NodeJS v14.15.1. Everthing works fine with redoc-cli 0.10.1 (just not showing multiple examples, as not supported yet).

Stange thing here is that 0.10.2 has not been released yet? https://github.com/Redocly/redoc/blob/master/cli/package.json#L3

marcokrikke avatar Dec 02 '20 11:12 marcokrikke

This seems to be added in 2.0.0-rc.48, but I'm not sure if it works.

Seems to work. Could be closed maybe

nadar avatar Jul 26 '21 15:07 nadar