redoc icon indicating copy to clipboard operation
redoc copied to clipboard

OpenAPI 3.1 examples not rendered correctly

Open kassi opened this issue 3 years ago • 4 comments
trafficstars

Describe the bug Having an array of examples in a schema definition, e.g. under #/components/schemas only renders the first one, not all of them.

Expected behavior I expect to see all examples in the right pane.

Minimal reproducible OpenAPI snippet(if possible)

components:
  schemas:
    Test:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
      examples:
        - id: 123
          title: Test title
        - id: 456
          title: Another title

Screenshots

Bildschirmfoto 2022-02-14 um 09 18 45

Additional context In openapi 3.1, example is deprecated. According to changes from openapi 3.0 to 3.1 (https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0) one should use examples instead of example and add several examples as a list. It doesn't work either when adding multiple examples to the individual fields instead of the object, i.e.

components:
  schemas:
    Test:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
          examples:
            - Test title
            - Another title

also shows only the first one.

I expect to the all examples either directly listed or selectable (although openapi 3.1 examples are a list, not a hash with keys to select from). Since objects can become complex and properties may depend on each other, showing several real world examples with different use cases make sense.

kassi avatar Feb 14 '22 08:02 kassi

This is not really a bug.

OpenAPI 3.1 also allows for defining mutliple media type examples. If you want multiple examples displayed, use that instead because that provides a key to put into an example selector.

adamaltman avatar Mar 03 '22 10:03 adamaltman

+1 for this feature request since only displaying the first example appears to be the current functionality.

llaski avatar Apr 29 '22 20:04 llaski

We should think about UI this feature. The main idea is easy to copy and paste mock data for requests.

How we can display multiple examples? One way we can add a new dropdown for it, but it seems too complicated to understand and we have concerns about naming these keys.

It seems super simple but it is not. What about complicated schemas with many key examples? How it should display?

If there are ideas we will be glad to hear them. We don't have a good UI solution for that now.

AlexVarchuk avatar May 05 '22 08:05 AlexVarchuk