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 validation #38

Closed
romanpa opened this issue Jun 21, 2016 · 4 comments
Closed

Schema validation #38

romanpa opened this issue Jun 21, 2016 · 4 comments

Comments

@romanpa
Copy link

romanpa commented Jun 21, 2016

Hi

The schema below should catch an error in an object below.
But id does not :(

Map schemaMap = getSchemaMap();
JSONObject rawSchema = new JSONObject(schemaMap);
Schema schema = SchemaLoader.load(rawSchema);
schema.validate(....)

{
"type" : "object",
"id" : "urn:jsonschema:com:zzzzz:tests:commons:jsonschema:models:Person",
"properties" : {
"book" : {
"type" : "object",
"id" : "urn:jsonschema:com:zzzzz:tests:commons:jsonschema:models:PhoneBook",
"properties" : {
"numbers" : {
"type" : "array",
"items" : {
"type" : "object",
"id" : "urn:jsonschema:com:zzzzz:tests:commons:jsonschema:models:PhoneNumber",
"properties" : {
"number" : {
"type" : "string",
"pattern" : "+?\d+"
},
"type" : {
"type" : "string"
}
}
}
}
}
},
"phoneBooks" : {
"type" : "array",
"items" : {
"type" : "object",
"$ref" : "urn:jsonschema:com:zzzzz:tests:commons:jsonschema:models:PhoneBook"
}
}
}
}

{
"book" : {
"numbers" : [ {
"number" : "22222"
}, {
"number" : "11111"
} ]
},
"phoneBooks" : [ {
"numbers" : [ {
"number" : "22222"
}, {
"number" : "11111"
}, {
"number" : "aaaaa"
} ]
} ]
}

@erosb
Copy link
Contributor

erosb commented Jun 21, 2016

Please send a PR with a failing test as it is described in the contributing guidelines

@romanpa
Copy link
Author

romanpa commented Jun 22, 2016

Hi

I'am sorry but fork was not imported correctly into IntelliJ and i am very short on time, so i created a gist

https://gist.github.com/romanpa/0ee3437f59f634821d8c03af2eaf69d3

Regards,
romanpa

erosb added a commit to erosb/everit-json-schema that referenced this issue Jul 17, 2016
@erosb
Copy link
Contributor

erosb commented Jul 17, 2016

I've spent quite some time on examining this issue, and I found the followings:

  • the "$ref" references are not resolved during schema loading if the "type" property is present. So a definition like { "type": "object", "$ref": "..." } will have the same effect as just { "type": "object" }. This is clearly a bug to be fixed, probably in the next release.
  • on the other hand, supporting URNs won't happen any time soon. Existing JSON Schema implementations also seem to vary in supporting it.

@erosb erosb closed this as completed Jul 17, 2016
@romanpa
Copy link
Author

romanpa commented Jul 19, 2016

Thanks

erosb added a commit that referenced this issue Jan 22, 2019
Reference: section 8.3.1 of json schema core draft-7 says:
"Such URIs and schemas can be supplied to an implementation prior to processing instances"

So here if the caller associates a raw schema to an URI using `SchemaLoaderBuilder#registerSchemaByURI()` then the loader
will recognize this URI and load the associated raw schema without hitting the network or any external protocols.

This was originally requested in #38.
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