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

Implement support for oneOf #72

Open
buremba opened this issue Jan 20, 2020 · 4 comments
Open

Implement support for oneOf #72

buremba opened this issue Jan 20, 2020 · 4 comments

Comments

@buremba
Copy link

buremba commented Jan 20, 2020

Here is my schema:

{
"oneOf": [
        {
            "properties": {
                "target": { "$ref": "#/definitions/target" }
            },
            "required": ["target"]
        },
        {
            "properties": {
                "sql": { "$ref": "#/definitions/sql" }
            },
            "required": ["sql"]
        },
    ]
}

If my input has neither sql nor target, the error output is the following:

[{"start":{"line":1,"column":1,"offset":0},"error":" should have required property 'sql'","path":""}]

For the reference, here is the error output from Ajv:

[{"keyword":"required","dataPath":"","schemaPath":"#/oneOf/0/required","params":{"missingProperty":"target"},"message":"should have required property 'target'"},{"keyword":"required","dataPath":"","schemaPath":"#/oneOf/1/required","params":{"missingProperty":"sql"},"message":"should have required property 'sql'"},{"keyword":"oneOf","dataPath":"","schemaPath":"#/oneOf","params":{"passingSchemas":null},"message":"should match exactly one schema in oneOf"}]

I was expecting something like:

[{"start":{"line":1,"column":1,"offset":0},"error":" must have either 'sql' or 'target'","path":""}]
@crizo23
Copy link

crizo23 commented Oct 8, 2020

In your example, did you mean for:
"target": { "$ref": "#/definitions/sql" }
to be:
"sql": { "$ref": "#/definitions/sql" }

@buremba
Copy link
Author

buremba commented Oct 8, 2020

@crizo23 thanks correct, I updated the snippet. Thanks!

@crizo23
Copy link

crizo23 commented Oct 8, 2020

I've encountered the same issue. I'm pretty sure the problem is somewhere in helpers.js and its makeTree or filterRedundant methods - I think these methods are trying to be too smart and are filtering out errors we actually care about. I also think there could be a config option to ignore any processing in helpers.js and to return all errors returned by AJV

UPDATE: please ignore most of my comment above. After looking at the source code I now realize that the title of this issue is correct - oneOf just isn't yet supported in filterRedundant. Perhaps I'll attempt a fix

@crizo23
Copy link

crizo23 commented Oct 8, 2020

@buremba responding to your original question, I think the error you're expecting is in the AJV results, it's just not returned by better-ajv-errors:
"message":"should match exactly one schema in oneOf"

orgads pushed a commit to orgads/better-ajv-errors that referenced this issue Dec 3, 2023
chore(deps): update actions/checkout action to v3
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