Skip to content

Commit e39ad8c

Browse files
authored
1 parent 5105f0b commit e39ad8c

23 files changed

+803
-24
lines changed

core/src/main/java/org/openapitools/openapidiff/core/compare/OperationDiff.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public DeferredChanged<ChangedOperation> diff(
7373
}
7474

7575
ParametersDiffResult parametersDiffResult =
76-
openApiDiff.getParametersDiff().diff(oldOperation.getParameters(), newOperation.getParameters(), context);
76+
openApiDiff
77+
.getParametersDiff()
78+
.diff(oldOperation.getParameters(), newOperation.getParameters(), context);
7779
builder
7880
.with(parametersDiffResult.deferredChanged)
7981
.ifPresent(

core/src/main/java/org/openapitools/openapidiff/core/compare/ParametersDiff.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class ParametersDiffResult {
2020
protected DeferredChanged<ChangedParameters> deferredChanged;
2121
protected boolean sameOperationsDiffSchema;
2222

23-
public ParametersDiffResult(DeferredChanged<ChangedParameters> deferredChanged, boolean sameOperationsDiffSchema) {
23+
public ParametersDiffResult(
24+
DeferredChanged<ChangedParameters> deferredChanged, boolean sameOperationsDiffSchema) {
2425
this.deferredChanged = deferredChanged;
2526
this.sameOperationsDiffSchema = sameOperationsDiffSchema;
2627
}
@@ -57,7 +58,8 @@ public static boolean same(Parameter left, Parameter right) {
5758
&& Objects.equals(left.getIn(), right.getIn());
5859
}
5960

60-
public ParametersDiffResult diff(List<Parameter> left, List<Parameter> right, DiffContext context) {
61+
public ParametersDiffResult diff(
62+
List<Parameter> left, List<Parameter> right, DiffContext context) {
6163
DeferredBuilder<Changed> builder = new DeferredBuilder<>();
6264
ChangedParameters changedParameters =
6365
new ChangedParameters(left, right != null ? new ArrayList<>(right) : null, context);
@@ -80,9 +82,8 @@ public ParametersDiffResult diff(List<Parameter> left, List<Parameter> right, Di
8082
}
8183
changedParameters.getIncreased().addAll(right);
8284
return new ParametersDiffResult(
83-
builder.buildIsChanged(changedParameters),
84-
pathUnchangedParametersChanged(changedParameters, context)
85-
);
85+
builder.buildIsChanged(changedParameters),
86+
pathUnchangedParametersChanged(changedParameters, context));
8687
}
8788

8889
public boolean pathUnchangedParametersChanged(
@@ -93,7 +94,8 @@ public boolean pathUnchangedParametersChanged(
9394
return false;
9495
// Go through each missing Parameter and compare it to newly added Parameters
9596
for (Parameter parameter : changedParameters.getMissing()) {
96-
// Speedy Check. Use the map already created in changedParameters to check if missing param is linked to newParam
97+
// Speedy Check. Use the map already created in changedParameters to check if missing param is
98+
// linked to newParam
9799
String newParameterName = context.getParameters().get(parameter.getName());
98100
if (newParameterName.isEmpty()) return false;
99101

@@ -107,7 +109,8 @@ public boolean pathUnchangedParametersChanged(
107109
Parameter newParameterRealized = newParameter.get();
108110
newParameterRealized.setName(parameter.getName()); // Make names similar
109111
boolean samePathDifferentParameter = !newParameterRealized.equals(parameter);
110-
newParameterRealized.setName(newParameterName); // Important:: MUST Reset the name as this is not a copy
112+
newParameterRealized.setName(
113+
newParameterName); // Important:: MUST Reset the name as this is not a copy
111114
return samePathDifferentParameter;
112115
}
113116
return false;
@@ -119,10 +122,11 @@ public boolean pathUnchanged(ChangedParameters changedParameters, DiffContext co
119122
String newUrl = context.getRightUrl();
120123
ArrayList<String> oldUrlPathParams = matchedItems(oldUrl, REGEX_PATH);
121124
ArrayList<String> newUrlPathParams = matchedItems(newUrl, REGEX_PATH);
122-
// Path Param count doesn't match or param-less path doesn't match or param is changed --> It's a new endpoint
125+
// Path Param count doesn't match or param-less path doesn't match or param is changed --> It's
126+
// a new endpoint
123127
return oldUrlPathParams.size() == newUrlPathParams.size()
124-
&& changedParameters.getChanged().isEmpty()
125-
&& oldUrl.replaceAll(REGEX_PATH, "").equals(newUrl.replaceAll(REGEX_PATH, ""));
128+
&& changedParameters.getChanged().isEmpty()
129+
&& oldUrl.replaceAll(REGEX_PATH, "").equals(newUrl.replaceAll(REGEX_PATH, ""));
126130
}
127131

128132
public ArrayList<String> matchedItems(String string, String regex) {

core/src/main/java/org/openapitools/openapidiff/core/compare/PathDiff.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public DeferredChanged<ChangedPath> diff(PathItem left, PathItem right, DiffCont
3636
.with(
3737
openApiDiff
3838
.getOperationDiff()
39-
.diff(oldOperation, newOperation,
40-
context.copyWithMethod(method).copyWithLeftRightUrls(
41-
context.getLeftUrl(),
42-
context.getRightUrl()
43-
)
44-
)
45-
).ifPresent(changedPath.getChanged()::add);
39+
.diff(
40+
oldOperation,
41+
newOperation,
42+
context
43+
.copyWithMethod(method)
44+
.copyWithLeftRightUrls(context.getLeftUrl(), context.getRightUrl())))
45+
.ifPresent(changedPath.getChanged()::add);
4646
}
4747
builder
4848
.with(

core/src/main/java/org/openapitools/openapidiff/core/compare/schemadiffresult/SchemaDiffResult.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,18 @@ public <V extends Schema<X>, X> DeferredChanged<ChangedSchema> diff(
5959
.setChangeFormat(!Objects.equals(left.getFormat(), right.getFormat()))
6060
.setReadOnly(new ChangedReadOnly(left.getReadOnly(), right.getReadOnly(), context))
6161
.setWriteOnly(new ChangedWriteOnly(left.getWriteOnly(), right.getWriteOnly(), context))
62-
.setMaxLength(new ChangedMaxLength(left.getMaxLength(), right.getMaxLength(), context));
62+
.setMaxLength(new ChangedMaxLength(left.getMaxLength(), right.getMaxLength(), context))
63+
.setNumericRange(
64+
new ChangedNumericRange(
65+
left.getMinimum(),
66+
right.getMinimum(),
67+
left.getMaximum(),
68+
right.getMaximum(),
69+
left.getExclusiveMinimum(),
70+
right.getExclusiveMinimum(),
71+
left.getExclusiveMaximum(),
72+
right.getExclusiveMaximum(),
73+
context));
6374
builder
6475
.with(
6576
openApiDiff

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.stream.Stream;
88
import org.openapitools.openapidiff.core.model.schema.ChangedEnum;
99
import org.openapitools.openapidiff.core.model.schema.ChangedMaxLength;
10+
import org.openapitools.openapidiff.core.model.schema.ChangedNumericRange;
1011
import org.openapitools.openapidiff.core.model.schema.ChangedReadOnly;
1112
import org.openapitools.openapidiff.core.model.schema.ChangedRequired;
1213
import org.openapitools.openapidiff.core.model.schema.ChangedWriteOnly;
@@ -30,6 +31,7 @@ public class ChangedSchema implements ComposedChanged {
3031
protected ChangedWriteOnly writeOnly;
3132
protected boolean changedType;
3233
protected ChangedMaxLength maxLength;
34+
protected ChangedNumericRange numericRange;
3335
protected boolean discriminatorPropertyChanged;
3436
protected ChangedSchema items;
3537
protected ChangedOneOfSchema oneOfSchema;
@@ -109,6 +111,7 @@ public List<Changed> getChangedElements() {
109111
enumeration,
110112
required,
111113
maxLength,
114+
numericRange,
112115
extensions))
113116
.collect(Collectors.toList());
114117
}
@@ -356,6 +359,12 @@ public ChangedSchema setMaxLength(final ChangedMaxLength maxLength) {
356359
return this;
357360
}
358361

362+
public ChangedSchema setNumericRange(final ChangedNumericRange numericRange) {
363+
clearChangedCache();
364+
this.numericRange = numericRange;
365+
return this;
366+
}
367+
359368
public ChangedSchema setDiscriminatorPropertyChanged(final boolean discriminatorPropertyChanged) {
360369
clearChangedCache();
361370
this.discriminatorPropertyChanged = discriminatorPropertyChanged;
@@ -410,6 +419,7 @@ public boolean equals(Object o) {
410419
&& Objects.equals(readOnly, that.readOnly)
411420
&& Objects.equals(writeOnly, that.writeOnly)
412421
&& Objects.equals(maxLength, that.maxLength)
422+
&& Objects.equals(numericRange, that.numericRange)
413423
&& Objects.equals(items, that.items)
414424
&& Objects.equals(oneOfSchema, that.oneOfSchema)
415425
&& Objects.equals(addProp, that.addProp)
@@ -437,6 +447,7 @@ public int hashCode() {
437447
writeOnly,
438448
changedType,
439449
maxLength,
450+
numericRange,
440451
discriminatorPropertyChanged,
441452
items,
442453
oneOfSchema,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ public DiffContext setLeftAndRightUrls(String leftUrl, String rightUrl) {
116116
return this;
117117
}
118118

119-
public String getLeftUrl() { return this.leftUrl; }
119+
public String getLeftUrl() {
120+
return this.leftUrl;
121+
}
120122

121-
public String getRightUrl() { return this.rightUrl; }
123+
public String getRightUrl() {
124+
return this.rightUrl;
125+
}
122126

123127
@Override
124128
public boolean equals(Object o) {
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package org.openapitools.openapidiff.core.model.schema;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Objects;
5+
import org.openapitools.openapidiff.core.model.Changed;
6+
import org.openapitools.openapidiff.core.model.DiffContext;
7+
import org.openapitools.openapidiff.core.model.DiffResult;
8+
9+
public final class ChangedNumericRange implements Changed {
10+
private final BigDecimal oldMinimumValue;
11+
private final BigDecimal newMinimumValue;
12+
private final BigDecimal oldMaximumValue;
13+
private final BigDecimal newMaximumValue;
14+
private final Boolean oldMinimumExclusiveValue;
15+
private final Boolean newMinimumExclusiveValue;
16+
private final Boolean oldMaximumExclusiveValue;
17+
private final Boolean newMaximumExclusiveValue;
18+
private final DiffContext context;
19+
20+
@Override
21+
public DiffResult isChanged() {
22+
if (Objects.equals(oldMinimumValue, newMinimumValue)
23+
&& Objects.equals(oldMaximumValue, newMaximumValue)
24+
&& Objects.equals(oldMinimumExclusiveValue, newMinimumExclusiveValue)
25+
&& Objects.equals(oldMaximumExclusiveValue, newMaximumExclusiveValue)) {
26+
return DiffResult.NO_CHANGES;
27+
}
28+
if (context.isRequest()
29+
&& (newMinimumValue == null
30+
|| oldMinimumValue != null
31+
&& oldMinimumValue.unscaledValue().compareTo(newMinimumValue.unscaledValue())
32+
>= 0)
33+
&& (newMaximumValue == null
34+
|| oldMaximumValue != null
35+
&& oldMaximumValue.unscaledValue().compareTo(newMaximumValue.unscaledValue())
36+
<= 0)
37+
&& (newMinimumExclusiveValue == null
38+
|| oldMinimumExclusiveValue != null && newMinimumExclusiveValue == true)
39+
&& (newMaximumExclusiveValue == null
40+
|| oldMaximumExclusiveValue != null && newMaximumExclusiveValue == true)
41+
|| context.isResponse()
42+
&& (newMinimumValue == null
43+
|| oldMinimumValue != null
44+
&& oldMinimumValue.unscaledValue().compareTo(newMinimumValue.unscaledValue())
45+
>= 0)
46+
&& (newMaximumValue == null
47+
|| oldMaximumValue != null
48+
&& oldMaximumValue.unscaledValue().compareTo(newMaximumValue.unscaledValue())
49+
<= 0)
50+
&& (newMinimumExclusiveValue == null
51+
|| oldMinimumExclusiveValue != null && newMinimumExclusiveValue == true)
52+
&& (newMaximumExclusiveValue == null
53+
|| oldMaximumExclusiveValue != null && newMaximumExclusiveValue == true)) {
54+
return DiffResult.COMPATIBLE;
55+
}
56+
return DiffResult.INCOMPATIBLE;
57+
}
58+
59+
public ChangedNumericRange(
60+
final BigDecimal oldMinimumValue,
61+
final BigDecimal newMinimumValue,
62+
final BigDecimal oldMaximumValue,
63+
final BigDecimal newMaximumValue,
64+
final Boolean oldMinimumExclusiveValue,
65+
final Boolean newMinimumExclusiveValue,
66+
final Boolean oldMaximumExclusiveValue,
67+
final Boolean newMaximumExclusiveValue,
68+
final DiffContext context) {
69+
this.oldMinimumValue = oldMinimumValue;
70+
this.newMinimumValue = newMinimumValue;
71+
this.oldMaximumValue = oldMaximumValue;
72+
this.newMaximumValue = newMaximumValue;
73+
this.oldMinimumExclusiveValue = oldMinimumExclusiveValue;
74+
this.newMinimumExclusiveValue = newMinimumExclusiveValue;
75+
this.oldMaximumExclusiveValue = oldMaximumExclusiveValue;
76+
this.newMaximumExclusiveValue = newMaximumExclusiveValue;
77+
this.context = context;
78+
}
79+
80+
public BigDecimal getOldMinimumValue() {
81+
return oldMinimumValue;
82+
}
83+
84+
public BigDecimal getNewMinimumValue() {
85+
return newMinimumValue;
86+
}
87+
88+
public BigDecimal getOldMaximumValue() {
89+
return oldMaximumValue;
90+
}
91+
92+
public BigDecimal getNewMaximumValue() {
93+
return newMaximumValue;
94+
}
95+
96+
public Boolean getOldMinimumExclusiveValue() {
97+
return oldMinimumExclusiveValue;
98+
}
99+
100+
public Boolean getNewMinimumExclusiveValue() {
101+
return newMinimumExclusiveValue;
102+
}
103+
104+
public Boolean getOldMaximumExclusiveValue() {
105+
return oldMaximumExclusiveValue;
106+
}
107+
108+
public Boolean getNewMaximumExclusiveValue() {
109+
return newMaximumExclusiveValue;
110+
}
111+
112+
public DiffContext getContext() {
113+
return this.context;
114+
}
115+
116+
@Override
117+
public boolean equals(Object o) {
118+
if (this == o) return true;
119+
if (o == null || getClass() != o.getClass()) return false;
120+
ChangedNumericRange that = (ChangedNumericRange) o;
121+
return Objects.equals(oldMinimumValue, newMinimumValue)
122+
&& Objects.equals(oldMaximumValue, newMaximumValue)
123+
&& Objects.equals(oldMinimumExclusiveValue, newMinimumExclusiveValue)
124+
&& Objects.equals(oldMaximumExclusiveValue, newMaximumExclusiveValue)
125+
&& Objects.equals(context, that.context);
126+
}
127+
128+
@Override
129+
public int hashCode() {
130+
return Objects.hash(
131+
oldMinimumValue,
132+
newMinimumValue,
133+
oldMaximumValue,
134+
newMaximumValue,
135+
oldMinimumExclusiveValue,
136+
newMinimumExclusiveValue,
137+
oldMaximumExclusiveValue,
138+
newMaximumExclusiveValue,
139+
context);
140+
}
141+
142+
@Override
143+
public String toString() {
144+
return "ChangedNumericRange("
145+
+ "oldMinimumValue="
146+
+ oldMinimumValue
147+
+ ", newMinimumValue="
148+
+ newMinimumValue
149+
+ ", oldMaximumValue="
150+
+ oldMaximumValue
151+
+ ", newMaximumValue="
152+
+ newMaximumValue
153+
+ ", oldMinimumExclusiveValue="
154+
+ oldMinimumExclusiveValue
155+
+ ", newMinimumExclusiveValue="
156+
+ newMinimumExclusiveValue
157+
+ ", oldMaximumExclusiveValue="
158+
+ oldMaximumExclusiveValue
159+
+ ", newMaximumExclusiveValue="
160+
+ newMaximumExclusiveValue
161+
+ ", context="
162+
+ context
163+
+ ')';
164+
}
165+
}

0 commit comments

Comments
 (0)