swagger2
swagger2 copied to clipboard
External and Local References
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.
Go for it! Let me know if you have any questions/issues.
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?
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.
sounds good, i'll refactor
What is the status of this issue? Swagger produces reference by default. This feature is needed :)
Bump! Would be really useful...