diff --git a/remotes/subSchemas-ids.json b/remotes/subSchemas-ids.json new file mode 100644 index 00000000..752b0b25 --- /dev/null +++ b/remotes/subSchemas-ids.json @@ -0,0 +1,22 @@ +{ + "$id": "http://localhost:1234/subSchemas-ids.json", + "allOf": [ + {"$ref": "#/$defs/referencing"} + ], + "$defs": { + "referencing": { + "$id": "referencing.json", + "allOf": [ + {"$ref": "#/$defs/referenced"} + ], + "$defs": { + "referenced": { + "enum": ["should-be-valid"] + } + } + }, + "referenced": { + "enum": ["should-NOT-be-valid"] + } + } +} diff --git a/tests/draft2019-09/ref.json b/tests/draft2019-09/ref.json index 7d850414..2c3254b4 100644 --- a/tests/draft2019-09/ref.json +++ b/tests/draft2019-09/ref.json @@ -1055,5 +1055,49 @@ "valid": false } ] - } + }, + { + "description": "$ref uses base URI learned from $id", + "schema": { + "allOf": [ + {"$ref": "#/$defs/referencing"} + ], + "$defs": { + "referencing": { + "$id": "/referencing.json", + "$comment": "The $id here changes the base URI that $ref's value is resolved against", + "allOf": [ + {"$ref": "#/$defs/referenced"} + ], + "$defs": { + "referenced": { + "$comment": "This schema IS being referenced", + "enum": ["should-be-valid"] + } + } + }, + "referenced": { + "$comment": "This schema is NOT being referenced", + "enum": ["should-NOT-be-valid"] + } + } + }, + "tests": [ + { + "description": "the correct schema is referenced", + "data": "should-be-valid", + "valid": true + }, + { + "description": "the incorrect schema is not referenced", + "data": "should-NOT-be-valid", + "valid": false + }, + { + "description": "sanity check that other invalid values aren't accepted either", + "data": "bogus", + "valid": false + } + ] + } ] diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 79107f9e..d3e2b7e7 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -310,5 +310,31 @@ "valid": true } ] + }, + { + "description": "$ref uses base URI learned from $id in remote schemas", + "schema": { + "$id": "http://localhost:1234/", + "allOf": [ + {"$ref": "subSchemas-ids.json"} + ] + }, + "tests": [ + { + "description": "the correct schema is referenced", + "data": "should-be-valid", + "valid": true + }, + { + "description": "the incorrect schema is not referenced", + "data": "should-NOT-be-valid", + "valid": false + }, + { + "description": "sanity check that other invalid values aren't accepted either", + "data": "bogus", + "valid": false + } + ] } ] diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 82631726..06c9db35 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -1012,5 +1012,49 @@ "valid": false } ] + }, + { + "description": "$ref uses base URI learned from $id", + "schema": { + "allOf": [ + {"$ref": "#/$defs/referencing"} + ], + "$defs": { + "referencing": { + "$id": "/referencing.json", + "$comment": "The $id here changes the base URI that $ref's value is resolved against", + "allOf": [ + {"$ref": "#/$defs/referenced"} + ], + "$defs": { + "referenced": { + "$comment": "This schema IS being referenced", + "enum": ["should-be-valid"] + } + } + }, + "referenced": { + "$comment": "This schema is NOT being referenced", + "enum": ["should-NOT-be-valid"] + } + } + }, + "tests": [ + { + "description": "the correct schema is referenced", + "data": "should-be-valid", + "valid": true + }, + { + "description": "the incorrect schema is not referenced", + "data": "should-NOT-be-valid", + "valid": false + }, + { + "description": "sanity check that other invalid values aren't accepted either", + "data": "bogus", + "valid": false + } + ] } ] diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index c2b20024..e79f0282 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -235,5 +235,31 @@ "valid": true } ] + }, + { + "description": "$ref uses base URI learned from $id in remote schemas", + "schema": { + "$id": "http://localhost:1234/", + "allOf": [ + {"$ref": "subSchemas-ids.json"} + ] + }, + "tests": [ + { + "description": "the correct schema is referenced", + "data": "should-be-valid", + "valid": true + }, + { + "description": "the incorrect schema is not referenced", + "data": "should-NOT-be-valid", + "valid": false + }, + { + "description": "sanity check that other invalid values aren't accepted either", + "data": "bogus", + "valid": false + } + ] } ]