-
Notifications
You must be signed in to change notification settings - Fork 18
Support $ref without a "file:" prefix #11
base: master
Are you sure you want to change the base?
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. |
lib/open_api_parser/pointer.rb
Outdated
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind removing comments for consistency with the rest of the library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean these ones: 9dcc0bd
or including all the other code comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the remainder in 0989f6a
lib/open_api_parser/reference.rb
Outdated
if @resolved | ||
fail 'Do not try to resolve an already resolved reference.' | ||
end | ||
@resolved = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we memoize this method such that subsequent calls return the same value rather than failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
spec/open_api_parser/pointer_spec.rb
Outdated
"#/i%5Cj" => 5, | ||
"#/k%22l" => 6, | ||
"#/%20" => 7, | ||
"#/m~0n" => 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These example are directly from the JSON Pointer RFC. We need to continue to support them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Changed the spec so that it tests by dropping the pound sign, not adding back: 1ea0e73
This PR adds support for
$ref
like'Pet.yaml'
and'definitions.yaml#/Pet'
, as seen in OpenAPI 2.0's examples. Also fixes some edge cases in the pointer resolution logic.