question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Q: How to use anyOf / allOf?

See original GitHub issue

General information

  • json-editor version: latest from cdn.

Expected behavior

var schema = {
    "properties": {
	"chord": {
	    "description": "Font",
	    "properties": {
		"name":        { "type": "string" },
		"file":        { "type": "string" },
		"description": { "type": "string" },
		"size":        { "type": "number" }
	    },
 	    "allOf": [
		{ "required": [ "description" ] },
		{ "required": [ "name"        ] },
		{ "required": [ "file"        ] }
	    ]
	}
    }
};

var data = {
    "chord" : {
        "file" : "Helvetica.otf",
        "name" : "Helvetica",
        "description" : "Sans serif font",
        "size" : 10
    }
};

var editor = new JSONEditor(document.getElementById('editor_holder'), {
    schema: schema,
    no_additional_properties: true,
    required_by_default: true,
    disable_collapse: true,
    show_opt_in: true,
});

editor.on('ready', function() {
    editor.setValue(data);
});

Actual behavior

basic1

Expected behavior

var schema = {
    "properties": {
	"chord": {
	    "description": "Font",
	    "properties": {
		"name":        { "type": "string" },
		"file":        { "type": "string" },
		"description": { "type": "string" },
		"size":        { "type": "number" }
	    },
 	    "anyOf": [
		{ "required": [ "description" ] },
		{ "required": [ "name"        ] },
		{ "required": [ "file"        ] }
	    ]
	}
    }
};

var data = {
    "chord" : {
        "name" : "Helvetica",
        "size" : 10
    }
};

var editor = new JSONEditor(document.getElementById('editor_holder'), {
    schema: schema,
    no_additional_properties: true,
    required_by_default: true,
    disable_collapse: true,
    show_opt_in: true,
});

editor.on('ready', function() {
    editor.setValue(data);
});

Actual behavior

basic2

Note that the file input field is missing.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
robocodercommented, Apr 27, 2021

The allOf example works better if "additionalProperties": false is in the schema instead of using no_additional_properties: true in the editor options.

The anyOf example seems to show the sub-schemas being hoisted into the wrong level (i.e., acting on “chord”)

0reactions
sciuriuscommented, Oct 14, 2021

Is there any progress on handling anyOf? The remark from @robocoder about “sub-schemas being hoisted into the wrong level” seems to confirm that the usage is okay, but there’s a bug somewhere in the editor code.

@schmunk42 Please remove the needinfo label.

Read more comments on GitHub >

github_iconTop Results From Across the Web

oneOf, anyOf, allOf, not - Swagger
Use the anyOf keyword to validate the data against any amount of the given subschemas. That is, the data may be valid against...
Read more >
validation - JSON Schema: Using anyOf, oneOf, allOf within ...
My assumption is that this will not work because the passing schema(s) in oneOf|anyOf|allOf of additionalProperties must apply to ALL keys ...
Read more >
Support for oneOf, anyOf and allOf - Liferay Help Center
With allOf you can use the power of composition to create an entity that combines several others. It's the most potent way of...
Read more >
Usage of anyOf/oneOf/allOf - SmartBear Community
Usage of anyOf/oneOf/allOf ... While following schema is valid in Open-API: . . . components: schemas: MyModel: description: One Model to rule ...
Read more >
oneOf, anyOf, allOf json schema features available - IBM
Are the oneOf, allOf and anyOf JSON schema features available in the latest DataPower firmware ? Where I can find information about the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found