Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oneOf issues #416

Open
ai-nikolai opened this issue Jun 21, 2023 · 2 comments
Open

oneOf issues #416

ai-nikolai opened this issue Jun 21, 2023 · 2 comments

Comments

@ai-nikolai
Copy link

First of all, thank you for this great package. It works really well and is much easier to get started compared to some others and has great re-activity.

The current issue that we are reporting is that oneOf only works with a very specific format of the const keyword.

However, the following json-schemas do not work:

1. Nesting the Const keyword into an array

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "option": {
            "oneOf": [
                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "const": "a"
                    }
                },
                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "const": "b"
                    }
                }
            ]
        },
        "sharedProperty": {
            "type": "string"
        }
    },
    "required": ["option", "sharedProperty"]
}

2. Using other keywords than const

e.g.: using the above schema and adding this option for oneOf:

                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": ["b", "c"]
                    }
                }

In particular, what we are aiming to generate is a json that has either:
option : [a], option: [b], or option: [b,c] and depending on that a different sub-schema.

Please advice us on how to get this going, i.e. the full json should like like:

{
 option : [a],
 sharedProperty : "abc"
}
@albanm
Copy link
Member

albanm commented Jun 21, 2023

In the next major version I intend to use a closer integration with ajv and I think the current subschema of a oneOf will be calculated by attempting validation of each subschema, this way any way of discriminating between subschemas will be supported. But this will not be available soon and I don't want to make such important changes to the current version. So for the time being, sorry but a const property is the only supported way to discriminate subschemas in a oneOf.

@ai-nikolai
Copy link
Author

Ok got it. Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants