From be914cb14fdeaa1de9f1707d9bd98731d588e0f7 Mon Sep 17 00:00:00 2001 From: westse <10818305+westse@users.noreply.github.com> Date: Wed, 28 Jun 2023 16:45:15 -0600 Subject: [PATCH 1/2] Treat new PUT request properties as compatible. Effectively reverts change for #136 which appears invalid in intent, implementation, and test. - Invalid in intent: #136 claims that adding a readOnly property to the request body of a PUT request is a breaking change because clients will begin to omit it and the server will interpret the omission as a directive to delete the property. This is incorrect because the server should expect, [per the OAS spec](https://spec.openapis.org/oas/v3.0.3#fixed-fields-19), that readOnly properties "SHOULD NOT be sent as part of the request". So it would be a bug for the server to delete any data associated with the readOnly property. Regardless, the API is left unbroken if the server simply ignores readOnly properties. - Invalid in implementation: the code treats as incompatible any PUT request property, not just readOnly properties. - Invalid in test: no readOnly properties are tested. In theory one could argue that some servers might enforce the "SHOULD NOT" language of the spec by returning validation errors where they didn't before, and this would constitute an API breakage. But that should be discussed in a different issue. --- .../openapidiff/core/model/ChangedSchema.java | 4 ---- .../openapidiff/core/AddPropPutDiffTest.java | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedSchema.java b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedSchema.java index 80d98007..d62cd7b6 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedSchema.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/ChangedSchema.java @@ -1,6 +1,5 @@ package org.openapitools.openapidiff.core.model; -import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.media.Schema; import java.util.*; import java.util.stream.Collectors; @@ -157,9 +156,6 @@ private DiffResult calculateCoreChanged() { } private boolean compatibleForRequest() { - if (PathItem.HttpMethod.PUT.equals(context.getMethod()) && !increasedProperties.isEmpty()) { - return false; - } return (oldSchema != null || newSchema == null); } diff --git a/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java index d73ab6eb..21f0b368 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java @@ -1,9 +1,10 @@ package org.openapitools.openapidiff.core; +import static org.assertj.core.api.Assertions.assertThat; import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals; -import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardIncompatible; import org.junit.jupiter.api.Test; +import org.openapitools.openapidiff.core.model.ChangedOpenApi; public class AddPropPutDiffTest { private final String OPENAPI_DOC1 = "add-prop-put-1.yaml"; @@ -15,7 +16,9 @@ public void testDiffSame() { } @Test - public void testDiffDifferent() { - assertOpenApiBackwardIncompatible(OPENAPI_DOC1, OPENAPI_DOC2); + public void testFieldAdditionalInPutApiIsCompatible() { + ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); + assertThat(changedOpenApi.isDifferent()).isTrue(); + assertThat(changedOpenApi.isCompatible()).isTrue(); } } From 0821b21011301748d3a4264dd5412e3ab0ae3860 Mon Sep 17 00:00:00 2001 From: westse <10818305+westse@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:52:44 -0600 Subject: [PATCH 2/2] Comment referencing ticket - https://github.com/OpenAPITools/openapi-diff/pull/537 --- .../org/openapitools/openapidiff/core/AddPropPutDiffTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java index 21f0b368..6ecc1bc2 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java @@ -17,6 +17,7 @@ public void testDiffSame() { @Test public void testFieldAdditionalInPutApiIsCompatible() { + // See https://github.com/OpenAPITools/openapi-diff/pull/537 ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); assertThat(changedOpenApi.isDifferent()).isTrue(); assertThat(changedOpenApi.isCompatible()).isTrue();