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.

Problem with "oneOf"

See original GitHub issue

Here is a scheme I am trying to use…

{
  "title": "Configuration",
  "type": "object",
  "properties": {
    "triggers": {
      "type": "array",
      "format": "tabs",
      "title": "Triggers",
      "items": {
        "title": "Trigger",
        "oneOf": [
          {
            "title": "Twitter",
            "type": "object",
            "properties": {
              "track": {
                "type": "string"
              }
            }
          },
          {
            "title": "Instagram",
            "type": "object",
            "properties": {
              "tags": {
                "title": "Tags",
                "type": "array",
                "format": "table",
                "items": {
                  "title": "tag",
                  "type": "string"
                }
              }
            }
          }
        ]
      }
    }
  }
}

In the editor, If I switch an “Trigger” from “Twitter” to “Instagram”, I still see a property from the Twitter schema (“track”). I don’t think that should be displaying at all, but it is also not displaying correctly. Is this a bug? In any case is there any way to get around this problem?

You can see what I mean here… http://jeremydorn.com/json-editor/?schema=N4IgLglmA2CmIC4QGECGZXQJ4GcwAJkB7AOwDMIBzAVwCd0JSQAacLAB3iSICMArWAGMwLEO1pFOtSLByJQYWlUqxachAo5cQqWvSyiyRWgFt0icKh5zWkGNoAqSyirWiosE+oVQ4Fp8qqoqSwAPJkiADaPvb+AO5QYEG2Wha8AsKi4pKqMt7g9IIA1vJsnBZ4SiSUogAmsoJK7JBMSMQmZvj10BAmHrX4PXj4RGT4SaY440TjhUUAdCAAvivMMX5IAJIkeKiU9CaiYKnc/EIirNlSeaUYlPl2GyAOezZl2rr6hsZmIkgYPD8rHqOEaEGajBIFgAMhBhmAABawfAI1A4BF3KZgGaKVDFRasagkCAAR2osE2SS8iEU5NYHmpGnAvm0dyOJxAlQg1WWKyWAF0+UsgAAA==&value=N4IgLgTglg5jCmEDOIBcBtUkCGBjA1miCAL4C6JQAAA=&theme=bootstrap3&iconlib=bootstrap3&object_layout=normal&show_errors=interaction

In the dropdown, change twitter to instagram.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jdorncommented, May 15, 2015

It’s not a bug, but it is really unintuitive behavior. By default, JSON Editor tries to keep the value of oneOf fields when you switch between schemas if possible.

You can fix this in one of two ways:

  1. Make the track property invalid for your Instagram oneOf schema by setting additionalProperties to false.
{
  "title": "Instagram",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "tags": {
      "title": "Tags",
      "type": "array",
      "format": "table",
      "items": {
        "title": "tag",
        "type": "string"
      }
    }
  }
}
  1. Turn off this default JSON Editor behavior by setting the option keep_oneof_values to false during initialization.
new JSONEditor(element, {
  schema: {...},
  keep_oneof_values: false
});
1reaction
mbrodalacommented, Jun 5, 2015
Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG][Java] OneOf-Class not generated #10880 - GitHub
It looks as if there's a problem with oneOf support for properties; as the summary indicates, the generator fails to generate the appropriate ......
Read more >
OpenAPI models not being generated when using oneOf
I have oneOf generation working for java using openapi-generator 5.4. 0 but I do add a discriminator field (like requestType: type: string enum ......
Read more >
OneOf, nested inside of another OneOf is not shown...
Hello,. I am developing a Spring app with OpenApi. For open API spec (schema.txt) java code is generated by the maven code generator...
Read more >
oneOf rendered as pulldown in API Reference
My expectation is that both of the objects would be rendered with a notation indicating "oneOf", or a pulldown with the objects' descriptions...
Read more >
Problem with oneOf enum in angular (jsonforms) - Reddit
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 >

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