Git Product home page Git Product logo

Comments (3)

natesilva avatar natesilva commented on September 26, 2024

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.

ml019 avatar ml019 commented on September 26, 2024

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.

ml019 avatar ml019 commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.