Closed dvv closed 14 years ago
model.A = {properties:{ id: String, title: String },id:'bar'}
model.B = {properties:{ id: String, a: {$ref:'bar'} }}
Please read JSON Schema drafts ;)
Heh. That's fine, I tried it before, but consider:
` var model = {}; model.Language = { type: 'object', id: 'Language', properties: { id: {type: 'string'}, name: {type: 'string'} } };
var schema = Schema.create({ type: 'object', id: 'User', properties: { //lang: {$ref: model.Language}, lang: {$ref: 'Language'} } });
object = { lang: 'AAA' };
validation = schema.validate(object); console.log(object); `
After validation object.lang is undefined. So what values to put to reference properties?
TIA, --Vladimir
You need to call
Schema.resolveRefs();
after having define schemas with refs to internally resolve the refs. I hope this solves your problem?
Is there some IRC channel for quicker iterations? :) Schema.resolveRefs();
made things go further, but lang: {$ref: 'Language'}
complains lang.id
and lang.name
are missing when I validate object.lang='a-dummy-string'
. What to to put to object.lang
for things to work? By sense a reference is a string such as /Language/en, say. No?
This is logical, because 'Language' wants to see an object, and not a string. What you want is:
lang: {$ref: 'Language.name'}
I remind you again: Read the both drafts I have used to implement schema.js very carefully. You can use #-based paths for relative and id-based paths for absolute referencing. A path is made up by dots.
I'm sorry, but to me schemas are magic, thus the questions. Nevertheless, if I do like say I get:
TypeError: Cannot call method 'call' of undefined at Validation.type (/home/dvv/NODE/akidee/lib/node/schema/index.js:237:35)
Please send me the whole example.
Please, take a look at http://gist.github.com/612860
Ha. I should have used lang: {$ref: 'Language.properties.id'}
!!! Damn, simple as the world :)
Closed.
Thanks, --Vladimir
Hi!
Suppose I have:
` model.A = {properties:{ id: String, title: String }}
model.B = {properties:{ id: String, a: ??? }} `
What should I substitute for definition of
B.properties.a
to make it a validating reference to an instance of model.A? Which value should I then feed toB.properties.a
for schema to be valid?TIA, --Vladimir