Skip to content

relative references do not resolve against the base uri #141

@vances

Description

@vances

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions