Skip to content

Commit c867a57

Browse files
committed
proposed new solution with deepEquals on Objects, fix also added to ChangedExamples.java, Fixed suggestion from copilot, grammatical error
1 parent cb91de6 commit c867a57

File tree

5 files changed

+7
-31
lines changed

5 files changed

+7
-31
lines changed

core/src/main/java/org/openapitools/openapidiff/core/model/ChangedExample.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.openapitools.openapidiff.core.model;
22

3-
import java.lang.reflect.Array;
3+
import org.apache.commons.lang3.builder.EqualsBuilder;
4+
45
import java.util.Objects;
56

67
public class ChangedExample implements Changed {
@@ -31,35 +32,10 @@ public void setRightExample(Object rightExample) {
3132

3233
@Override
3334
public DiffResult isChanged() {
34-
DiffResult arrayDiff = compareArrays();
35-
if (arrayDiff != null) {
36-
return arrayDiff;
37-
}
38-
39-
return Objects.equals(leftExample, rightExample) ? DiffResult.NO_CHANGES : DiffResult.METADATA;
40-
}
41-
42-
private DiffResult compareArrays() {
43-
if (leftExample == null || rightExample == null) {
44-
return null;
45-
}
46-
47-
if (!leftExample.getClass().isArray() || !rightExample.getClass().isArray()) {
48-
return null;
49-
}
50-
51-
int leftLength = Array.getLength(leftExample);
52-
53-
if (leftLength != Array.getLength(rightExample)) {
35+
if (!Objects.deepEquals(leftExample, rightExample)) {
5436
return DiffResult.METADATA;
5537
}
5638

57-
for (int i = 0; i < leftLength; i++) {
58-
if (!Objects.deepEquals(Array.get(leftExample, i), Array.get(rightExample, i))) {
59-
return DiffResult.METADATA;
60-
}
61-
}
62-
6339
return DiffResult.NO_CHANGES;
6440
}
6541

core/src/main/java/org/openapitools/openapidiff/core/model/ChangedExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void setRightExamples(Object rightExamples) {
3030

3131
@Override
3232
public DiffResult isChanged() {
33-
if (!Objects.equals(leftExamples, rightExamples)) {
33+
if (!Objects.deepEquals(leftExamples, rightExamples)) {
3434
return DiffResult.METADATA;
3535
}
3636
return DiffResult.NO_CHANGES;

core/src/main/java/org/openapitools/openapidiff/core/output/AsciidocRender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void render(ChangedOpenApi diff, OutputStreamWriter outputStreamWriter) {
3434
diff.getNewSpecOpenApi().getInfo().getVersion()));
3535
safelyAppend(outputStreamWriter, System.lineSeparator());
3636
safelyAppend(outputStreamWriter, System.lineSeparator());
37-
safelyAppend(outputStreamWriter, "NOTE: No differences. Specifications are equivalents");
37+
safelyAppend(outputStreamWriter, "NOTE: No differences. Specifications are equivalent");
3838
} else {
3939
safelyAppend(
4040
outputStreamWriter,

core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ConsoleRender implements Render {
2727
public void render(ChangedOpenApi diff, OutputStreamWriter outputStreamWriter) {
2828
this.diff = diff;
2929
if (diff.isUnchanged()) {
30-
safelyAppend(outputStreamWriter, "No differences. Specifications are equivalents");
30+
safelyAppend(outputStreamWriter, "No differences. Specifications are equivalent");
3131
} else {
3232
safelyAppend(outputStreamWriter, bigTitle("Api Change Log"));
3333
safelyAppend(

core/src/test/java/org/openapitools/openapidiff/core/output/ConsoleRenderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ void renderShowsNoDifferencesWhenCSVMediaTypeResponseExampleIsByteArray() {
8989
render.render(diff, outputStreamWriter);
9090
assertThat(outputStream.toString()).isNotBlank();
9191
assertThat(outputStream.toString())
92-
.hasToString("No differences. Specifications are equivalents");
92+
.hasToString("No differences. Specifications are equivalent");
9393
}
9494
}

0 commit comments

Comments
 (0)