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

Invalid JSON is accepted by validator. #2

Closed
nosachamos opened this issue Dec 13, 2011 · 3 comments
Closed

Invalid JSON is accepted by validator. #2

nosachamos opened this issue Dec 13, 2011 · 3 comments
Assignees

Comments

@nosachamos
Copy link

I had the following JSON schema defined:
{
"description" : "Example Address JSON Schema",
"type" : "object",
"properties" : {
"address" : {
"title": "Street name and number",
"type" : "string"
},
"city" : {
"title" : "City name",
"type" : "string"
},
"postalCode" : {
"title" : "Zip Code: 2 letters dash five digits",
"type" : "string",
"pattern" : "^[A-Z]{2}-[0-9]{5}"
},
"region" : {
"title" : "Optional Region name",
"type" : "string",
"optional" : true
}
},
"additionalProperties" : false
}

Then I attempted to validate the following JSON, which is invalid since non-optional property "city" is missing:

{
"address" : "happy fake address"
}

But it accepted as valid.

@fge
Copy link
Collaborator

fge commented Dec 15, 2011

Erm, no, it is valid!

Your schema says, for address:

"address" : {
"title": "Street name and number",
"type" : "string"
}

Your address is a string.

If you want to make one or more properties required, add "required": true to the schema of these properties.

@ghost ghost assigned fge Dec 15, 2011
@fge
Copy link
Collaborator

fge commented Dec 15, 2011

BTW, which version do you use? and which version of JSON Schema, too? The optional keyword no longer exists.

@fge
Copy link
Collaborator

fge commented Dec 27, 2011

Closing. Referring to an obsolete schema version.

However, if you deem it important to support draft v2, I can manage that.

@fge fge closed this as completed Dec 27, 2011
fge added a commit that referenced this issue May 27, 2012
Instead, just define the base checkValue() method as doig nothing, and make all
ex-inheritors of SimpleSyntaxChecker inherit from SyntaxChecker.
fge added a commit that referenced this issue May 27, 2012
…xChecker

Make children types be an EnumSet in the constructor.
fge added a commit that referenced this issue May 27, 2012
…ation

It was not a good idea after all, and is more confusing than anything else.
fge added a commit that referenced this issue May 27, 2012
…face

And remove a now unneeded check in AbstractSyntaxChecker's .checkSyntax().
fge added a commit that referenced this issue May 27, 2012
Both a single type and multipe types. I wonder whether both tests are
justified...
fge added a commit that referenced this issue May 27, 2012
Rename AbstractSyntaxChecker to SimpleSyntaxChecker, since this is what it
really is.

Also, don't make it abstract.
fge added a commit that referenced this issue May 27, 2012
11 classes were just direct inheritors of SimpleSyntaxValidator, just build
SyntaxValidator instances instead.
fge added a commit that referenced this issue May 27, 2012
…axChecker

It is now a class by itself. Make tests for it.
fge added a commit that referenced this issue May 27, 2012
Validators for m{in,ax}{Length,Items} are now instantiated from
PositiveIntegerSyntaxChecker. Remove classes and tests.
fge added a commit that referenced this issue May 27, 2012
…class

The test already existed but sported a now unneeded private class: remove it.
fge added a commit that referenced this issue May 27, 2012
fge added a commit that referenced this issue May 27, 2012
Same treatment for TypeKeywordSyntaxChecker and derivates.
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