Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support schemas inside of additionalProperties #108

Open
GAUNSD opened this issue Feb 23, 2021 · 8 comments
Open

Support schemas inside of additionalProperties #108

GAUNSD opened this issue Feb 23, 2021 · 8 comments
Labels

Comments

@GAUNSD
Copy link

GAUNSD commented Feb 23, 2021

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"
}
@GAUNSD GAUNSD added the bug Something isn't working label Feb 23, 2021
@raleigh04 raleigh04 added t/bug Something isn't working and removed bug Something isn't working labels May 6, 2021
@raleigh04 raleigh04 added enhancement New feature or request and removed t/bug Something isn't working labels Jun 28, 2021
@philsturgeon

This comment has been minimized.

@Airkro
Copy link

Airkro commented Jun 16, 2022

Maybe the viewer's internal logic could turn additionalProperties into properties/{*} to support this.

@philsturgeon
Copy link

This could be considered "OpenAPI v3.1 Compatibility" work, as this was not supported in prior versions and is now.

http://json-schema.org/understanding-json-schema/reference/object.html#additional-properties

@siimsoni
Copy link

additionalProperties is part of JSON Schema Draft 4, and a quite important part of it, as it's needed to represent value maps.
https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.4.4
It is quite surprising that this is not supported, considering the project claims full JSON Schema Draft 4 support.

@onavratil-monetplus
Copy link

This bug is a major inconvenience

@danielgtaylor
Copy link

Any update on this? It's hard to recommend Elements be used when a fairly basic feature is missing. This makes it so maps are just documented as object which isn't very useful, particularly when the map value is a complex type.

@jy95
Copy link

jy95 commented Jan 3, 2024

If it could help anyone, I started a viewer project called docusaurus-json-schema-plugin which supports additionalProperties . I had that need as well ...

If needed, you can migrate your schema from draft-04 to draft-07 using ajv-cli

@siimsoni
Copy link

siimsoni commented May 23, 2024

It seems to be working as of 8.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants