Open pimterry opened 3 years ago
Hey @pimterry, did you get a chance to dig into this at all, or is it still an issue? There's a loooooot of issues here and I'm trying to help, but maintenance of this repo isn't my job and I know you're smart! :D
Hey @philsturgeon! I haven't dug into this any further, but I've just tested with the same code from above, and I can confirm it's still an issue: bundling the official GitHub OpenAPI spec fails with the same error, because it tries to dereference a $ref that's part of an example response, not a real usable reference.
The prerequisite for implementing this (https://github.com/APIDevTools/json-schema-ref-parser/pull/249) just shipped!
We could now fix this here, we just need to pass an excludedPathMatcher
option that can recognize valid examples
paths in an OpenAPI document (i.e. match any path to an Example Object) so we treat those literally and skip dereferencing them.
Just to update this: this is still an issue, and the current behaviour is certainly incorrect, but it fell off my todo list because GitHub changed their spec instead so it no longer applies to my use case.
If anybody else is interested in this, feel free to pick it up! The new json-schema-ref-parser feature from https://github.com/APIDevTools/json-schema-ref-parser/pull/249 should be sufficient to do this, you just need to use that to define which parts of an OpenAPI spec should not be dereferenced automatically (i.e. which parts are literal examples).
Not all
$ref
properties are actual refs that should be dereferenced. Inexample
values specifically,$ref
can be used for a literal field name, and should never be dereferenced (I think? https://github.com/OAI/OpenAPI-Specification/issues/1986#issuecomment-519988505 seems to agree).This matters unfortunately because GitHub's API spec does exactly that: https://github.com/github/rest-api-description/issues/188. In their
components.examples
they have:The
$ref
properties within this are literal values, as they would be returned by the API. Bundling this spec fails, like so:Not sure if this applies to cases other than examples, but I wouldn't be that surprised.