Support $ref without a "file:" prefix - #11
Conversation
Also supports reference to an external file with a pointer.
`path` could mean the path portion of a URI.
|
This is quite a large PR and will take me some time to review. Thanks for opening it. |
| @@ -1,5 +1,8 @@ | |||
| module OpenApiParser | |||
| # Responsible for interpreting the fragment portion of a $ref value | |||
| # as a JSON Pointer and resolving it within a given document. | |||
There was a problem hiding this comment.
Would you mind removing comments for consistency with the rest of the library?
There was a problem hiding this comment.
Did you mean these ones: 9dcc0bd
or including all the other code comments?
| if @resolved | ||
| fail 'Do not try to resolve an already resolved reference.' | ||
| end | ||
| @resolved = true |
There was a problem hiding this comment.
Can we memoize this method such that subsequent calls return the same value rather than failing?
There was a problem hiding this comment.
I've tried reducing the number of states that the Reference object holds: 134f3f8 so that #resolve can be called any number of times. This way, a Reference is a representation of a {"$ref": ".."} object, which can be resolved in many different contexts.
If you had performance concerns, I can look into caching the reference resolution result at the Document level.
| "#/i%5Cj" => 5, | ||
| "#/k%22l" => 6, | ||
| "#/%20" => 7, | ||
| "#/m~0n" => 8, |
There was a problem hiding this comment.
These example are directly from the JSON Pointer RFC. We need to continue to support them.
There was a problem hiding this comment.
👍 Changed the spec so that it tests by dropping the pound sign, not adding back: 1ea0e73
This PR adds support for
$reflike'Pet.yaml'and'definitions.yaml#/Pet', as seen in OpenAPI 2.0's examples. Also fixes some edge cases in the pointer resolution logic.