Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/extension/alterschema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/extension/alterschema/alterschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ inline auto APPLIES_TO_POINTERS(std::vector<Pointer> &&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"
Expand Down Expand Up @@ -207,7 +206,6 @@ auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) -> void {
bundle.add<MaxContainsCoveredByMaxItems>();
bundle.add<MinItemsGivenMinContains>();
bundle.add<MinPropertiesCoveredByRequired>();
bundle.add<NoMetadata>();
bundle.add<MinItemsImplicit>();
bundle.add<MinLengthImplicit>();
bundle.add<MinPropertiesImplicit>();
Expand Down
36 changes: 0 additions & 36 deletions src/extension/alterschema/canonicalizer/no_metadata.h

This file was deleted.

251 changes: 12 additions & 239 deletions test/alterschema/alterschema_canonicalize_2020_12_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that canonicalisation preserves metadata (via removal of NoMetadata), consider reintroducing a few of the removed no_metadata_* cases as positive tests that $comment, description, and unknown keywords are retained (including nested subschemas) to keep this behavior covered.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

"anyOf": [
{ "type": "string", "minLength": 0 },
{ "type": "number" }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down
Loading