Problems with oneOf
See original GitHub issueHi,
I have this schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"sensors": {
"title": "Sensors",
"type": "object",
"additionalProperties": false,
"properties": {
"sensor1": {
"title": "Sensor 1",
"$ref": "#/definitions/Sensor"
},
"sensor2": {
"title": "Sensor 2",
"$ref": "#/definitions/Sensor"
}
}
}
},
"definitions": {
"Value": {
"type": "object",
"required": [ "minimum", "maximum" ],
"additionalProperties": false,
"properties": {
"minimum": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"default": 0
},
"maximum": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"default": 100
}
}
},
"Sensor": {
"type": "object",
"oneOf": [
{
"title": "Disabled",
"type": "object",
"required": [ "disabled" ],
"additionalProperties": false,
"properties": {
"disabled": {
"type": "null"
}
}
},
{
"title": "Test 1",
"type": "object",
"required": [ "test1" ],
"additionalProperties": false,
"properties": {
"test1": {
"$ref": "#/definitions/Value"
}
}
},
{
"title": "Test 2",
"type": "object",
"required": [ "test2" ],
"additionalProperties": false,
"properties": {
"test2": {
"$ref": "#/definitions/Value"
}
}
}
]
}
}
}
So, by default, the JSON output is:
{
"sensors": {
"sensor1": {
"disabled": null
},
"sensor2": {
"disabled": null
}
}
}
On the generated user interface, if I change “Sensor 1” from “Disabled” to “Test 1”, the generated output is now this:
{
"sensors": {
"sensor1": {
"test1": {
"minimum": 0,
"maximum": 100
},
"disabled": null
},
"sensor2": {
"disabled": null
}
}
}
Also, the user interface shows this error: No additional properties allowed, but property disabled is set
I think, that “disabled” shouldn’t appear under “sensor1”.
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Problems with OneOf - NFTs, Music and the Metaverse
Here are five problems I see with OneOf's secondary market. 5 Problems with OneOf's Secondary Market: There is no floor price (lowest ask...
Read more >Issue with oneOf when used in conjunction with pattern #74
And then Im using oneOf as means to specify one of a type (database type) with a pattern. ... It seems to validate...
Read more >nanopb oneof - encoding problems
I am trying to encode a message using oneof - and the size does not seem ok. Looks like ...
Read more >Problem with oneOf enum in angular (jsonforms)
Problem with oneOf enum in angular (jsonforms). Hello guys,. I use the JSON Forms library with Angular, JSON Forms allows me to define...
Read more >oneOf Validation Issue
You've assumed that the validation path should go down `oneOf[1]` and find it valid, and go down `one of[0]` and find it invalid,...
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
I just added a new option
keep_oneof_values
. It defaults totrue
to keep the current behavior, but you can set it tofalse
to do what you want.Set globally:
Set per JSONEditor instance:
Set for a single oneOf instance:
Hey @jdorn, sorry for the off-topic, but I’ve seen many tickets that can be closed, this being one of them (there is actually a duplicate of this too).