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

Validating an invalid data #520

Closed
1 of 3 tasks
jvenkat74 opened this issue Jun 6, 2024 · 3 comments
Closed
1 of 3 tasks

Validating an invalid data #520

jvenkat74 opened this issue Jun 6, 2024 · 3 comments

Comments

@jvenkat74
Copy link

When trying to validate the data against schema, we get it as valid using jsoncons, whereas it is not valid (as start variable has a string instead of integer)

Enumerate the steps to reproduce the bug

Attached are schema.json and data.json. This works against online JSON Schema validator properly.
data.json
schema.json

What compiler, architecture, and operating system?

  • Compiler: gcc
  • Architecture (e.g. x86, x64) x64
  • Operating system: Debian 12

What jsoncons library version?

  • Latest release 0.175.0
  • Other release ______
  • master
@jvenkat74 jvenkat74 added the Bug label Jun 6, 2024
@danielaparker
Copy link
Owner

danielaparker commented Jun 6, 2024

Interesting. This is the output that I get when I run it without format validation:

#include <iostream>
#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonschema/jsonschema.hpp>

// for brevity
using jsoncons::json;
using jsoncons::ojson;
namespace jsonschema = jsoncons::jsonschema;

int main() 
{
    std::string schema_str = R"(/*schema*/)";

    std::string data_str = R"(/*data*/)";

    try
    {
        ojson schema = ojson::parse(schema_str);
        jsonschema::json_schema<ojson> compiled = jsonschema::make_json_schema(std::move(schema)/*,
            jsonschema::evaluation_options{}.require_format_validation(true)*/);
        ojson data = ojson::parse(data_str);

        jsoncons::json_decoder<ojson> decoder;
        compiled.validate(data, decoder);
        ojson output = decoder.get_result();
        std::cout << pretty_print(output) << "\n";
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << "\n";
    }
}

Output:

[
    {
        "valid": false,
        "evaluationPath": "/properties/logicalapps/items/properties/listenIP/oneOf",
        "schemaLocation": "#/properties/logicalapps/items/properties/listenIP/oneOf",
        "instanceLocation": "/logicalapps/0/listenIP",
        "error": "Must be valid against exactly one schema, but found 2 matching schemas at indices 0,1"
    },

    ...

    {
        "valid": false,
        "evaluationPath": "/properties/logicalapps/items/properties/clientMode/items/properties/port/items/properties/start/type",
        "schemaLocation": "#/properties/logicalapps/items/properties/clientMode/items/properties/port/items/properties/start",
        "instanceLocation": "/logicalapps/0/clientMode/0/port/0/start",
        "error": "Expected integer, found string"
    }
]

Without format validation of the ip4 and ip6 addresses, it shows the integer error. But with, it doesn't. I need to check.

danielaparker added a commit that referenced this issue Jun 6, 2024
danielaparker added a commit that referenced this issue Jun 6, 2024
@danielaparker
Copy link
Owner

@jvenkat74 , this should be fixed on master, please check. The format validator was incorrectly returning an abort code on failure, so processing stopped before the port node.

@jvenkat74
Copy link
Author

It has been fixed. Error is getting flagged now. Thanks!

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

No branches or pull requests

2 participants