From d4d30f1cb112cc38be738bac416f47e8798ecc32 Mon Sep 17 00:00:00 2001 From: Johan Dorland Date: Thu, 17 May 2018 16:34:30 +0200 Subject: [PATCH 1/2] Add tests for location-independent identifiers --- tests/draft4/ref.json | 105 ++++++++++++++++++++++++++++++++++++++++++ tests/draft6/ref.json | 105 ++++++++++++++++++++++++++++++++++++++++++ tests/draft7/ref.json | 105 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 315 insertions(+) diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index 52cf50a9..2158b4be 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -296,5 +296,110 @@ "valid": false } ] + }, + { + "description": "Location-independent identifier", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Canonical location-independent identifier", + "schema": { + "$ref": "http://localhost:1234/bar#foo", + "definitions": { + "A": { + "id": "http://localhost:1234/bar#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#foo", + "definitions": { + "A": { + "id": "nested.json", + "definitions": { + "B": { + "id": "#foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifiers should take precedent over regular fragments", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "id": "#foo", + "type": "integer" + } + }, + "foo": { + "type": "string" + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] } ] diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 5b589649..15d69164 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -328,5 +328,110 @@ "valid": false } ] + }, + { + "description": "Location-independent identifier", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Canonical location-independent identifier", + "schema": { + "$ref": "http://localhost:1234/bar#foo", + "definitions": { + "A": { + "$id": "http://localhost:1234/bar#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#foo", + "definitions": { + "A": { + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifiers should take precedent over regular fragments", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + }, + "foo": { + "type": "string" + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] } ] diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 75795076..770c5eab 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -328,5 +328,110 @@ "valid": false } ] + }, + { + "description": "Location-independent identifier", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Canonical location-independent identifier", + "schema": { + "$ref": "http://localhost:1234/bar#foo", + "definitions": { + "A": { + "$id": "http://localhost:1234/bar#foo", + "type": "integer" + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$id": "http://localhost:1234/root", + "$ref": "http://localhost:1234/nested.json#foo", + "definitions": { + "A": { + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] + }, + { + "description": "Location-independent identifiers should take precedent over regular fragments", + "schema": { + "$ref": "#foo", + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + }, + "foo": { + "type": "string" + } + }, + "tests": [ + { + "data": 1, + "description": "match", + "valid": true + }, + { + "data": "a", + "description": "mismatch", + "valid": false + } + ] } ] From c98ffc39e23865526ab9bc3a8cfc5431ed08e9cd Mon Sep 17 00:00:00 2001 From: Johan Dorland Date: Tue, 26 Jun 2018 18:38:40 +0200 Subject: [PATCH 2/2] Remove one wrong testcase and put every $ref in an allOf. --- tests/draft4/ref.json | 39 +++++++++------------------------------ tests/draft6/ref.json | 39 +++++++++------------------------------ tests/draft7/ref.json | 39 +++++++++------------------------------ 3 files changed, 27 insertions(+), 90 deletions(-) diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index 2158b4be..481117a7 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -300,7 +300,9 @@ { "description": "Location-independent identifier", "schema": { - "$ref": "#foo", + "allOf": [{ + "$ref": "#foo" + }], "definitions": { "A": { "id": "#foo", @@ -324,7 +326,9 @@ { "description": "Canonical location-independent identifier", "schema": { - "$ref": "http://localhost:1234/bar#foo", + "allOf": [{ + "$ref": "http://localhost:1234/bar#foo" + }], "definitions": { "A": { "id": "http://localhost:1234/bar#foo", @@ -349,7 +353,9 @@ "description": "Location-independent identifier with base URI change in subschema", "schema": { "id": "http://localhost:1234/root", - "$ref": "http://localhost:1234/nested.json#foo", + "allOf": [{ + "$ref": "http://localhost:1234/nested.json#foo" + }], "definitions": { "A": { "id": "nested.json", @@ -374,32 +380,5 @@ "valid": false } ] - }, - { - "description": "Location-independent identifiers should take precedent over regular fragments", - "schema": { - "$ref": "#foo", - "definitions": { - "A": { - "id": "#foo", - "type": "integer" - } - }, - "foo": { - "type": "string" - } - }, - "tests": [ - { - "data": 1, - "description": "match", - "valid": true - }, - { - "data": "a", - "description": "mismatch", - "valid": false - } - ] } ] diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 15d69164..68dbce28 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -332,7 +332,9 @@ { "description": "Location-independent identifier", "schema": { - "$ref": "#foo", + "allOf": [{ + "$ref": "#foo" + }], "definitions": { "A": { "$id": "#foo", @@ -356,7 +358,9 @@ { "description": "Canonical location-independent identifier", "schema": { - "$ref": "http://localhost:1234/bar#foo", + "allOf": [{ + "$ref": "http://localhost:1234/bar#foo" + }], "definitions": { "A": { "$id": "http://localhost:1234/bar#foo", @@ -381,7 +385,9 @@ "description": "Location-independent identifier with base URI change in subschema", "schema": { "$id": "http://localhost:1234/root", - "$ref": "http://localhost:1234/nested.json#foo", + "allOf": [{ + "$ref": "http://localhost:1234/nested.json#foo" + }], "definitions": { "A": { "$id": "nested.json", @@ -406,32 +412,5 @@ "valid": false } ] - }, - { - "description": "Location-independent identifiers should take precedent over regular fragments", - "schema": { - "$ref": "#foo", - "definitions": { - "A": { - "$id": "#foo", - "type": "integer" - } - }, - "foo": { - "type": "string" - } - }, - "tests": [ - { - "data": 1, - "description": "match", - "valid": true - }, - { - "data": "a", - "description": "mismatch", - "valid": false - } - ] } ] diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 770c5eab..a641f386 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -332,7 +332,9 @@ { "description": "Location-independent identifier", "schema": { - "$ref": "#foo", + "allOf": [{ + "$ref": "#foo" + }], "definitions": { "A": { "$id": "#foo", @@ -356,7 +358,9 @@ { "description": "Canonical location-independent identifier", "schema": { - "$ref": "http://localhost:1234/bar#foo", + "allOf": [{ + "$ref": "http://localhost:1234/bar#foo" + }], "definitions": { "A": { "$id": "http://localhost:1234/bar#foo", @@ -381,7 +385,9 @@ "description": "Location-independent identifier with base URI change in subschema", "schema": { "$id": "http://localhost:1234/root", - "$ref": "http://localhost:1234/nested.json#foo", + "allOf": [{ + "$ref": "http://localhost:1234/nested.json#foo" + }], "definitions": { "A": { "$id": "nested.json", @@ -406,32 +412,5 @@ "valid": false } ] - }, - { - "description": "Location-independent identifiers should take precedent over regular fragments", - "schema": { - "$ref": "#foo", - "definitions": { - "A": { - "$id": "#foo", - "type": "integer" - } - }, - "foo": { - "type": "string" - } - }, - "tests": [ - { - "data": 1, - "description": "match", - "valid": true - }, - { - "data": "a", - "description": "mismatch", - "valid": false - } - ] } ]