When the $ref keyword value is a relative URI it should resolved against the schema's Base URI. Currently the relative URI is being concatenated with the previous path segment.
The examples here are those from json-schema.org:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://example.com/schemas/address",
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
]
}
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "https://example.com/schemas/customer",
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"shipping_address": {
"$ref": "/schemas/address"
},
"billing_address": {
"$ref": "/schemas/address"
}
},
"required": [
"first_name",
"last_name",
"shipping_address",
"billing_address"
]
}
{
"first_name": "john",
"last_name": "smith",
"billing_address": {
"street_address": "1 Main",
"city": "Springfield",
"state": "MO"
}
}
1> {ok, Address} = file:read_file("address.json").
2> {ok, Customer} = file:read_file("customer.json").
3> {ok, John} = file:read_file("john.json").
4> jesse:add_schema("https://example.com/schemas/address", json:decode(Address)).
5> jesse:add_schema("https://example.com/schemas/customer", json:decode(Customer)).
6> jesse:validate("https://example.com/schemas/customer", json:decode(John)).
{error,[{schema_invalid,[{<<"$ref">>,
<<"/schemas/address">>}],
{schema_not_found,"https://example.com/schemas//schemas/address"}}]}
The resolved URI should be https://example.com/schemas/address.
When the
$refkeyword value is a relative URI it should resolved against the schema's Base URI. Currently the relative URI is being concatenated with the previous path segment.The examples here are those from json-schema.org:
{ "$schema": "http://json-schema.org/draft-06/schema#", "$id": "https://example.com/schemas/address", "type": "object", "properties": { "street_address": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" } }, "required": [ "street_address", "city", "state" ] }{ "$schema": "http://json-schema.org/draft-06/schema#", "$id": "https://example.com/schemas/customer", "type": "object", "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" }, "shipping_address": { "$ref": "/schemas/address" }, "billing_address": { "$ref": "/schemas/address" } }, "required": [ "first_name", "last_name", "shipping_address", "billing_address" ] }{ "first_name": "john", "last_name": "smith", "billing_address": { "street_address": "1 Main", "city": "Springfield", "state": "MO" } }The resolved URI should be
https://example.com/schemas/address.