Skip to content

Instantly share code, notes, and snippets.

@NathanRSmith
Created June 16, 2015 17:49
Show Gist options
  • Save NathanRSmith/e09d671f0a72b43b781b to your computer and use it in GitHub Desktop.
Save NathanRSmith/e09d671f0a72b43b781b to your computer and use it in GitHub Desktop.
Themis nested error
var Themis = require('themis');
/********** NO **********/
var schema1 = {
"definitions": {
"stuff": {
"stuff1": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/stuff/anyStuff"
}
}
}
},
"stuff2": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/stuff/anyStuff"
}
}
}
},
"anyStuff": {
"type": "object",
"oneOf": [{
"$ref": "#/definitions/stuff/stuff1"
}, {
"$ref": "#/definitions/stuff/stuff2"
}]
}
},
"loadStuff": {
"type": "object",
"properties": {
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/stuff/anyStuff"
}
}
}
}
},
"type": "object",
"$ref": "#/definitions/loadStuff"
}
/********** YES **********/
var schema2 = {
"definitions": {
"stuff": {
"stuff1": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
},
"stuff2": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
}
},
"anyStuff": {
"type": "object",
"oneOf": [{
"$ref": "#/definitions/stuff/stuff1"
}, {
"$ref": "#/definitions/stuff/stuff2"
}]
},
"loadStuff": {
"type": "object",
"properties": {
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
}
},
"type": "object",
"$ref": "#/definitions/loadStuff"
}
/********** YES **********/
var schema3 = {
"definitions": {
"stuff1": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
},
"stuff2": {
"type": "object",
"properties": {
"thing1": {
"type": "string"
},
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
},
"anyStuff": {
"type": "object",
"oneOf": [{
"$ref": "#/definitions/stuff1"
}, {
"$ref": "#/definitions/stuff2"
}]
},
"loadStuff": {
"type": "object",
"properties": {
"stuff": {
"type": "array",
"items": {
"$ref": "#/definitions/anyStuff"
}
}
}
}
},
"type": "object",
"$ref": "#/definitions/loadStuff"
}
try {
Themis.validator(schema1);
console.log('should not reach here');
} catch (err) {
console.log('failed');
console.log(err.stack);
}
Themis.validator(schema2);
console.log('ok');
Themis.validator(schema3);
console.log('ok');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment