Comments (3)
When you call the JaySchema constructor, are you providing a loader callback? Try something like this:
var JaySchema = require('jayschema');
var js = new JaySchema(JaySchema.loaders.http); // we provide the HTTP loader here
var instance = {
"OperationSet": [
{ "latitude": 37.421999, "longitude": -122.083954 }
]
};
var schema = {
"properties": {
"OperationSet": {
"items": {
"$ref": "http://json-schema.org/geo"
},
"minItems": 1,
"type": "array"
}
}
};
js.validate(instance, schema, function(errs) {
if (errs) { console.error(errs); }
else { console.log('validation OK!'); }
});
This worked for me, but note that the json-schema.org web site sometimes returns ECONNREFUSED
. Try again until it works. And of course, host the schema on a server you control if you need it to be reliable.
from jayschema.
Ah ok.
I made the assumption that http/https support was built in. I saw other emails about file system based loaders and relative URLs but assumed the http support was already there.
I’ll give this a try.
Thanks
Michael
From: Nate Silva [mailto:[email protected]]
Sent: Wednesday, 29 January 2014 3:37 AM
To: natesilva/jayschema
Cc: ml019
Subject: Re: [jayschema] Schema not available errors with http/https JSON references (#23)
When you call the JaySchema constructor, are you providing a loader callback? Try something like this:
var JaySchema = require('jayschema');
var js = new JaySchema(JaySchema.loaders.http); // we provide the HTTP loader here
var instance = {
"OperationSet": [
{ "latitude": 37.421999, "longitude": -122.083954 }
]
};
var schema = {
"properties": {
"OperationSet": {
"items": {
"$ref": "http://json-schema.org/geo"
},
"minItems": 1,
"type": "array"
}
}
};
js.validate(instance, schema, function(errs) {
if (errs) { console.error(errs); }
else { console.log('validation OK!'); }
});
This worked for me, but note that the json-schema.org web site sometimes returns ECONNREFUSED. Try again until it works. And of course, host the schema on a server you control if you need it to be reliable.
—
Reply to this email directly or view it on GitHub #23 (comment) . https://github.com/notifications/beacon/5861038__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwNjQ1OTgzOCwiZGF0YSI6eyJpZCI6MjQ0MTMyMjZ9fQ==--135e51bdf8b5587fc5c62005b94b020fc1d9665f.gif
from jayschema.
Hi Nate.
The example code you provided is now working thank you.
I have an extra complication now in that the JSON being validated itself uses $ref to include other JSON data files - effectively the included schema validates each of the included data files.
The validator is indicating that each of the included data files does not have the properties required by the included schema, but the files validate successfully standard-alone against the included schema.
So 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},
"MultipleOf8" : {"allOf": [{"$ref" : "#/definitions/Types/NonNegativeInteger"}, { "multipleOf": 8}]},
"NonEmptyString" : {"type" : "string", "minLength" : 1},
"URI" : {"type" : "string", "format" : "uri", "minLength" : 1},
"Boolean" : {"type": "boolean"},
"BooleanDefaultFalse" : {"allOf": [{"$ref" : "#/definitions/Types/Boolean"}, { "default": false }]},
"BooleanDefaultTrue" : {"allOf": [{"$ref" : "#/definitions/Types/Boolean"}, { "default": true }]},
"TimeUnit" : {"enum" : ["seconds", "minutes", "hours", "days", "weeks"]}
},
"Profile" : {
"Type" : {"enum" : ["ebMS3_PModeOperationSet"]},
"Purpose" : {"enum" : ["Positive", "Negative"], "default" : "Positive"},
"Version" : {
"type" : "object",
"properties" : {
"Major" : {"$ref" : "#/definitions/Types/NonNegativeInteger"},
"Minor" : {"$ref" : "#/definitions/Types/NonNegativeInteger"},
"Patch" : {"$ref" : "#/definitions/Types/NonNegativeInteger"}
},
"required" : ["Major", "Minor"]
},
"Profile" : {
"type" : "object",
"properties" : {
"Type" : {"$ref" : "#/definitions/Profile/Type"},
"Purpose" : {"$ref" : "#/definitions/Profile/Purpose"},
"Title" : {"$ref" : "#/definitions/Types/NonEmptyString"},
"Description" : {"$ref" : "#/definitions/Types/NonEmptyString"},
"Version" : {"$ref" : "#/definitions/Profile/Version"}
},
"required" : ["Type", "Purpose", "Title", "Description", "Version"]
}
},
"PMode" : {
"OperationSet" : {
"type" : "array",
"items" : {"$ref" : "https://test.compliancetest.net/?download_profile_type=1&type_id=26"},
"minItems" : 1
}
}
}
}
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' } ]
If 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. I am growing to love JSON schema more each day...
Regards
Michael
from jayschema.
Related Issues (20)
- Custom validation?
- Are custom formats supported? HOT 5
- Enum with null throwing error HOT 3
- Format "uri" is not throwing errors HOT 2
- validator._schemaRegistry not API ?
- Callback not invoked for undefined enum with custom loader HOT 2
- async callback
- Validator is not detecting bad enum value HOT 2
- Speed: the validator is-my-json-valid is thousands of times faster then jayschema HOT 3
- Support CLI usage HOT 1
- Validating schemas themselves HOT 3
- Combining oneOf + enum causes the rejection of enum fields
- error: Undefined should be an object
- Support browserify; get rid of dynamically loaded dependencies HOT 1
- validate hang HOT 1
- Leap seconds
- Line numbers?
- broken link
- TypeError: Cannot convert undefined or null to object HOT 1
- $ref with spaces does not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jayschema.