Skip to content

Commit 0856ad6

Browse files
authored
Add diff results of operation ID (metadata) (#191)
Closes #189
1 parent 0622adc commit 0856ad6

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public Optional<ChangedOperation> diff(
3232
.getMetadataDiff()
3333
.diff(oldOperation.getDescription(), newOperation.getDescription(), context)
3434
.ifPresent(changedOperation::setDescription);
35+
openApiDiff
36+
.getMetadataDiff()
37+
.diff(oldOperation.getOperationId(), newOperation.getOperationId(), context)
38+
.ifPresent(changedOperation::setOperationId);
3539
changedOperation.setDeprecated(
3640
!Boolean.TRUE.equals(oldOperation.getDeprecated())
3741
&& Boolean.TRUE.equals(newOperation.getDeprecated()));

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

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ChangedOperation implements ComposedChanged {
1515
private PathItem.HttpMethod httpMethod;
1616
private ChangedMetadata summary;
1717
private ChangedMetadata description;
18+
private ChangedMetadata operationId;
1819
private boolean deprecated;
1920
private ChangedParameters parameters;
2021
private ChangedRequestBody requestBody;
@@ -38,6 +39,7 @@ public List<Changed> getChangedElements() {
3839
return Arrays.asList(
3940
summary,
4041
description,
42+
operationId,
4143
parameters,
4244
requestBody,
4345
apiResponses,
@@ -86,6 +88,10 @@ public ChangedMetadata getDescription() {
8688
return this.description;
8789
}
8890

91+
public ChangedMetadata getOperationId() {
92+
return this.operationId;
93+
}
94+
8995
public boolean isDeprecated() {
9096
return this.deprecated;
9197
}
@@ -140,6 +146,11 @@ public ChangedOperation setDescription(final ChangedMetadata description) {
140146
return this;
141147
}
142148

149+
public ChangedOperation setOperationId(final ChangedMetadata operationId) {
150+
this.operationId = operationId;
151+
return this;
152+
}
153+
143154
public ChangedOperation setDeprecated(final boolean deprecated) {
144155
this.deprecated = deprecated;
145156
return this;
@@ -183,6 +194,7 @@ public boolean equals(Object o) {
183194
&& httpMethod == that.httpMethod
184195
&& Objects.equals(summary, that.summary)
185196
&& Objects.equals(description, that.description)
197+
&& Objects.equals(operationId, that.operationId)
186198
&& Objects.equals(parameters, that.parameters)
187199
&& Objects.equals(requestBody, that.requestBody)
188200
&& Objects.equals(apiResponses, that.apiResponses)
@@ -199,6 +211,7 @@ public int hashCode() {
199211
httpMethod,
200212
summary,
201213
description,
214+
operationId,
202215
deprecated,
203216
parameters,
204217
requestBody,
@@ -221,6 +234,8 @@ public java.lang.String toString() {
221234
+ this.getSummary()
222235
+ ", description="
223236
+ this.getDescription()
237+
+ ", operationId="
238+
+ this.getOperationId()
224239
+ ", deprecated="
225240
+ this.isDeprecated()
226241
+ ", parameters="
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.openapitools.openapidiff.core;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
7+
import org.openapitools.openapidiff.core.model.DiffResult;
8+
9+
public class OperationDiffTest {
10+
11+
private final String OPENAPI_DOC1 = "operation_diff_1.yaml";
12+
private final String OPENAPI_DOC2 = "operation_diff_2.yaml";
13+
14+
@Test
15+
public void testContentDiffWithOneEmptyMediaType() {
16+
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2);
17+
assertThat(changedOpenApi.isChanged()).isEqualTo(DiffResult.METADATA);
18+
assertThat(changedOpenApi.isDifferent()).isTrue();
19+
assertThat(changedOpenApi.getChangedOperations().size()).isEqualTo(1);
20+
assertThat(changedOpenApi.getChangedOperations().get(0).getOperationId().isDifferent())
21+
.isTrue();
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: operation
20+
responses:
21+
'200':
22+
description: response
23+
content:
24+
application/json: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
openapi: "3.0.1"
3+
info:
4+
title: "Test title"
5+
description: "This is a test metadata"
6+
termsOfService: "http://test.com"
7+
contact:
8+
name: "Mark Snijder"
9+
url: "marksnijder.nl"
10+
11+
license:
12+
name: "To be decided"
13+
url: "http://test.com"
14+
version: "version 1.0"
15+
paths:
16+
/pets/{id}:
17+
get:
18+
description: Returns a user based on a single ID, if the user does not have access to the pet
19+
operationId: changed
20+
responses:
21+
'200':
22+
description: response
23+
content:
24+
application/json: {}

0 commit comments

Comments
 (0)