Skip to content

Commit 991418b

Browse files
authored
fix: No change if same minItems or maxItems (#780)
* fix: No change if same minItems or maxItems * feat: Test adding or removing property
1 parent e7e0243 commit 991418b

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMaxItems.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ChangedMaxItems(Integer oldValue, Integer newValue, DiffContext context)
1717

1818
@Override
1919
public DiffResult isChanged() {
20-
if (oldValue == null && newValue == null) {
20+
if (oldValue == newValue) {
2121
return DiffResult.NO_CHANGES;
2222
}
2323
if (oldValue == null || newValue == null) {

core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMinItems.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ChangedMinItems(Integer oldValue, Integer newValue, DiffContext context)
1717

1818
@Override
1919
public DiffResult isChanged() {
20-
if (oldValue == null && newValue == null) {
20+
if (oldValue == newValue) {
2121
return DiffResult.NO_CHANGES;
2222
}
2323
if (oldValue == null || newValue == null) {

core/src/test/java/org/openapitools/openapidiff/core/SchemaDiffTest.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void changeMultipleOfHandling() {
144144
assertThat(props.get("field4").getMultipleOf().getRight()).isNull();
145145
}
146146

147-
@Test // issues #480
147+
@Test // issues #480 and #779
148148
public void changeMinMaxItemsHandling() {
149149
ChangedOpenApi changedOpenApi =
150150
OpenApiCompare.fromLocations(
@@ -158,6 +158,9 @@ public void changeMinMaxItemsHandling() {
158158
Map<String, ChangedSchema> props = changedSchema.getChangedProperties();
159159
assertThat(props).isNotEmpty();
160160

161+
// Check no changes in minItems and maxItems
162+
assertThat(props.get("field0")).isNull();
163+
161164
// Check increasing of minItems
162165
assertThat(props.get("field1").getMinItems().isIncompatible()).isTrue();
163166
assertThat(props.get("field1").getMinItems().getOldValue()).isEqualTo(1);
@@ -177,6 +180,26 @@ public void changeMinMaxItemsHandling() {
177180
assertThat(props.get("field4").getMaxItems().isIncompatible()).isTrue();
178181
assertThat(props.get("field4").getMaxItems().getOldValue()).isEqualTo(100);
179182
assertThat(props.get("field4").getMaxItems().getNewValue()).isEqualTo(90);
183+
184+
// Check removal of minItems
185+
assertThat(props.get("field5").getMinItems().isCompatible()).isTrue();
186+
assertThat(props.get("field5").getMinItems().getOldValue()).isEqualTo(1);
187+
assertThat(props.get("field5").getMinItems().getNewValue()).isNull();
188+
189+
// Check removal of maxItems
190+
assertThat(props.get("field5").getMaxItems().isCompatible()).isTrue();
191+
assertThat(props.get("field5").getMaxItems().getOldValue()).isEqualTo(100);
192+
assertThat(props.get("field5").getMaxItems().getNewValue()).isNull();
193+
194+
// Check addition of minItems
195+
assertThat(props.get("field6").getMinItems().isCompatible()).isTrue();
196+
assertThat(props.get("field6").getMinItems().getOldValue()).isNull();
197+
assertThat(props.get("field6").getMinItems().getNewValue()).isEqualTo(1);
198+
199+
// Check addition of maxItems
200+
assertThat(props.get("field6").getMaxItems().isCompatible()).isTrue();
201+
assertThat(props.get("field6").getMaxItems().getOldValue()).isNull();
202+
assertThat(props.get("field6").getMaxItems().getNewValue()).isEqualTo(100);
180203
}
181204

182205
@Test // issue #482

core/src/test/resources/schemaDiff/schema-min-max-items-diff-1.yaml

+17-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ components:
1616
TestDTO:
1717
type: object
1818
properties:
19+
field0:
20+
type: array
21+
items:
22+
type: string
23+
minItems: 1
24+
maxItems: 10
1925
field1:
2026
type: array
2127
items:
@@ -33,10 +39,20 @@ components:
3339
items:
3440
type: string
3541
minItems: 1
36-
maxItems: 90
42+
maxItems: 90
3743
field4:
3844
type: array
3945
items:
4046
type: string
4147
minItems: 1
4248
maxItems: 100
49+
field5:
50+
type: array
51+
items:
52+
type: string
53+
minItems: 1
54+
maxItems: 100
55+
field6:
56+
type: array
57+
items:
58+
type: string

core/src/test/resources/schemaDiff/schema-min-max-items-diff-2.yaml

+18-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ components:
1616
TestDTO:
1717
type: object
1818
properties:
19+
field0:
20+
type: array
21+
items:
22+
type: string
23+
minItems: 1
24+
maxItems: 10
1925
field1:
2026
type: array
2127
items:
@@ -27,16 +33,26 @@ components:
2733
items:
2834
type: string
2935
minItems: 10
30-
maxItems: 100
36+
maxItems: 100
3137
field3:
3238
type: array
3339
items:
3440
type: string
3541
minItems: 1
36-
maxItems: 100
42+
maxItems: 100
3743
field4:
3844
type: array
3945
items:
4046
type: string
4147
minItems: 1
4248
maxItems: 90
49+
field5:
50+
type: array
51+
items:
52+
type: string
53+
field6:
54+
type: array
55+
items:
56+
type: string
57+
minItems: 1
58+
maxItems: 100

0 commit comments

Comments
 (0)