Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. var Validator = require('jsonschema').Validator;
  2. var v = new Validator();
  3.  
  4. // Address, to be embedded on Person
  5. var addressSchema = {
  6. id: "/SimpleAddress",
  7. type: "object",
  8. properties: {
  9. lines: {
  10. type: "array",
  11. items: {type: "string"}
  12. },
  13. zip: {type: "string"},
  14. city: {type: "string"},
  15. country: {type: "string"}
  16. },
  17. required: ["country"]
  18. };
  19.  
  20. // Person
  21. var schema = {
  22. id: "/SimplePerson",
  23. type: "object",
  24. properties: {
  25. name: {type: "string"},
  26. address: {$ref: "/SimpleAddress"},
  27. votes: {type: "integer", "minimum": 1}
  28. }
  29. };
  30.  
  31. var p = {
  32. name: "Barack Obama",
  33. address: {
  34. lines: [ "1600 Pennsylvania Avenue Northwest" ],
  35. zip: "DC 20500",
  36. city: "Washington",
  37. country: "USA"
  38. },
  39. votes: 5
  40. };
  41.  
  42. v.addSchema(addressSchema, '/SimpleAddress');
  43. var result = v.validate(p, schema);
  44. console.log("Validation result:", result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement