Skip to content

Commit bb30244

Browse files
committed
Update linter: add tests for draft 3, rename rule, update tests, and undo unintended change
Signed-off-by: karan-palan <karanpalan007@gmail.com>
1 parent 767c38f commit bb30244

8 files changed

+109
-19
lines changed

src/extension/alterschema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema
4646
linter/unsatisfiable_min_properties.h
4747
linter/content_media_type_without_encoding.h
4848
linter/content_schema_without_media_type.h
49+
linter/additional_items_with_schema_items.h
4950
linter/non_applicable_type_specific_keywords.h
5051
linter/unnecessary_allof_ref_wrapper.h
5152
linter/duplicate_allof_branches.h

src/extension/alterschema/alterschema.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ static auto every_item_is_boolean(const T &container) -> bool {
4747
#include "canonicalizer/type_union_implicit.h"
4848

4949
// Linter
50+
#include "linter/additional_items_with_schema_items.h"
5051
#include "linter/additional_properties_default.h"
5152
#include "linter/const_with_type.h"
5253
#include "linter/content_media_type_without_encoding.h"
5354
#include "linter/content_schema_default.h"
5455
#include "linter/content_schema_without_media_type.h"
55-
#include "linter/dangling_additional_items.h"
5656
#include "linter/dependencies_default.h"
5757
#include "linter/dependencies_property_tautology.h"
5858
#include "linter/dependent_required_default.h"
@@ -113,7 +113,7 @@ auto add(SchemaTransformer &bundle, const AlterSchemaMode mode)
113113
bundle.add<DuplicateEnumValues>();
114114
bundle.add<DuplicateRequiredValues>();
115115
bundle.add<ConstWithType>();
116-
bundle.add<DanglingAdditionalItems>();
116+
bundle.add<AdditionalItemsWithSchemaItems>();
117117
bundle.add<ExclusiveMaximumNumberAndMaximum>();
118118
bundle.add<ExclusiveMinimumNumberAndMinimum>();
119119

src/extension/alterschema/linter/dangling_additional_items.h renamed to src/extension/alterschema/linter/additional_items_with_schema_items.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
class DanglingAdditionalItems final : public SchemaTransformRule {
1+
class AdditionalItemsWithSchemaItems final : public SchemaTransformRule {
22
public:
3-
DanglingAdditionalItems()
4-
: SchemaTransformRule{
5-
"dangling_additional_items",
6-
"`additionalItems` is ignored when `items` is an object"} {};
3+
AdditionalItemsWithSchemaItems()
4+
: SchemaTransformRule{"additional_items_with_schema_items",
5+
"The `additionalItems` keyword is ignored when the "
6+
"`items` keyword is set to a schema"} {};
77

88
[[nodiscard]] auto
99
condition(const sourcemeta::core::JSON &schema,
@@ -19,7 +19,8 @@ class DanglingAdditionalItems final : public SchemaTransformRule {
1919
{"https://json-schema.org/draft/2019-09/vocab/applicator",
2020
"http://json-schema.org/draft-07/schema#",
2121
"http://json-schema.org/draft-06/schema#",
22-
"http://json-schema.org/draft-04/schema#"}) &&
22+
"http://json-schema.org/draft-04/schema#",
23+
"http://json-schema.org/draft-03/schema#"}) &&
2324
schema.is_object() && schema.defines("items") &&
2425
schema.defines("additionalItems") && schema.at("items").is_object();
2526
}

test/alterschema/alterschema_lint_2019_09_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,8 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_ref_wrapper_5) {
16611661
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
16621662
"$schema": "https://json-schema.org/draft/2019-09/schema",
16631663
"allOf": [
1664-
{ "type": "integer",
1664+
{
1665+
"type": "integer",
16651666
"$ref": "https://example.com"
16661667
}
16671668
]
@@ -1680,7 +1681,7 @@ TEST(AlterSchema_lint_2019_09, unnecessary_allof_ref_wrapper_5) {
16801681
EXPECT_EQ(document, expected);
16811682
}
16821683

1683-
TEST(AlterSchema_lint_2019_09, dangling_additional_items_1) {
1684+
TEST(AlterSchema_lint_2019_09, additional_items_with_schema_items_1) {
16841685
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
16851686
"$schema": "https://json-schema.org/draft/2019-09/schema",
16861687
"items": {
@@ -1701,7 +1702,7 @@ TEST(AlterSchema_lint_2019_09, dangling_additional_items_1) {
17011702
EXPECT_EQ(document, expected);
17021703
}
17031704

1704-
TEST(AlterSchema_lint_2019_09, dangling_additional_items_2) {
1705+
TEST(AlterSchema_lint_2019_09, additional_items_with_schema_items_2) {
17051706
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
17061707
"$schema": "https://json-schema.org/draft/2019-09/schema",
17071708
"items": {

test/alterschema/alterschema_lint_draft3_test.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,47 @@ TEST(AlterSchema_lint_draft3, equal_numeric_bounds_to_enum_2) {
579579

580580
EXPECT_EQ(document, expected);
581581
}
582+
583+
TEST(AlterSchema_lint_draft3, additional_items_with_schema_items_1) {
584+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
585+
"$schema": "http://json-schema.org/draft-03/schema#",
586+
"items": {
587+
"type": "number"
588+
},
589+
"additionalItems": false
590+
})JSON");
591+
592+
LINT_AND_FIX_FOR_READABILITY(document);
593+
594+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
595+
"$schema": "http://json-schema.org/draft-03/schema#",
596+
"items": {
597+
"type": "number"
598+
}
599+
})JSON");
600+
601+
EXPECT_EQ(document, expected);
602+
}
603+
604+
TEST(AlterSchema_lint_draft3, additional_items_with_schema_items_2) {
605+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
606+
"$schema": "http://json-schema.org/draft-03/schema#",
607+
"items": {
608+
"type": "string"
609+
},
610+
"additionalItems": {
611+
"type": "boolean"
612+
}
613+
})JSON");
614+
615+
LINT_AND_FIX_FOR_READABILITY(document);
616+
617+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
618+
"$schema": "http://json-schema.org/draft-03/schema#",
619+
"items": {
620+
"type": "string"
621+
}
622+
})JSON");
623+
624+
EXPECT_EQ(document, expected);
625+
}

