Skip to content

Commit 75fbcd5

Browse files
committed
fix: No change if same minItems or maxItems
1 parent e7e0243 commit 75fbcd5

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public ChangedMaxItems(Integer oldValue, Integer newValue, DiffContext context)
1717

1818
@Override
1919
public DiffResult isChanged() {
20+
if (oldValue == newValue) {
21+
return DiffResult.NO_CHANGES;
22+
}
2023
if (oldValue == null && newValue == null) {
2124
return DiffResult.NO_CHANGES;
2225
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public ChangedMinItems(Integer oldValue, Integer newValue, DiffContext context)
1717

1818
@Override
1919
public DiffResult isChanged() {
20+
if (oldValue == newValue) {
21+
return DiffResult.NO_CHANGES;
22+
}
2023
if (oldValue == null && newValue == null) {
2124
return DiffResult.NO_CHANGES;
2225
}

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

Lines changed: 4 additions & 1 deletion
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);

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

Lines changed: 7 additions & 1 deletion
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,7 +39,7 @@ components:
3339
items:
3440
type: string
3541
minItems: 1
36-
maxItems: 90
42+
maxItems: 90
3743
field4:
3844
type: array
3945
items:

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

Lines changed: 8 additions & 2 deletions
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,13 +33,13 @@ 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:

0 commit comments

Comments
 (0)