swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Rendering string:string dictionary example in Schemas

Open propagated opened this issue 5 years ago • 3 comments

Q&A (please complete the following information)

  • OS: [e.g. macOS]
  • Browser: [chrome]
  • Version: [73]
  • Method of installation: [editor.swagger.io]
  • Swagger-UI version: [e.g. 3.10.0]
  • Swagger/OpenAPI version: [OpenAPI 3.0]

Content & configuration

Example Swagger/OpenAPI definition:

components:
  schemas:
    Order:
      type: object
      properties:
        testMap:
          type: object
          additionalProperties:
            type: string
          example:
            en-us: Map
            fr: le Map

Describe the bug you're encountering

Per https://swagger.io/docs/specification/data-models/dictionaries/

Examples of Dictionary Contents You can use the example keyword to specify sample dictionary contents:

type: object additionalProperties: type: string example: en: Hello! fr: Bonjour!

UI does not render any of these examples in the schema section, it only shows { < * >: String }

To reproduce...

Steps to reproduce the behavior:

  1. Go to editor.swagger.io
  2. Add a dictionary with examples to a component schema
  3. Look at render
  4. See no examples in the schemas section.

Expected behavior

Component schema preview shows examples in-line.

Screenshots

dictionary

Additional context or thoughts

propagated avatar Apr 16 '19 12:04 propagated

It's still not fixed yet..

JasperSui avatar Aug 12 '20 07:08 JasperSui

This still doesn't seem to be fixed....

getupkid avatar Mar 07 '23 01:03 getupkid

Any update on this? The rendered result is confusing. Try this:

openapi: 3.0.0
info:
  title: Example
  version: '1.0.0'
paths:
  /example:
    get:
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema: 
                $ref: '#/components/schemas/Response'
components:
  schemas:
    Response:
      type: object
      properties:
        listOfAccounts:
          type: array
          items:
            $ref: '#/components/schemas/Account'
        mapOfAccounts:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Account'
        mapOfListsOfAccounts:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/Account'             
    Account:
      type: object
      properties:
        accountId:
          type: string
        accountName:
          type: string

Result (Example value):

{
  "listOfAccounts": [
    {
      "accountId": "string",
      "accountName": "string"
    }
  ],
  "mapOfAccounts": {
    "additionalProp1": {
      "accountId": "string",
      "accountName": "string"
    },
    "additionalProp2": {
      "accountId": "string",
      "accountName": "string"
    },
    "additionalProp3": {
      "accountId": "string",
      "accountName": "string"
    }
  },
  "mapOfListsOfAccounts": {
    "additionalProp1": [
      {
        "accountId": "string",
        "accountName": "string"
      }
    ],
    "additionalProp2": [
      {
        "accountId": "string",
        "accountName": "string"
      }
    ],
    "additionalProp3": [
      {
        "accountId": "string",
        "accountName": "string"
      }
    ]
  }
}

Result (Schema): image

Nikolas-Charalambidis avatar Dec 27 '23 06:12 Nikolas-Charalambidis