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

The result schema of the "oneOf" validation keyword does not match its documentation #2311

Open
bduminiuc opened this issue Oct 15, 2024 · 0 comments

Comments

@bduminiuc
Copy link

I found a commit changing the result of "oneOf" validation.

commit 338d8defdb79eeff5f9801bd443ef9a4ae5bb8e7
Author: Steve Hanson <[email protected]>
Date:   Thu Jun 17 08:58:37 2021 +0100

    initial

I try to parse invalid json with the following schema:

{
    "oneOf": [
        { "type": "integer" },
        { "type": "number" },
        { "type": "string", "pattern": "^z" }
    ]
}

Before the commit, the validator output is:

{"oneOf":{"errors":[{},{},{"type":{"expected":["string"],"actual":"integer","errorCode":20,"instanceRef":"#","schemaRef":"#/oneOf/2"}}],"errorCode":22,"instanceRef":"#","schemaRef":"#"}}

but after:

{"oneOf":{"matches":[0,1],"errorCode":22,"instanceRef":"#","schemaRef":"#"}}

However, I see the documentation says:

allOf, anyOf, and oneOf
errors: required array of at least one object.

So, either it is a mistake in the documentation or the code. But what is the correct one?

Snippet to reproduce:

using namespace rapidjson;

Document sd;
sd.Parse(schema_str);
auto const schema = SchemaDocument{sd};

Document d;
d.Parse("1");  // invalid json

SchemaValidator validator{schema};
if (!d.Accept(validator)) {
    MemoryPoolAllocator<> allocator;
    auto ret = Value(validator.GetError(), allocator);

    StringBuffer sb;
    Writer<StringBuffer> w{sb};
    ret.Accept(w);
    std::cout << sb.GetString();
} else {
    std::cout << "no error";
}
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

1 participant