Skip to content

Support schemas inside of additionalProperties #108

Open
@GAUNSD

Description

@GAUNSD

Describe the bug

When I have a JSON schema that defines further schema constraints inside of additionalProperties...JSV does not render them properly in the UI.

To Reproduce

Sample JSON Schema

{
	"$id": "https://example.com/sample.schema.json",
	"$schema": "http://json-schema.org/draft-07/schema#",
	"type": "object",
	"title": "Sample schema",
	"description": "To reproduce a JSV issue",
	"required": [
		"foo",
		"bar",
		"baz"
	],
	"additionalProperties": false,
	"properties": {
		"foo": {
			"type": "string",
			"description": "Some foo property",
			"const": "foo_value"
		},
		"bar": {
			"type": "object",
			"description": "An object where keys can be anything...but I want to restrict the values of each key",
			"required": [
				"bing",
				"bang"
			],
			"additionalProperties": {
				"type": "object",
				"description": "Constraints for each value",
				"additionalProperties": false,
				"properties": {
					"bar_prop_one": {
						"type": "string"
					},
					"bar_prop_two": {
						"type": "string"
					}
				}
			}
		},
		"baz": {
			"type": "object",
			"description": "An object where keys can be anything...but I want to restrict the values of each key by a shared definition",
			"required": [
				"boom"
			],
			"additionalProperties": {
				"$ref": "#/definitions/defined_entity"
			}
		}
	},
	"definitions": {
		"defined_entity": {
			"$id": "#/definitions/defined_entity",
			"type": "string",
			"description": "Definition for an Entity.",
			"enum": [
				"entity_one",
				"entity_two"
			]
		}
	}
}

Sample JSON object that would work with schema above

{
	"foo": "foo_value",
	"bar": {
		"bing": {
			"bar_prop_one": "a",
			"bar_prop_two": "b",
		},
		"bang": {
			"bar_prop_one": "a",
			"bar_prop_two": "b",
		},
		"tang": {
			"bar_prop_one": "tango",
			"bar_prop_two": "tangotango",
		},
	},
	"baz": {
		"boom": "entity_one",
		"one": "entity_one",
		"two": "entity_one",
		"three": "entity_two",
		"four": "entity_two",
		"eleven": "entity_two"
	}
}

JSV Configuration

import sampleSchema = "../../../schemas/sample.schema.json";

<JsonSchemaViewer
	schema={sampleSchema}
	viewMode="standalone"
/>

Expected behavior

A clear and concise description of what you expected to happen.

My expectation is that the schema I provide inside additionalProperties is rendered in some way.

Additional context

Add any other context about the problem here.

Screenshots

image

Environment

{
	"@stoplight/json-schema-viewer": "3.0.0",
	"@stoplight/markdown-viewer": "3.8.1",
	"@stoplight/ui-kit": "3.0.0-beta.39",
	"mobx": "5.15.7"
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions