swagger2 icon indicating copy to clipboard operation
swagger2 copied to clipboard

External and Local References

Open cHolzberger opened this issue 8 years ago • 6 comments

Neither Local or Remote references are resolved when doing a compile, resulting in the swagger ui to display errors about missing definitions.

e.g.

definitions:
  InventoryItem:
    $ref: "InventoryItem.yml"

will not work, neither will

definitions:
  InventoryItem:
    $ref: "file:InventoryItem.yml"

nor

definitions:
  InventoryItem:
    $ref: "./InventoryItem.yml"

i would like to implement this functionality with the consequence that compile will need to be async then. the least problematic way would be to inline the definitions and switching to the async version of deref (it has more features and seems to be a better fit anyway) [http://bojand.github.io/json-schema-deref].

the resolution of external refs should be optional, either as flag or via a sperate function. (seen something similar here: https://github.com/BigstickCarpet/swagger-parser/blob/master/docs/swagger-parser.md#dereferenceapi-options-callback)

do you have any issues with doing so? i think loadDocument could be converted to async while doing so also.

cHolzberger avatar Nov 29 '16 00:11 cHolzberger

Go for it! Let me know if you have any questions/issues.

carlansley avatar Nov 29 '16 02:11 carlansley

ok, this is the first shot, not ready to be merged yet. https://github.com/cHolzberger/swagger2/commits/local-ref

i wonder how to write that test. can't make much sense out of the exiting tests (well haven't looked at it for long)

state is:

  • compile works async
  • $refs are solved starting at a defined basepath
  • $refs inside $refs are followed
  • you have to pass in the path where to start looking up refs to the compile function (which i don't like)

so far...

-- edit: also deref and compile are too closely related to each other, validation would only happen on the ref'ed document, i think it would be better to validate the deref'ed document .

any thoughts on this?

cHolzberger avatar Dec 11 '16 19:12 cHolzberger

I can have a look at doing the test(s) if you feel your implementation is in a decent state.

Regarding the deref, I agree I'd like it moved out of compile (that would break the current API, but nows the time to do it). How about a new deref and derefSync function that performs the deref separately from validate and compile. That way compile can stay synchronous as it is now.

carlansley avatar Dec 12 '16 20:12 carlansley

sounds good, i'll refactor

cHolzberger avatar Dec 13 '16 00:12 cHolzberger

What is the status of this issue? Swagger produces reference by default. This feature is needed :)

thpica avatar Aug 26 '17 17:08 thpica

Bump! Would be really useful...

Sytten avatar Jan 02 '19 07:01 Sytten