Skip to content

Commit 9d39253

Browse files
committed
Extension are now supported by PathItem, Operation, Parameter & Request Body
1 parent 5c95b34 commit 9d39253

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

src/main/java/com/qdesrame/openapi/diff/compare/OperationDiff.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public Optional<ChangedOperation> diff(Operation oldOperation, Operation newOper
4949
.ifPresent(changedOperation::setChangedSecurityRequirements);
5050
}
5151

52+
openApiDiff.getExtensionsDiff().diff(oldOperation.getExtensions(), newOperation.getExtensions(), context)
53+
.ifPresent(changedOperation::setChangedExtensions);
54+
5255
return isChanged(changedOperation);
5356
}
5457

src/main/java/com/qdesrame/openapi/diff/compare/ParameterDiff.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ protected Optional<ChangedParameter> computeDiff(HashSet<String> refSet, Paramet
5252
}
5353
openApiDiff.getContentDiff().diff(left.getContent(), right.getContent(), context)
5454
.ifPresent(changedParameter::setChangedContent);
55-
55+
openApiDiff.getExtensionsDiff().diff(left.getExtensions(), right.getExtensions(), context)
56+
.ifPresent(changedParameter::setChangedExtensions);
5657
return isChanged(changedParameter);
5758
}
5859

src/main/java/com/qdesrame/openapi/diff/compare/PathDiff.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public Optional<ChangedPath> diff(PathItem left, PathItem right, DiffContext con
3333
Operation newOperation = newOperationMap.get(method);
3434
openApiDiff.getOperationDiff().diff(oldOperation, newOperation, context.copyWithMethod(method)).ifPresent(changedPath.getChanged()::add);
3535
}
36+
openApiDiff.getExtensionsDiff().diff(left.getExtensions(), right.getExtensions(), context)
37+
.ifPresent(changedPath::setChangedExtensions);
3638
return isChanged(changedPath);
3739
}
3840
}

src/main/java/com/qdesrame/openapi/diff/compare/RequestBodyDiff.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import io.swagger.v3.oas.models.parameters.RequestBody;
99

1010
import java.util.HashSet;
11+
import java.util.Map;
1112
import java.util.Objects;
1213
import java.util.Optional;
1314

1415
import static com.qdesrame.openapi.diff.utils.ChangedUtils.isChanged;
16+
import static java.util.Optional.ofNullable;
1517