test/alterschema/alterschema_lint_draft4_test.cc

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ TEST(AlterSchema_lint_draft4, unnecessary_allof_ref_wrapper_1) {
762762
EXPECT_EQ(document, expected);
763763
}
764764

765-
TEST(AlterSchema_lint_draft4, dangling_additional_items_1) {
765+
TEST(AlterSchema_lint_draft4, additional_items_with_schema_items_1) {
766766
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
767767
"$schema": "http://json-schema.org/draft-04/schema#",
768768
"items": {
@@ -783,7 +783,7 @@ TEST(AlterSchema_lint_draft4, dangling_additional_items_1) {
783783
EXPECT_EQ(document, expected);
784784
}
785785

786-
TEST(AlterSchema_lint_draft4, dangling_additional_items_2) {
786+
TEST(AlterSchema_lint_draft4, additional_items_with_schema_items_2) {
787787
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
788788
"$schema": "http://json-schema.org/draft-04/schema#",
789789
"type": "array",
@@ -808,7 +808,8 @@ TEST(AlterSchema_lint_draft4, dangling_additional_items_2) {
808808
EXPECT_EQ(document, expected);
809809
}
810810

811-
TEST(AlterSchema_lint_draft4, dangling_additional_items_no_change_array_items) {
811+
TEST(AlterSchema_lint_draft4,
812+
additional_items_with_schema_items_no_change_array_items) {
812813
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
813814
"$schema": "http://json-schema.org/draft-04/schema#",
814815
"items": [
@@ -832,7 +833,8 @@ TEST(AlterSchema_lint_draft4, dangling_additional_items_no_change_array_items) {
832833
EXPECT_EQ(document, expected);
833834
}
834835

835-
TEST(AlterSchema_lint_draft4, dangling_additional_items_no_change_no_items) {
836+
TEST(AlterSchema_lint_draft4,
837+
additional_items_with_schema_items_no_change_no_items) {
836838
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
837839
"$schema": "http://json-schema.org/draft-04/schema#",
838840
"additionalItems": false
@@ -847,3 +849,44 @@ TEST(AlterSchema_lint_draft4, dangling_additional_items_no_change_no_items) {
847849

848850
EXPECT_EQ(document, expected);
849851
}
852+
853+
TEST(AlterSchema_lint_draft4,
854+
additional_items_with_schema_items_no_change_boolean_items_true) {
855+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
856+
"$schema": "http://json-schema.org/draft-04/schema#",
857+
"items": true,
858+
"additionalItems": false
859+
})JSON");
860+
861+
LINT_AND_FIX_FOR_READABILITY(document);
862+
863+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
864+
"$schema": "http://json-schema.org/draft-04/schema#",
865+
"additionalItems": false
866+
})JSON");
867+
868+
EXPECT_EQ(document, expected);
869+
}
870+
871+
TEST(AlterSchema_lint_draft4,
872+
additional_items_with_schema_items_no_change_boolean_items_false) {
873+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
874+
"$schema": "http://json-schema.org/draft-04/schema#",
875+
"items": false,
876+
"additionalItems": {
877+
"type": "string"
878+
}
879+
})JSON");
880+
881+
LINT_AND_FIX_FOR_READABILITY(document);
882+
883+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
884+
"$schema": "http://json-schema.org/draft-04/schema#",
885+
"items": false,
886+
"additionalItems": {
887+
"type": "string"
888+
}
889+
})JSON");
890+
891+
EXPECT_EQ(document, expected);
892+
}

test/alterschema/alterschema_lint_draft6_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ TEST(AlterSchema_lint_draft6, unnecessary_allof_ref_wrapper_1) {
11131113
EXPECT_EQ(document, expected);
11141114
}
11151115

1116-
TEST(AlterSchema_lint_draft6, dangling_additional_items_1) {
1116+
TEST(AlterSchema_lint_draft6, additional_items_with_schema_items_1) {
11171117
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
11181118
"$schema": "http://json-schema.org/draft-06/schema#",
11191119
"items": {
@@ -1134,7 +1134,7 @@ TEST(AlterSchema_lint_draft6, dangling_additional_items_1) {
11341134
EXPECT_EQ(document, expected);
11351135
}
11361136

1137-
TEST(AlterSchema_lint_draft6, dangling_additional_items_2) {
1137+
TEST(AlterSchema_lint_draft6, additional_items_with_schema_items_2) {
11381138
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
11391139
"$schema": "http://json-schema.org/draft-06/schema#",
11401140
"items": {

test/alterschema/alterschema_lint_draft7_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ TEST(AlterSchema_lint_draft7, unnecessary_allof_ref_wrapper_1) {
12091209
EXPECT_EQ(document, expected);
12101210
}
12111211

1212-
TEST(AlterSchema_lint_draft7, dangling_additional_items_1) {
1212+
TEST(AlterSchema_lint_draft7, additional_items_with_schema_items_1) {
12131213
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
12141214
"$schema": "http://json-schema.org/draft-07/schema#",
12151215
"items": {
@@ -1230,7 +1230,7 @@ TEST(AlterSchema_lint_draft7, dangling_additional_items_1) {
12301230
EXPECT_EQ(document, expected);
12311231
}
12321232

1233-
TEST(AlterSchema_lint_draft7, dangling_additional_items_2) {
1233+
TEST(AlterSchema_lint_draft7, additional_items_with_schema_items_2) {
12341234
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
12351235
"$schema": "http://json-schema.org/draft-07/schema#",
12361236
"type": "array",

0 commit comments

Comments
 (0)