diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 2800d9d..94691a2 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -172,7 +172,10 @@ public: if (unresolved != file.unresolved.end()) schema::make(value, this, {}, {{new_uri}}); else // no, nothing ref'd it, keep for later - file.unknown_keywords[fragment] = value; + // could use fragment here, but better not to: if key is an integer the pointer will be interpreted as + // an array. This cannot be the case here, so we force using key as a string when storing the + // unknown_keyword-schema. + file.unknown_keywords[uri.pointer()][key] = value; // recursively add possible subschemas of unknown keywords if (value.type() == json::value_t::object) diff --git a/test/issue-143/CMakeLists.txt b/test/issue-143/CMakeLists.txt new file mode 100644 index 0000000..1cc2365 --- /dev/null +++ b/test/issue-143/CMakeLists.txt @@ -0,0 +1,13 @@ +add_test_simple_schema(Issue::143-1 + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance-fail-1.json) +add_test_simple_schema(Issue::143-a + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance-fail-a.json) +add_test_simple_schema(Issue::143-ok + ${CMAKE_CURRENT_SOURCE_DIR}/schema.json + ${CMAKE_CURRENT_SOURCE_DIR}/instance.json) + +set_tests_properties(Issue::143-1 Issue::143-a + PROPERTIES + WILL_FAIL 1) diff --git a/test/issue-143/instance-fail-1.json b/test/issue-143/instance-fail-1.json new file mode 100644 index 0000000..7eefb69 --- /dev/null +++ b/test/issue-143/instance-fail-1.json @@ -0,0 +1,4 @@ +{ + "ref1": "a", + "refa": "a" +} diff --git a/test/issue-143/instance-fail-a.json b/test/issue-143/instance-fail-a.json new file mode 100644 index 0000000..67f7c5e --- /dev/null +++ b/test/issue-143/instance-fail-a.json @@ -0,0 +1,4 @@ +{ + "ref1": 12, + "refa": 12 +} diff --git a/test/issue-143/instance.json b/test/issue-143/instance.json new file mode 100644 index 0000000..d2d55e6 --- /dev/null +++ b/test/issue-143/instance.json @@ -0,0 +1,4 @@ +{ + "ref1": 12, + "refa": "a" +} diff --git a/test/issue-143/schema.json b/test/issue-143/schema.json new file mode 100644 index 0000000..4a4503f --- /dev/null +++ b/test/issue-143/schema.json @@ -0,0 +1,21 @@ +{ + "type": "object", + + "properties": { + "unknown_keyword_storage": { + "1": { + "type": "number" + }, + "a": { + "type": "string" + } + }, + "ref1": { + "$ref": "#/properties/unknown_keyword_storage/1" + }, + "refa": { + "$ref": "#/properties/unknown_keyword_storage/a" + } + }, + "additionalProperties": false +}