Closed skryukov closed 4 years ago
I'm not sure what you mean. Can you provide an example using a JSONSchemer schema?
@davishmcclurg sure =)
This example inspired by OpenAPI 3 schemas that contain keys like /some/path/{id}
:
require 'json_schemer'
schema = {
'type' => 'object',
'properties' => { 'foo' => { '$ref' => '#/definitions/~1some~1{id}'} },
'definitions' => { '/some/{id}' => { 'type' => 'string' } }
}
Hana::Pointer.new('/definitions/~1some~1{id}').eval(schema)
# => {"type"=>"string"}
schemer = JSONSchemer.schema(schema)
schemer.valid?('foo' => 'bar')
# raises URI::InvalidURIError (bad URI(is not URI?): "#/definitions/~1some~1{id}")
Fix released in 0.2.9
The fix for this is going to be reverted in v1.0.0. The json schema spec says that $ref
needs to be a URI reference, which is defined in RFC 3986. URI fragments are defined there as:
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
fragment = *( pchar / "/" / "?" )
unreserved
and sub-delims
don't include {
or }
so they must be percent encoded.
In your example, it would be #/definitions/~1some~1%7Bid%7D
.
Tested in v1.0.0 (unreleased):
>> JSONSchemer.valid_schema?({ '$ref' => '#/definitions/~1some~1%7Bid%7D' })
=> true
>> JSONSchemer.valid_schema?({ '$ref' => '#/definitions/~1some~1{id}' })
=> false
URI::RFC3986_PARSER.parse
is too restrictive for the JSON pointers. Here is the fragment from RFC 6901: