Open ml019 opened 10 years ago
So if you are trying to use $ref
to pull data into the instance (the data being validated), that won’t work. The $ref
keyword is only for use in schemas. Just due to the way that JSON Schema works, the instance is expected to be plain old JSON and no special processing is done to it before validation.
Thanks Nate, I figured that might be the case.
Is that a specific implementation choice you have made in JaySchema, or will all validators take that approach? As far as I can see from the JSON References RFC, its applicability isn't limited to use in JSON schemas.
As always, I am very appreciative of the prompt responses you provide.
Regards Michael
On Tue, Feb 4, 2014 at 4:08 AM, Nate Silva notifications@github.com wrote:
So if you are trying to use $ref to pull data into the instance (the data being validated), that won't work. The $ref keyword is only for use in schemas. Just due to the way that JSON Schema works, the instance is expected to be plain old JSON and no special processing is done to it before validation.
Reply to this email directly or view it on GitHubhttps://github.com/natesilva/jayschema/issues/24#issuecomment-33976026 .
JSON-Ref and JSON Pointer were created by some of the same folks who created JSON Schema. I believe they were created for use in schemas, but you’re right, there’s nothing limiting it to that.
I don’t know if other validators allow you to have a $ref
in your instance data. I believe most, if all, do not. It would be an interesting feature though.
Thanks Nate.
My use-case naturally lent itself to $ref in the schema AND in the instance. Basically it is a situation where you want to aggregate existing objects which already have their own schemas, and validate the aggregation as a whole.
Any chance of adding $ref for instances to your feature wish list?
Thanks
Michael
From: Nate Silva [mailto:notifications@github.com] Sent: Wednesday, 5 February 2014 3:56 AM To: natesilva/jayschema Cc: ml019 Subject: Re: [jayschema] Is the use of $ref in the JSON being validated supported? (#24)
JSON-Ref and [JSON Pointer])[http://tools.ietf.org/html/rfc6901] were created by some of the same folks who created JSON Schema. I believe they were created for use in schemas, but you’re right, there’s nothing limiting it to that.
I don’t know if other validators allow you to have a $ref in your instance data. I believe most, if all, do not. It would be an interesting feature though.
— Reply to this email directly or view it on GitHub https://github.com/natesilva/jayschema/issues/24#issuecomment-34080834 .Image removed by sender.
I posted this question to a closed issue accidently so not sure if anyone saw it. I am using $ref to pull in multiple values into the JSON being validated.
I wanted to confirm if Jayschema supports the use of $ref in the input to be validated. The errors I am getting would suggest it doesn't or more likely, I've not got the code quite right.
The data file looks like this
{ "Profile":{ "Type":"ebMS3_PModeOperationSet", "Purpose":"Positive", "Title":"PMode Operation Set for Superstream Entry Level", "Description":"Covers ultra-light and light profiles", "Version":{ "Major":0, "Minor":1 }
}, "PModes" : [ {"$ref" : "http://test.compliancetest.net/get-profile?id=e7359f244623457286c672a4c1e7ae7dc8eb405b"}, {"$ref" : "http://test.compliancetest.net/get-profile?id=1f1c6bb0c31a2a5f78fc4757ad20f39e242b16ff"}, {"$ref" : "http://test.compliancetest.net/get-profile?id=92befc2c857eef0d0d912901dfedaa11e4269afe"} ] }
and the schema looks like this
{ "$schema" : "http://json-schema.org/draft-04/schema#", "title" : "ebMS3 PMode Operation Set Profile", "Version" : { "Major" : 0, "Minor" : 1 },
"type" : "object", "properties" : { "Profile" : {"$ref" : "#/definitions/Profile/Profile"}, "PModes" : {"$ref" : "#/definitions/PMode/OperationSet"}
}, "required" : ["Profile", "PModes"],
"definitions" : { "Types" : { "NonNegativeInteger" : {"type" : "integer", "minimum" : 0},
} }
the errors I am getting are
[ { instanceContext: '#/PModes/0', resolutionScope: 'https://test.compliancetest.net/?download_profile_type=1&type_id=26#', constraintName: 'required', constraintValue: [ 'Profile', 'General' ], desc: 'missing: Profile,General', kind: 'ObjectValidationError' }, { instanceContext: '#/PModes/1', resolutionScope: 'https://test.compliancetest.net/?download_profile_type=1&type_id=26#', constraintName: 'required', constraintValue: [ 'Profile', 'General' ], desc: 'missing: Profile,General', kind: 'ObjectValidationError' }, { instanceContext: '#/PModes/2', resolutionScope: 'https://test.compliancetest.net/?download_profile_type=1&type_id=26#', constraintName: 'required', constraintValue: [ 'Profile', 'General' ], desc: 'missing: Profile,General', kind: 'ObjectValidationError' } ]
Is there a way to see what the schema validator thinks is the effective JSON it is validating? I'm thinking my data includes aren't right for some reason.
Thanks for your assistance.
Regards Michael