json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Error resolving $ref for property alongside top-level $ref

Open taicho opened this issue 8 years ago • 2 comments

All,

I'm having an issue resolving a reference. Having tested a couple scenarios, I was happy to see that providing a top-level reference and included some other properties alongside the $ref netted me a merged/combined object, for example:

Dereferencing this:

{
    "$ref":"http://someuri/myOtherSchema",
    "anotherProperty":"whatever"
}

Results in this (imagining myOtherSchema contains the added properties):

{
    "somePropertyFromMyOtherSchema": "misc",
    "anotherPropertyFromMyOtherSchema":"more",
    "anotherProperty": "whatever"
}

However, if I attempt to dereference the following:

{
    "$ref": "http://someuri/foo",
    "anotherProperty": {"$ref":"http://someuri/blah/some/field/value"}
}

It results in an error ('Error resolving $ref: http://someuri/blah/some/field/value'). It's worth noting that I am using a custom resolver and I changed the $ref urls for this post but removing the top-level $ref results in success i.e. my resolver is working as expected and in fact is a simple in-memory resolver. When this error happens the $ref mentioned in the error never even hits my resolver and its resolution is never attempted. Is having a top-level $ref alongside a property that points to a $ref expressly forbidden by the specification, is this a flaw or a feature of json-schema-ref-parser?

taicho avatar Sep 20 '17 21:09 taicho

I'm closing this. This still fails when doing a straight dereference call but doing bundle -> dereference allows me to get the result I was looking for.

taicho avatar Sep 21 '17 14:09 taicho

@taicho - Thanks for reporting this. I honestly never even thought about that use-case, so never tested for it. I'm going to re-open this issue as a reminder to fix this and add a test. I'm glad you found an acceptable workaround for the time-being though

JamesMessinger avatar Sep 21 '17 15:09 JamesMessinger