elements icon indicating copy to clipboard operation
elements copied to clipboard

Object with additionalProperties (i.e. map of string to object) does not display schema

Open codygibb opened this issue 3 years ago • 4 comments

Context

Swagger specs can define string-to-object dictionary mappings with the following config:

type: object
additionalProperties:
  type: object
  properties:
    ...

In these cases, the object keys can be any string, but the object values have a fixed schema.

Current Behavior

Elements does not display the object value schema for dictionary mappings. It simply says "object" with no further details:

Screen Shot 2022-08-04 at 3 18 29 PM

Expected Behavior

Elements should display the object value schema. For example, ReDoc allows expanding object value schema:

Screen Shot 2022-08-04 at 3 18 21 PM

Steps to Reproduce

Example referenced in the above two screenshots:

{
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "bars": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/Bar"
          },
        },
      }
    },
    "Bar": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
        },
        "code": {
          "type": "integer",
        }
      }
    }
  },
  "paths": {
    "/foos": {
      "post": {
        "operationId": "CreateFoo",
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Foo"
            }
          }
        ],
        "tags": [
          "Foo"
        ]
      }
    },
  },
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "swagger": "2.0"
}

Environment

  • Version used: whatever is currently being hosted by unpkg.com/@stoplight/elements.
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Chrome 103.0.5060.134 (arm64)
  • Operating System and version (desktop or mobile): desktop

codygibb avatar Aug 04 '22 22:08 codygibb

Note, I believe the root issue here is actually in another repo: https://github.com/stoplightio/json-schema-viewer/issues/108

codygibb avatar Aug 08 '22 22:08 codygibb

FWIW I am experiencing the same behaviour using YAML schemas

ahopkinstk avatar Aug 14 '22 23:08 ahopkinstk

Even worse, when you open a reusable schema with additionalProperties you see a blank page.

Thore1954 avatar Jan 11 '23 07:01 Thore1954

Just wanted to add for someone still experiencing this issue:

We bumped the @stoplight/elements package from 7.7.7 to 8.0.2 (https://github.com/dyte-io/docs/pull/261/files) , and this issue was resolved somewhere in between, we see the correct "Dictionary" type now:

image

thebongy avatar Jan 31 '24 14:01 thebongy