-
Notifications
You must be signed in to change notification settings - Fork 14
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
Error thrown during validation if schema contains an id
#103
Comments
Thanks for the report. I'll see what I can do. |
@jasonkarns, this is a usage issue (which may also indicate a design problem). I've modified your example to make it work: jsck = new JSCK.draft4
id: "urn:some.id#"
type: "object"
properties:
user:
type: "object"
required: ["login"]
properties:
login:
type: "string"
pattern: "^[\\w\\d_]{3,32}$"
email:
type: "string"
format: "email"
validator = jsck.validator(uri: "urn:some.id#")
validator.validate
user:
login: "matthew"
email: "[email protected]" An instance of JSCK may contain numerous schemas, all with different |
@automatthew can we improve the docs on that? |
We can and should. |
@automatthew or if we don't see a URI, can we simply assume there's only one |
Yeah, maybe with this logic:
|
Part of this is still throwing me for a loop. I understand current behavior, but note in my example I'm only constructing the validator with a single schema. Presence of an ID in the schema does not change the fact that the validator still only has a single schema and should operate as such. Basically, current behavior is saying that the content of a schema will alter the acceptable usage of the validator. And that's a flaw, IMO. |
I agree. I'll be altering it per my comment just above. Another option I considered is having two different validation classes: one for the case where you are using a single schema, and another for when you want the validator to have access to several. That is arguably more semantically accurate, but probably even more confusing. For most of our use cases (and it seems also for yours) we don't need to have multiple schema documents within a single validator. We use |
Sample taken directly from the Readme, with an
id
added to the schema:This throws the error:
Based on my debugging, this occurs because a schema's
id
is used as the key for that schema. If no id is provided, then the schema is indexed with#
as the key.jsck/src/validator.coffee
Lines 78 to 80 in fdc93ac
Then when validation is attempted, the validate call just blindly uses
'#'
as the key to lookup the schema:jsck/src/validator.coffee
Line 86 in fdc93ac
If the schema in question has an id, then the schema lookup fails to find one indexed under
'#'
, and throws the error:jsck/src/validator.coffee
Line 107 in fdc93ac
The text was updated successfully, but these errors were encountered: