Skip to content

Commit 38d686c

Browse files
authored
Don't break semantics in required_properties_in_properties (#2050)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 1f08b59 commit 38d686c

File tree

6 files changed

+212
-1
lines changed

6 files changed

+212
-1
lines changed

src/extension/alterschema/strict/required_properties_in_properties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class RequiredPropertiesInProperties final : public SchemaTransformRule {
3030
"http://json-schema.org/draft-04/schema#",
3131
"http://json-schema.org/draft-03/schema#"})) &&
3232
schema.is_object() && schema.defines("required") &&
33-
schema.at("required").is_array() && !schema.at("required").empty());
33+
schema.at("required").is_array() && !schema.at("required").empty() &&
34+
!schema.defines("additionalProperties"));
3435

3536
std::vector<Pointer> locations;
3637
std::size_t index{0};

test/alterschema/alterschema_lint_2019_09_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,48 @@ TEST(AlterSchema_lint_2019_09, required_properties_in_properties_5) {
32043204
EXPECT_EQ(document, expected);
32053205
}
32063206

3207+
TEST(AlterSchema_lint_2019_09, required_properties_in_properties_16) {
3208+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
3209+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3210+
"required": [ "foo", "bar" ],
3211+
"additionalProperties": false
3212+
})JSON");
3213+
3214+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
3215+
3216+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
3217+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3218+
"required": [ "foo", "bar" ],
3219+
"additionalProperties": false
3220+
})JSON");
3221+
3222+
EXPECT_EQ(document, expected);
3223+
}
3224+
3225+
TEST(AlterSchema_lint_2019_09, required_properties_in_properties_17) {
3226+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
3227+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3228+
"required": [ "foo", "bar" ],
3229+
"additionalProperties": false,
3230+
"properties": {
3231+
"foo": true
3232+
}
3233+
})JSON");
3234+
3235+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
3236+
3237+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
3238+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3239+
"required": [ "foo", "bar" ],
3240+
"additionalProperties": false,
3241+
"properties": {
3242+
"foo": true
3243+
}
3244+
})JSON");
3245+
3246+
EXPECT_EQ(document, expected);
3247+
}
3248+
32073249
TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_1) {
32083250
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
32093251
"$schema": "https://json-schema.org/draft/2019-09/schema",

test/alterschema/alterschema_lint_2020_12_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3665,6 +3665,48 @@ TEST(AlterSchema_lint_2020_12, required_properties_in_properties_15) {
36653665
EXPECT_EQ(document, expected);
36663666
}
36673667

3668+
TEST(AlterSchema_lint_2020_12, required_properties_in_properties_16) {
3669+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
3670+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3671+
"required": [ "foo", "bar" ],
3672+
"additionalProperties": false
3673+
})JSON");
3674+
3675+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
3676+
3677+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
3678+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3679+
"required": [ "foo", "bar" ],
3680+
"additionalProperties": false
3681+
})JSON");
3682+
3683+
EXPECT_EQ(document, expected);
3684+
}
3685+
3686+
TEST(AlterSchema_lint_2020_12, required_properties_in_properties_17) {
3687+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
3688+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3689+
"required": [ "foo", "bar" ],
3690+
"additionalProperties": false,
3691+
"properties": {
3692+
"foo": true
3693+
}
3694+
})JSON");
3695+
3696+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
3697+
3698+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
3699+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3700+
"required": [ "foo", "bar" ],
3701+
"additionalProperties": false,
3702+
"properties": {
3703+
"foo": true
3704+
}
3705+
})JSON");
3706+
3707+
EXPECT_EQ(document, expected);
3708+
}
3709+
36683710
TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_1) {
36693711
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
36703712
"$schema": "https://json-schema.org/draft/2020-12/schema",

test/alterschema/alterschema_lint_draft4_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,48 @@ TEST(AlterSchema_lint_draft4, required_properties_in_properties_5) {
20142014
EXPECT_EQ(document, expected);
20152015
}
20162016

2017+
TEST(AlterSchema_lint_draft4, required_properties_in_properties_16) {
2018+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2019+
"$schema": "http://json-schema.org/draft-04/schema#",
2020+
"required": [ "foo", "bar" ],
2021+
"additionalProperties": false
2022+
})JSON");
2023+
2024+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2025+
2026+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2027+
"$schema": "http://json-schema.org/draft-04/schema#",
2028+
"required": [ "foo", "bar" ],
2029+
"additionalProperties": false
2030+
})JSON");
2031+
2032+
EXPECT_EQ(document, expected);
2033+
}
2034+
2035+
TEST(AlterSchema_lint_draft4, required_properties_in_properties_17) {
2036+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2037+
"$schema": "http://json-schema.org/draft-04/schema#",
2038+
"required": [ "foo", "bar" ],
2039+
"additionalProperties": false,
2040+
"properties": {
2041+
"foo": true
2042+
}
2043+
})JSON");
2044+
2045+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2046+
2047+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2048+
"$schema": "http://json-schema.org/draft-04/schema#",
2049+
"required": [ "foo", "bar" ],
2050+
"additionalProperties": false,
2051+
"properties": {
2052+
"foo": true
2053+
}
2054+
})JSON");
2055+
2056+
EXPECT_EQ(document, expected);
2057+
}
2058+
20172059
TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_1) {
20182060
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
20192061
"$schema": "http://json-schema.org/draft-04/schema#",

test/alterschema/alterschema_lint_draft6_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,48 @@ TEST(AlterSchema_lint_draft6, required_properties_in_properties_5) {
23702370
EXPECT_EQ(document, expected);
23712371
}
23722372

2373+
TEST(AlterSchema_lint_draft6, required_properties_in_properties_16) {
2374+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2375+
"$schema": "http://json-schema.org/draft-06/schema#",
2376+
"required": [ "foo", "bar" ],
2377+
"additionalProperties": false
2378+
})JSON");
2379+
2380+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2381+
2382+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2383+
"$schema": "http://json-schema.org/draft-06/schema#",
2384+
"required": [ "foo", "bar" ],
2385+
"additionalProperties": false
2386+
})JSON");
2387+
2388+
EXPECT_EQ(document, expected);
2389+
}
2390+
2391+
TEST(AlterSchema_lint_draft6, required_properties_in_properties_17) {
2392+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2393+
"$schema": "http://json-schema.org/draft-06/schema#",
2394+
"required": [ "foo", "bar" ],
2395+
"additionalProperties": false,
2396+
"properties": {
2397+
"foo": true
2398+
}
2399+
})JSON");
2400+
2401+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2402+
2403+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2404+
"$schema": "http://json-schema.org/draft-06/schema#",
2405+
"required": [ "foo", "bar" ],
2406+
"additionalProperties": false,
2407+
"properties": {
2408+
"foo": true
2409+
}
2410+
})JSON");
2411+
2412+
EXPECT_EQ(document, expected);
2413+
}
2414+
23732415
TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_1) {
23742416
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
23752417
"$schema": "http://json-schema.org/draft-06/schema#",

test/alterschema/alterschema_lint_draft7_test.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,48 @@ TEST(AlterSchema_lint_draft7, required_properties_in_properties_5) {
27262726
EXPECT_EQ(document, expected);
27272727
}
27282728

2729+
TEST(AlterSchema_lint_draft7, required_properties_in_properties_16) {
2730+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2731+
"$schema": "http://json-schema.org/draft-07/schema#",
2732+
"required": [ "foo", "bar" ],
2733+
"additionalProperties": false
2734+
})JSON");
2735+
2736+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2737+
2738+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2739+
"$schema": "http://json-schema.org/draft-07/schema#",
2740+
"required": [ "foo", "bar" ],
2741+
"additionalProperties": false
2742+
})JSON");
2743+
2744+
EXPECT_EQ(document, expected);
2745+
}
2746+
2747+
TEST(AlterSchema_lint_draft7, required_properties_in_properties_17) {
2748+
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
2749+
"$schema": "http://json-schema.org/draft-07/schema#",
2750+
"required": [ "foo", "bar" ],
2751+
"additionalProperties": false,
2752+
"properties": {
2753+
"foo": true
2754+
}
2755+
})JSON");
2756+
2757+
LINT_AND_FIX_FOR_READABILITY_STRICT(document);
2758+
2759+
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
2760+
"$schema": "http://json-schema.org/draft-07/schema#",
2761+
"required": [ "foo", "bar" ],
2762+
"additionalProperties": false,
2763+
"properties": {
2764+
"foo": true
2765+
}
2766+
})JSON");
2767+
2768+
EXPECT_EQ(document, expected);
2769+
}
2770+
27292771
TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_1) {
27302772
sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({
27312773
"$schema": "http://json-schema.org/draft-07/schema#",

0 commit comments

Comments
 (0)