tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
283 stars 57 forks source link

Resolves id in value #80

Closed adamschnaare closed 5 years ago

adamschnaare commented 5 years ago

id wasn't seeming to resolve correctly.

adamschnaare commented 5 years ago

@tlivings - not sure why the checks are failing, but just wanted to suggest a small edit.

tlivings commented 5 years ago

Looks like a test running is having an issue:

# with external ref
323/home/travis/build/tlivings/enjoi/lib/resolver.js:6
324cov_2kqrv0iw6h.s[35]++;return this.joi.any();}resolveReference(value){cov_2kqrv0iw6h.f[4]++;let refschema;const id=(cov_2kqrv0iw6h.s[36]++,value.substr(value.indexOf('#')+1,value.length));const path=(cov_2kqrv0iw6h.s[37]++,value.substr(value.indexOf('#')+1));cov_2kqrv0iw6h.s[38]++;if((cov_2kqrv0iw6h.b[12][0]++,id)&&(cov_2kqrv0iw6h.b[12][1]++,this.subSchemas)){cov_2kqrv0iw6h.b[11][0]++;cov_2kqrv0iw6h.s[39]++;refschema=(cov_2kqrv0iw6h.b[13][0]++,this.subSchemas[id])||(cov_2kqrv0iw6h.b[13][1]++,this.subSchemas[id.substr(0,id.length-1)]);}else{cov_2kqrv0iw6h.b[11][1]++;}cov_2kqrv0iw6h.s[40]++;if(!refschema){cov_2kqrv0iw6h.b[14][0]++;cov_2kqrv0iw6h.s[41]++;refschema=this.root;}else{cov_2kqrv0iw6h.b[14][1]++;}cov_2kqrv0iw6h.s[42]++;Hoek.assert(refschema,'Can not find schema reference: '+value+'.');let fragment=(cov_2kqrv0iw6h.s[43]++,refschema);const paths=(cov_2kqrv0iw6h.s[44]++,path.split('/'));cov_2kqrv0iw6h.s[45]++;for(let i=(cov_2kqrv0iw6h.s[46]++,1);(cov_2
325
326RangeError: Maximum call stack size exceeded
327    at resolveproperties (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:5130)
328    at SchemaResolver.object (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:5962)
329    at joitype (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:2154)
330    at SchemaResolver.resolveType (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:3427)
331    at SchemaResolver.resolve (/home/travis/build/tlivings/enjoi/lib/resolver.js:1:30105)
332    at SchemaResolver.resolve (/home/travis/build/tlivings/enjoi/lib/resolver.js:1:30870)
333    at /home/travis/build/tlivings/enjoi/lib/resolver.js:6:5550
334    at Array.forEach (<anonymous>)
335    at resolveproperties (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:5405)
336    at SchemaResolver.object (/home/travis/build/tlivings/enjoi/lib/resolver.js:6:5962)
tlivings commented 5 years ago

What is the change you are trying to make?

tlivings commented 5 years ago

I think what you are looking for is this: https://github.com/tlivings/enjoi#sub-schemas

But the documentation is actually wrong. A sub-schema reference should be subSchema#/... and in this case, id will resolve to subSchema, which is the desired behavior.

# is the "root" schema, which means the reference is referring to the current document. You would only have a value for id be different when referencing external / additional schemas by name.

Does this make sense?

adamschnaare commented 5 years ago

Yep! Get it now. I was just confused by the doc. I'll remove the PR. Thanks for the time and help.