diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt index d17efb350..635e0c357 100644 --- a/src/extension/alterschema/CMakeLists.txt +++ b/src/extension/alterschema/CMakeLists.txt @@ -12,7 +12,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema canonicalizer/min_properties_covered_by_required.h canonicalizer/min_properties_implicit.h canonicalizer/multiple_of_implicit.h - canonicalizer/no_metadata.h canonicalizer/properties_implicit.h canonicalizer/type_array_to_any_of.h canonicalizer/type_boolean_as_enum.h diff --git a/src/extension/alterschema/alterschema.cc b/src/extension/alterschema/alterschema.cc index d20eff011..ad79e2862 100644 --- a/src/extension/alterschema/alterschema.cc +++ b/src/extension/alterschema/alterschema.cc @@ -41,7 +41,6 @@ inline auto APPLIES_TO_POINTERS(std::vector &&keywords) #include "canonicalizer/min_properties_covered_by_required.h" #include "canonicalizer/min_properties_implicit.h" #include "canonicalizer/multiple_of_implicit.h" -#include "canonicalizer/no_metadata.h" #include "canonicalizer/properties_implicit.h" #include "canonicalizer/type_array_to_any_of.h" #include "canonicalizer/type_boolean_as_enum.h" @@ -207,7 +206,6 @@ auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) -> void { bundle.add(); bundle.add(); bundle.add(); - bundle.add(); bundle.add(); bundle.add(); bundle.add(); diff --git a/src/extension/alterschema/canonicalizer/no_metadata.h b/src/extension/alterschema/canonicalizer/no_metadata.h deleted file mode 100644 index 3a2ff3361..000000000 --- a/src/extension/alterschema/canonicalizer/no_metadata.h +++ /dev/null @@ -1,36 +0,0 @@ -class NoMetadata final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - NoMetadata() - : SchemaTransformRule{"no_metadata", - "Annotations, comments, and unknown keywords have " - "no effect on validation"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &, const SchemaFrame::Location &, - const SchemaWalker &walker, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object() && !schema.empty()); - - std::vector locations; - for (const auto &entry : schema.as_object()) { - const auto &metadata{walker(entry.first, vocabularies)}; - if (metadata.type == SchemaKeywordType::Annotation || - metadata.type == SchemaKeywordType::Comment || - metadata.type == SchemaKeywordType::Unknown) { - locations.push_back(Pointer{entry.first}); - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - schema.erase(location.at(0).to_property()); - } - } -}; diff --git a/test/alterschema/alterschema_canonicalize_2020_12_test.cc b/test/alterschema/alterschema_canonicalize_2020_12_test.cc index aa5c66ae3..26ef16404 100644 --- a/test/alterschema/alterschema_canonicalize_2020_12_test.cc +++ b/test/alterschema/alterschema_canonicalize_2020_12_test.cc @@ -663,6 +663,7 @@ TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_5) { const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "My schema", "anyOf": [ { "type": "string", "minLength": 0 }, { "type": "number" } @@ -893,244 +894,6 @@ TEST(AlterSchema_canonicalize_2020_12, EXPECT_EQ(document, expected); } -TEST(AlterSchema_canonicalize_2020_12, no_metadata_comment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "This is a comment", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_title_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My Schema", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_description_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_unknown_keyword_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "foobar": "unknown keyword", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_x_prefix_keyword_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "x-custom": "custom extension", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_multiple_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "A comment", - "title": "My Schema", - "description": "A description", - "x-custom": "extension", - "unknown": true, - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_nested_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Root schema", - "type": "object", - "properties": { - "foo": { - "title": "Foo property", - "$comment": "This is foo", - "type": "string" - } - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "type": "string", - "minLength": 0 - } - }, - "type": "object", - "minProperties": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_examples_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "default": "hello", - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_deprecated_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "deprecated": true, - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, no_metadata_readonly_writeonly_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "readOnly": true, - "writeOnly": false, - "type": "string" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - TEST(AlterSchema_canonicalize_2020_12, circular_ref_through_defs_1) { auto document = sourcemeta::core::parse_json(R"JSON({ "$schema": "https://json-schema.org/draft/2020-12/schema", @@ -1349,7 +1112,17 @@ TEST(AlterSchema_canonicalize_2020_12, { "enum": [ false, true ] }, { "type": "object", "minProperties": 0, "properties": {} }, { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, + { + "type": "string", + "contentSchema": { + "type": "object", + "minProperties": 0, + "properties": {} + }, + "contentEncoding": "base64", + "contentMediaType": "application/json", + "minLength": 0 + }, { "type": "number" } ] })JSON");