Skip to content

Add diff results of operation ID (metadata) #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public Optional<ChangedOperation> diff(
.getMetadataDiff()
.diff(oldOperation.getDescription(), newOperation.getDescription(), context)
.ifPresent(changedOperation::setDescription);
openApiDiff
.getMetadataDiff()
.diff(oldOperation.getOperationId(), newOperation.getOperationId(), context)
.ifPresent(changedOperation::setOperationId);
changedOperation.setDeprecated(
!Boolean.TRUE.equals(oldOperation.getDeprecated())
&& Boolean.TRUE.equals(newOperation.getDeprecated()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ChangedOperation implements ComposedChanged {
private PathItem.HttpMethod httpMethod;
private ChangedMetadata summary;
private ChangedMetadata description;
private ChangedMetadata operationId;
private boolean deprecated;
private ChangedParameters parameters;
private ChangedRequestBody requestBody;
Expand All @@ -38,6 +39,7 @@ public List<Changed> getChangedElements() {
return Arrays.asList(
summary,
description,
operationId,
parameters,
requestBody,
apiResponses,
Expand Down Expand Up @@ -86,6 +88,10 @@ public ChangedMetadata getDescription() {
return this.description;
}

public ChangedMetadata getOperationId() {
return this.operationId;
}

public boolean isDeprecated() {
return this.deprecated;
}
Expand Down Expand Up @@ -140,6 +146,11 @@ public ChangedOperation setDescription(final ChangedMetadata description) {
return this;
}

public ChangedOperation setOperationId(final ChangedMetadata operationId) {
this.operationId = operationId;
return this;
}

public ChangedOperation setDeprecated(final boolean deprecated) {
this.deprecated = deprecated;
return this;
Expand Down Expand Up @@ -183,6 +194,7 @@ public boolean equals(Object o) {
&& httpMethod == that.httpMethod
&& Objects.equals(summary, that.summary)
&& Objects.equals(description, that.description)
&& Objects.equals(operationId, that.operationId)
&& Objects.equals(parameters, that.parameters)
&& Objects.equals(requestBody, that.requestBody)
&& Objects.equals(apiResponses, that.apiResponses)
Expand All @@ -199,6 +211,7 @@ public int hashCode() {
httpMethod,
summary,
description,
operationId,
deprecated,
parameters,
requestBody,
Expand All @@ -221,6 +234,8 @@ public java.lang.String toString() {
+ this.getSummary()
+ ", description="
+ this.getDescription()
+ ", operationId="
+ this.getOperationId()
+ ", deprecated="
+ this.isDeprecated()
+ ", parameters="
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openapitools.openapidiff.core;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
import org.openapitools.openapidiff.core.model.DiffResult;

public class OperationDiffTest {

private final String OPENAPI_DOC1 = "operation_diff_1.yaml";
private final String OPENAPI_DOC2 = "operation_diff_2.yaml";

@Test
public void testContentDiffWithOneEmptyMediaType() {
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2);
assertThat(changedOpenApi.isChanged()).isEqualTo(DiffResult.METADATA);
assertThat(changedOpenApi.isDifferent()).isTrue();
assertThat(changedOpenApi.getChangedOperations().size()).isEqualTo(1);
assertThat(changedOpenApi.getChangedOperations().get(0).getOperationId().isDifferent())
.isTrue();
}
}
24 changes: 24 additions & 0 deletions core/src/test/resources/operation_diff_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
openapi: "3.0.1"
info:
title: "Test title"
description: "This is a test metadata"
termsOfService: "http://test.com"
contact:
name: "Mark Snijder"
url: "marksnijder.nl"
email: "[email protected]"
license:
name: "To be decided"
url: "http://test.com"
version: "version 1.0"
paths:
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: operation
responses:
'200':
description: response
content:
application/json: {}
24 changes: 24 additions & 0 deletions core/src/test/resources/operation_diff_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
openapi: "3.0.1"
info:
title: "Test title"
description: "This is a test metadata"
termsOfService: "http://test.com"
contact:
name: "Mark Snijder"
url: "marksnijder.nl"
email: "[email protected]"
license:
name: "To be decided"
url: "http://test.com"
version: "version 1.0"
paths:
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: changed
responses:
'200':
description: response
content:
application/json: {}