Skip to content

Commit be914cb

Browse files
committed
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.
1 parent fa2b18f commit be914cb

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.openapitools.openapidiff.core.model;
22

3-
import io.swagger.v3.oas.models.PathItem;
43
import io.swagger.v3.oas.models.media.Schema;
54
import java.util.*;
65
import java.util.stream.Collectors;
@@ -157,9 +156,6 @@ private DiffResult calculateCoreChanged() {
157156
}
158157

159158
private boolean compatibleForRequest() {
160-
if (PathItem.HttpMethod.PUT.equals(context.getMethod()) && !increasedProperties.isEmpty()) {
161-
return false;
162-
}
163159
return (oldSchema != null || newSchema == null);
164160
}
165161

core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.openapitools.openapidiff.core;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
4-
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardIncompatible;
55

66
import org.junit.jupiter.api.Test;
7+
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
78

89
public class AddPropPutDiffTest {
910
private final String OPENAPI_DOC1 = "add-prop-put-1.yaml";
@@ -15,7 +16,9 @@ public void testDiffSame() {
1516
}
1617

1718
@Test
18-
public void testDiffDifferent() {
19-
assertOpenApiBackwardIncompatible(OPENAPI_DOC1, OPENAPI_DOC2);
19+
public void testFieldAdditionalInPutApiIsCompatible() {
20+
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2);
21+
assertThat(changedOpenApi.isDifferent()).isTrue();
22+
assertThat(changedOpenApi.isCompatible()).isTrue();
2023
}
2124
}

0 commit comments

Comments
 (0)