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.

Nested anyOf not working as expected

See original GitHub issue

Using the playground, the schema below works as expected;

Working schema
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "options1": {
            "type": "string",
            "enum": [
                "a",
                "b"
            ]
        },
        "options2": {
            "type": "string",
            "enum": [
                "c",
                "d"
            ]
        }
    },
    "type": "object",
    "properties": {
        "only1": {
            "title": "Only 1",
            "$ref": "#/definitions/options1"
        },
        "only2": {
            "title": "Only 2",
            "$ref": "#/definitions/options2"
        },
        "both": {
            "title": "1 and 2",
            "anyOf": [
                {
                    "$ref": "#/definitions/options1"
                },
                {
                    "$ref": "#/definitions/options2"
                }
            ]
        }
    }
}

Screenshot 2019-12-20 at 16 03 17

However for the schema below the last dropdown does not work

Not working schema with anyOf's
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "options1": {
            "type": "string",
            "anyOf": [
                {
                    "title": "A",
                    "const": "a"
                },
                {
                    "title": "B",
                    "const": "b"
                }
            ]
        },
        "options2": {
            "type": "string",
            "anyOf": [
                {
                    "title": "C",
                    "const": "c"
                },
                {
                    "title": "D",
                    "const": "d"
                }
            ]
        }
    },
    "type": "object",
    "properties": {
        "only1": {
            "title": "Only 1",
            "$ref": "#/definitions/options1"
        },
        "only2": {
            "title": "Only 2",
            "$ref": "#/definitions/options2"
        },
        "both": {
            "title": "1 and 2",
            "anyOf": [
                {
                    "$ref": "#/definitions/options1"
                },
                {
                    "$ref": "#/definitions/options2"
                }
            ]
        }
    }
}

image

The last dropdown is missing here

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
epicfaacecommented, Mar 16, 2020

I think it was meant to be any of with the option 1 / option 2 dropdown.

The only difference that is done from working -> not working is that the schemas with enum are switched to using anyOf. Both should render the same widget.

0reactions
tdamsmacommented, Apr 21, 2022

The current playground examples are working as expected, so this issue can be closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema nested allOf/anyOf/oneOf not working
EDIT - It appears to be a bug in IntelliJ IDEA validator. It works in python3-jsonschema, Java Everit, jsonschema.dev. json · validation ...
Read more >
JSON schema validation fails if anyOf is nested in oneOf
Gives a "Validates to more than one variant" error, but it is expected to validate without errors. Already verified with other validators.
Read more >
Schema in a request allows additional properties
If you are using combining operations for objects with properties, additionalProperties must be true or the combining operations will not work.
Read more >
Understanding JSON Schema
4.11.2 anyOf . ... Earlier versions of JSON Schema are not completely ... When you start developing large schemas with many nested and ......
Read more >
Jenkins Tutorial — Part 5 — When Conditions - ITNEXT
not , allOf and anyOf are complex conditions that are used in conjunction with conditions. not executes the stage if the nested condition...
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