diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMaxItems.java b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMaxItems.java index 1af1134b..1ef3a498 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMaxItems.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMaxItems.java @@ -17,7 +17,7 @@ public ChangedMaxItems(Integer oldValue, Integer newValue, DiffContext context) @Override public DiffResult isChanged() { - if (oldValue == null && newValue == null) { + if (oldValue == newValue) { return DiffResult.NO_CHANGES; } if (oldValue == null || newValue == null) { diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMinItems.java b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMinItems.java index 7791893c..3a3d4071 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMinItems.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedMinItems.java @@ -17,7 +17,7 @@ public ChangedMinItems(Integer oldValue, Integer newValue, DiffContext context) @Override public DiffResult isChanged() { - if (oldValue == null && newValue == null) { + if (oldValue == newValue) { return DiffResult.NO_CHANGES; } if (oldValue == null || newValue == null) { diff --git a/core/src/test/java/org/openapitools/openapidiff/core/SchemaDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/SchemaDiffTest.java index 8cd477ff..1f41406a 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/SchemaDiffTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/SchemaDiffTest.java @@ -144,7 +144,7 @@ public void changeMultipleOfHandling() { assertThat(props.get("field4").getMultipleOf().getRight()).isNull(); } - @Test // issues #480 + @Test // issues #480 and #779 public void changeMinMaxItemsHandling() { ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations( @@ -158,6 +158,9 @@ public void changeMinMaxItemsHandling() { Map props = changedSchema.getChangedProperties(); assertThat(props).isNotEmpty(); + // Check no changes in minItems and maxItems + assertThat(props.get("field0")).isNull(); + // Check increasing of minItems assertThat(props.get("field1").getMinItems().isIncompatible()).isTrue(); assertThat(props.get("field1").getMinItems().getOldValue()).isEqualTo(1); @@ -177,6 +180,26 @@ public void changeMinMaxItemsHandling() { assertThat(props.get("field4").getMaxItems().isIncompatible()).isTrue(); assertThat(props.get("field4").getMaxItems().getOldValue()).isEqualTo(100); assertThat(props.get("field4").getMaxItems().getNewValue()).isEqualTo(90); + + // Check removal of minItems + assertThat(props.get("field5").getMinItems().isCompatible()).isTrue(); + assertThat(props.get("field5").getMinItems().getOldValue()).isEqualTo(1); + assertThat(props.get("field5").getMinItems().getNewValue()).isNull(); + + // Check removal of maxItems + assertThat(props.get("field5").getMaxItems().isCompatible()).isTrue(); + assertThat(props.get("field5").getMaxItems().getOldValue()).isEqualTo(100); + assertThat(props.get("field5").getMaxItems().getNewValue()).isNull(); + + // Check addition of minItems + assertThat(props.get("field6").getMinItems().isCompatible()).isTrue(); + assertThat(props.get("field6").getMinItems().getOldValue()).isNull(); + assertThat(props.get("field6").getMinItems().getNewValue()).isEqualTo(1); + + // Check addition of maxItems + assertThat(props.get("field6").getMaxItems().isCompatible()).isTrue(); + assertThat(props.get("field6").getMaxItems().getOldValue()).isNull(); + assertThat(props.get("field6").getMaxItems().getNewValue()).isEqualTo(100); } @Test // issue #482 diff --git a/core/src/test/resources/schemaDiff/schema-min-max-items-diff-1.yaml b/core/src/test/resources/schemaDiff/schema-min-max-items-diff-1.yaml index 23d84148..a7426987 100644 --- a/core/src/test/resources/schemaDiff/schema-min-max-items-diff-1.yaml +++ b/core/src/test/resources/schemaDiff/schema-min-max-items-diff-1.yaml @@ -16,6 +16,12 @@ components: TestDTO: type: object properties: + field0: + type: array + items: + type: string + minItems: 1 + maxItems: 10 field1: type: array items: @@ -33,10 +39,20 @@ components: items: type: string minItems: 1 - maxItems: 90 + maxItems: 90 field4: type: array items: type: string minItems: 1 maxItems: 100 + field5: + type: array + items: + type: string + minItems: 1 + maxItems: 100 + field6: + type: array + items: + type: string diff --git a/core/src/test/resources/schemaDiff/schema-min-max-items-diff-2.yaml b/core/src/test/resources/schemaDiff/schema-min-max-items-diff-2.yaml index 0d8e6199..5e58f573 100644 --- a/core/src/test/resources/schemaDiff/schema-min-max-items-diff-2.yaml +++ b/core/src/test/resources/schemaDiff/schema-min-max-items-diff-2.yaml @@ -16,6 +16,12 @@ components: TestDTO: type: object properties: + field0: + type: array + items: + type: string + minItems: 1 + maxItems: 10 field1: type: array items: @@ -27,16 +33,26 @@ components: items: type: string minItems: 10 - maxItems: 100 + maxItems: 100 field3: type: array items: type: string minItems: 1 - maxItems: 100 + maxItems: 100 field4: type: array items: type: string minItems: 1 maxItems: 90 + field5: + type: array + items: + type: string + field6: + type: array + items: + type: string + minItems: 1 + maxItems: 100