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.

Problems with oneOf

See original GitHub issue

Hi,

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:open
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jdorncommented, Feb 2, 2015

I just added a new option keep_oneof_values. It defaults to true to keep the current behavior, but you can set it to false to do what you want.

Set globally:

JSONEditor.defaults.options.keep_oneof_values = false;

Set per JSONEditor instance:

var editor = new JSONEditor(el, {
  schema: {...},
  keep_oneof_values: false
});

Set for a single oneOf instance:

{
  "options": {
    "keep_oneof_values": false
  },
  "oneOf": []
}
0reactions
Papipocommented, Jul 27, 2015

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).

Read more comments on GitHub >

github_iconTop 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 >

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