Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Validator = require('jsonschema').Validator;
- var v = new Validator();
- // Address, to be embedded on Person
- var addressSchema = {
- id: "/SimpleAddress",
- type: "object",
- properties: {
- lines: {
- type: "array",
- items: {type: "string"}
- },
- zip: {type: "string"},
- city: {type: "string"},
- country: {type: "string"}
- },
- required: ["country"]
- };
- // Person
- var schema = {
- id: "/SimplePerson",
- type: "object",
- properties: {
- name: {type: "string"},
- address: {$ref: "/SimpleAddress"},
- votes: {type: "integer", "minimum": 1}
- }
- };
- var p = {
- name: "Barack Obama",
- address: {
- lines: [ "1600 Pennsylvania Avenue Northwest" ],
- zip: "DC 20500",
- city: "Washington",
- country: "USA"
- },
- votes: 5
- };
- v.addSchema(addressSchema, '/SimpleAddress');
- var result = v.validate(p, schema);
- console.log("Validation result:", result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement