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

Schema pattern matching always comes back valid #45

Closed
mehagar opened this issue Jul 27, 2015 · 7 comments
Closed

Schema pattern matching always comes back valid #45

mehagar opened this issue Jul 27, 2015 · 7 comments

Comments

@mehagar
Copy link
Contributor

mehagar commented Jul 27, 2015

Schema:

{
    "$schema": "http://json-schema.org/draft-03/schema#",
    "type": "object",
    "properties": {
      "key": {
        "type": "string",
        "pattern": "ABC"
      }
    }
}

JSON String to validate

{
  "key": "123"
}

Example

   std::string jsonString = "{\n  \"key\": \"123\"\n}";
   WJReader reader = WJROpenMemDocument((void*)jsonString.c_str(), NULL, 0);
   WJElement doc = WJEOpenDocument(reader, NULL, NULL, NULL);

   std::string schemaString = "{\n    \"$schema\": \"http://json-schema.org/draft-03/schema#\",\n    \"type\": \"object\",\n    \"properties\": {\n      \"key\": {\n        \"type\": \"string\",\n        \"pattern\": \"ABC\"\n      }\n    }\n}";
   WJReader SchemaReader = WJROpenMemDocument((void*)schemaString.c_str(), NULL, 0);
   WJElement SchemaDoc = WJEOpenDocument(SchemaReader, NULL, NULL, NULL);

   if(WJESchemaValidate(
      SchemaDoc, doc,
      NULL, NULL, NULL, NULL))
   {
      std::cout << "schema matches\n";
   }
   else
   {
      std::cout << "schema does not match\n";
   }

This prints "schema matches\n", as does any other setting of the pattern.

@penduin
Copy link
Member

penduin commented Jul 27, 2015

The regex library isn't a hard dependency for WJElement, but I should
mention in the docs that parts of schema validation won't work as
expected without it.

Your code builds and runs as intended, actually. :^) I'm guessing
that when you configured with cmake, you got this message:
*** WARNING: GNU C regex library not found.
WJESchemaValidate() will not support patternProperties

I should tweak that to also mention "pattern", which uses the same
regex library. If you're building on a non-GNU C library, I think
there are several other regular expression libs which use the same
interface (and provide a compatible regex.h) but I don't know where to
point you off the top of my head.

Is that enough for you to go on?

On 7/27/15, mehagar notifications@github.com wrote:

Schema:

{
    "$schema": "http://json-schema.org/draft-03/schema#",
    "type": "object",
    "properties": {
      "key": {
        "type": "string",
        "pattern": "ABC"
      }
    }
}

JSON String to validate

{
  "key": "123"
}

Example

   std::string jsonString = "{\n  \"key\": \"123\"\n}";
   WJReader reader = WJROpenMemDocument((void*)jsonString.c_str(), NULL,
0);
   WJElement doc = WJEOpenDocument(reader, NULL, NULL, NULL);

   std::string schemaString = "{\n    \"$schema\":
\"http://json-schema.org/draft-03/schema#\",\n    \"type\": \"object\",\n
\"properties\": {\n      \"key\": {\n        \"type\": \"string\",\n
\"pattern\": \"ABC\"\n      }\n    }\n}";
   WJReader SchemaReader = WJROpenMemDocument((void*)schemaString.c_str(),
NULL, 0);
   WJElement SchemaDoc = WJEOpenDocument(SchemaReader, NULL, NULL, NULL);

   if(WJESchemaValidate(
      SchemaDoc, doc,
      NULL, NULL, NULL, NULL))
   {
      std::cout << "schema matches\n";
   }
   else
   {
      std::cout << "schema does not match\n";
   }

This prints "schema matches\n", as does any other setting of the pattern.


Reply to this email directly or view it on GitHub:
#45

@mehagar
Copy link
Contributor Author

mehagar commented Jul 27, 2015

I am indeed using a Windows library. I'll try using a compatible regex one for windows.

@minego
Copy link
Member

minego commented Jul 27, 2015

Please let us know if you find one that works so we can update instructions
for building on windows.
On Jul 27, 2015 1:07 PM, "mehagar" notifications@github.com wrote:

I am indeed using a Windows library. I'll try using a compatible regex one
for windows.


Reply to this email directly or view it on GitHub
#45 (comment)
.

@mehagar
Copy link
Contributor Author

mehagar commented Jul 27, 2015

I will. For now, it is appropriate to close this issue? The initial question has been answered.

@minego
Copy link
Member

minego commented Jul 27, 2015

Perhaps the ticket should stay open until we have updated the build to
make it clearer that this will happen? What do you think Owen?

On 07/27/15 15:27, mehagar wrote:

I will. For now, it is appropriate to close this issue? The initial
question has been answered.


Reply to this email directly or view it on GitHub
#45 (comment).

@penduin
Copy link
Member

penduin commented Jul 27, 2015

Yeah let's see what we learn here; there might be something we should
at least document before closing this. Thanks!

On 7/27/15, Micah N Gorrell notifications@github.com wrote:

Perhaps the ticket should stay open until we have updated the build to
make it clearer that this will happen? What do you think Owen?

On 07/27/15 15:27, mehagar wrote:

I will. For now, it is appropriate to close this issue? The initial
question has been answered.


Reply to this email directly or view it on GitHub
#45 (comment).


Reply to this email directly or view it on GitHub:
#45 (comment)

@penduin
Copy link
Member

penduin commented Aug 28, 2015

Haven't heard anything in a while, so I've just made the build warning more explicit if the regex library is absent.

I'll be happy to add further documentation and/or alternate library support if anyone has any such suggestions!

@penduin penduin closed this as completed Aug 28, 2015
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

3 participants