Q: How to use anyOf / allOf?
See original GitHub issueGeneral 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
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
Note that the file
input field is missing.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
allOf
example works better if"additionalProperties": false
is in the schema instead of usingno_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”)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.