From 0106cf88e972afd4157ac87b0733beb64285d4f5 Mon Sep 17 00:00:00 2001 From: "hidde.wieringa" Date: Thu, 22 Oct 2020 16:38:03 +0200 Subject: [PATCH 1/2] Feature: add diff results of operation ID (metadata) --- .../core/compare/OperationDiff.java | 4 ++++ .../core/model/ChangedOperation.java | 15 ++++++++++++ .../openapidiff/core/OperationDiffTest.java | 23 ++++++++++++++++++ core/src/test/resources/operation_diff_1.yaml | 24 +++++++++++++++++++ core/src/test/resources/operation_diff_2.yaml | 24 +++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 core/src/test/java/org/openapitools/openapidiff/core/OperationDiffTest.java create mode 100644 core/src/test/resources/operation_diff_1.yaml create mode 100644 core/src/test/resources/operation_diff_2.yaml diff --git a/core/src/main/java/org/openapitools/openapidiff/core/compare/OperationDiff.java b/core/src/main/java/org/openapitools/openapidiff/core/compare/OperationDiff.java index 038816c77..3a9f0f656 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/compare/OperationDiff.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/compare/OperationDiff.java @@ -32,6 +32,10 @@ public Optional 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())); diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java index 7af8a3a1b..2171a2b4b 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java @@ -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; @@ -38,6 +39,7 @@ public List getChangedElements() { return Arrays.asList( summary, description, + operationId, parameters, requestBody, apiResponses, @@ -86,6 +88,10 @@ public ChangedMetadata getDescription() { return this.description; } + public ChangedMetadata getOperationId() { + return this.operationId; + } + public boolean isDeprecated() { return this.deprecated; } @@ -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; @@ -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) @@ -199,6 +211,7 @@ public int hashCode() { httpMethod, summary, description, + operationId, deprecated, parameters, requestBody, @@ -221,6 +234,8 @@ public java.lang.String toString() { + this.getSummary() + ", description=" + this.getDescription() + + ", description=" + + this.getOperationId() + ", deprecated=" + this.isDeprecated() + ", parameters=" diff --git a/core/src/test/java/org/openapitools/openapidiff/core/OperationDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/OperationDiffTest.java new file mode 100644 index 000000000..79f929f82 --- /dev/null +++ b/core/src/test/java/org/openapitools/openapidiff/core/OperationDiffTest.java @@ -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(); + } +} diff --git a/core/src/test/resources/operation_diff_1.yaml b/core/src/test/resources/operation_diff_1.yaml new file mode 100644 index 000000000..0618b58e6 --- /dev/null +++ b/core/src/test/resources/operation_diff_1.yaml @@ -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: "snijderd@gmail.com" + 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: {} diff --git a/core/src/test/resources/operation_diff_2.yaml b/core/src/test/resources/operation_diff_2.yaml new file mode 100644 index 000000000..8d60a2dc1 --- /dev/null +++ b/core/src/test/resources/operation_diff_2.yaml @@ -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: "snijderd@gmail.com" + 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: {} From 454e6e83c380198a16e62c8970bb6854a9b8271b Mon Sep 17 00:00:00 2001 From: "hidde.wieringa" Date: Thu, 22 Oct 2020 16:41:07 +0200 Subject: [PATCH 2/2] Fix copy paste error --- .../openapitools/openapidiff/core/model/ChangedOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java index 2171a2b4b..0da0516fc 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedOperation.java @@ -234,7 +234,7 @@ public java.lang.String toString() { + this.getSummary() + ", description=" + this.getDescription() - + ", description=" + + ", operationId=" + this.getOperationId() + ", deprecated=" + this.isDeprecated()