1618
/**
1719
* Created by adarsh.sharma on 28/12/17.
@@ -30,6 +32,10 @@ public Optional<ChangedRequestBody> diff(RequestBody left, RequestBody right, Di
3032
return cachedDiff(new HashSet<>(), left, right, leftRef, rightRef, context);
3133
}
3234

35+
private static Map<String, Object> getExtensions(RequestBody body) {
36+
return ofNullable(body).map(RequestBody::getExtensions).orElse(null);
37+
}
38+
3339
@Override
3440
protected Optional<ChangedRequestBody> computeDiff(HashSet<String> refSet, RequestBody left, RequestBody right, DiffContext context) {
3541
Content oldRequestContent = new Content();
@@ -59,6 +65,8 @@ protected Optional<ChangedRequestBody> computeDiff(HashSet<String> refSet, Reque
5965
changedRequestBody.setChangeDescription(!Objects.equals(leftDescription, rightDescription));
6066

6167
openApiDiff.getContentDiff().diff(oldRequestContent, newRequestContent, context).ifPresent(changedRequestBody::setChangedContent);
68+
openApiDiff.getExtensionsDiff().diff(getExtensions(left), getExtensions(right), context)
69+
.ifPresent(changedRequestBody::setChangedExtensions);
6270

6371
return isChanged(changedRequestBody);
6472
}

src/main/java/com/qdesrame/openapi/diff/model/ChangedOperation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.qdesrame.openapi.diff.model;
22

3+
import com.qdesrame.openapi.diff.model.schema.ChangedExtensions;
4+
import com.qdesrame.openapi.diff.utils.ChangedUtils;
35
import io.swagger.v3.oas.models.Operation;
46
import io.swagger.v3.oas.models.PathItem;
57
import lombok.Getter;
@@ -18,6 +20,7 @@ public class ChangedOperation implements Changed {
1820
private ChangedRequestBody changedRequestBody;
1921
private ChangedApiResponse changedApiResponse;
2022
private ChangedSecurityRequirements changedSecurityRequirements;
23+
private ChangedExtensions changedExtensions;
2124

2225
public ChangedOperation(String pathUrl, PathItem.HttpMethod httpMethod, Operation oldOperation, Operation newOperation) {
2326
this.httpMethod = httpMethod;
@@ -30,11 +33,13 @@ public ChangedOperation(String pathUrl, PathItem.HttpMethod httpMethod, Operatio
3033
public DiffResult isChanged() {
3134
//TODO BETTER HANDLING FOR DEPRECIATION
3235
if (!deprecated && isChangedParam().isUnchanged() && isChangedRequest().isUnchanged()
33-
&& isChangedResponse().isUnchanged() && isChangedSecurity().isUnchanged()) {
36+
&& isChangedResponse().isUnchanged() && isChangedSecurity().isUnchanged()
37+
&& ChangedUtils.isUnchanged(changedExtensions)) {
3438
return DiffResult.NO_CHANGES;
3539
}
3640
if (isChangedParam().isCompatible() && isChangedRequest().isCompatible()
37-
&& isChangedResponse().isCompatible() && isChangedSecurity().isCompatible()) {
41+
&& isChangedResponse().isCompatible() && isChangedSecurity().isCompatible()
42+
&& ChangedUtils.isCompatible(changedExtensions)) {
3843
return DiffResult.COMPATIBLE;
3944
}
4045
return DiffResult.INCOMPATIBLE;

src/main/java/com/qdesrame/openapi/diff/model/ChangedParameter.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.qdesrame.openapi.diff.model;
22

3+
import com.qdesrame.openapi.diff.model.schema.ChangedExtensions;
4+
import com.qdesrame.openapi.diff.utils.ChangedUtils;
35
import io.swagger.v3.oas.models.parameters.Parameter;
46
import lombok.Getter;
57
import lombok.Setter;
@@ -22,6 +24,7 @@ public class ChangedParameter implements Changed {
2224
private boolean changeAllowEmptyValue;
2325
private ChangedSchema changedSchema;
2426
private ChangedContent changedContent;
27+
private ChangedExtensions changedExtensions;
2528

2629
public ChangedParameter(String name, String in, DiffContext context) {
2730
this.name = name;
@@ -37,16 +40,18 @@ public DiffResult isChanged() {
3740
&& !changeAllowEmptyValue
3841
&& !changeStyle
3942
&& !changeExplode
40-
&& (changedSchema == null || changedSchema.isUnchanged())
41-
&& (changedContent == null || changedContent.isUnchanged())) {
43+
&& ChangedUtils.isUnchanged(changedSchema)
44+
&& ChangedUtils.isUnchanged(changedContent)
45+
&& ChangedUtils.isUnchanged(changedExtensions)) {
4246
return DiffResult.NO_CHANGES;
4347
}
4448
if ((!changeRequired || Boolean.TRUE.equals(oldParameter.getRequired()))
4549
&& (!changeAllowEmptyValue || Boolean.TRUE.equals(newParameter.getAllowEmptyValue()))
4650
&& !changeStyle
4751
&& !changeExplode
48-
&& (changedSchema == null || changedSchema.isCompatible())
49-
&& (changedContent == null || changedContent.isCompatible())) {
52+
&& ChangedUtils.isCompatible(changedSchema)
53+
&& ChangedUtils.isCompatible(changedContent)
54+
&& ChangedUtils.isCompatible(changedExtensions)) {
5055
return DiffResult.COMPATIBLE;
5156
}
5257
return DiffResult.INCOMPATIBLE;

src/main/java/com/qdesrame/openapi/diff/model/ChangedPath.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.qdesrame.openapi.diff.model;
22

3+
import com.qdesrame.openapi.diff.model.schema.ChangedExtensions;
4+
import com.qdesrame.openapi.diff.utils.ChangedUtils;
35
import io.swagger.v3.oas.models.Operation;
46
import io.swagger.v3.oas.models.PathItem;
57
import lombok.Getter;
@@ -21,6 +23,7 @@ public class ChangedPath implements Changed {
2123
Map<PathItem.HttpMethod, Operation> increased;
2224
Map<PathItem.HttpMethod, Operation> missing;
2325
List<ChangedOperation> changed;
26+
private ChangedExtensions changedExtensions;
2427

2528
public ChangedPath(String pathUrl, PathItem oldPath, PathItem newPath, DiffContext context) {
2629
this.pathUrl = pathUrl;
@@ -34,10 +37,11 @@ public ChangedPath(String pathUrl, PathItem oldPath, PathItem newPath, DiffConte
3437

3538
@Override
3639
public DiffResult isChanged() {
37-
if (increased.isEmpty() && missing.isEmpty() && changed.isEmpty()) {
40+
if (increased.isEmpty() && missing.isEmpty() && changed.isEmpty() && ChangedUtils.isUnchanged(changedExtensions)) {
3841
return DiffResult.NO_CHANGES;
3942
}
40-
if (missing.isEmpty() && changed.stream().allMatch(Changed::isCompatible)) {
43+
if (missing.isEmpty() && changed.stream().allMatch(Changed::isCompatible)
44+
&& ChangedUtils.isCompatible(changedExtensions)) {
4145
return DiffResult.COMPATIBLE;
4246
}
4347
return DiffResult.INCOMPATIBLE;

src/main/java/com/qdesrame/openapi/diff/model/ChangedRequestBody.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.qdesrame.openapi.diff.model;
22

3+
import com.qdesrame.openapi.diff.model.schema.ChangedExtensions;
4+
import com.qdesrame.openapi.diff.utils.ChangedUtils;
35
import io.swagger.v3.oas.models.parameters.RequestBody;
46
import lombok.Getter;
57
import lombok.Setter;
@@ -17,6 +19,7 @@ public class ChangedRequestBody implements Changed {
1719
private boolean changeDescription;
1820
private boolean changeRequired;
1921
private ChangedContent changedContent;
22+
private ChangedExtensions changedExtensions;
2023

2124
public ChangedRequestBody(RequestBody oldRequestBody, RequestBody newRequestBody, DiffContext context) {
2225
this.oldRequestBody = oldRequestBody;
@@ -26,10 +29,14 @@ public ChangedRequestBody(RequestBody oldRequestBody, RequestBody newRequestBody
2629

2730
@Override
2831
public DiffResult isChanged() {
29-
if (!changeDescription && !changeRequired && (changedContent == null || changedContent.isUnchanged())) {
32+
if (!changeDescription && !changeRequired
33+
&& ChangedUtils.isUnchanged(changedContent)
34+
&& ChangedUtils.isUnchanged(changedExtensions)) {
3035
return DiffResult.NO_CHANGES;
3136
}
32-
if (!changeRequired && (changedContent == null || changedContent.isCompatible())) {
37+
if (!changeRequired
38+
&& ChangedUtils.isCompatible(changedContent)
39+
&& ChangedUtils.isCompatible(changedExtensions)) {
3340
return DiffResult.COMPATIBLE;
3441
}
3542
return DiffResult.INCOMPATIBLE;

0 commit comments

Comments
 (0)