Skip to content
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

#198: Fixing false positive breaking change reported when removing an optional field from a response #327

Merged
merged 1 commit into from
Feb 28, 2022
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 @@ -137,8 +137,13 @@ private DiffResult calculateCoreChanged() {
&& !discriminatorPropertyChanged) {
return DiffResult.NO_CHANGES;
}
boolean missingRequiredProperties =
oldSchema != null
&& oldSchema.getRequired() != null
&& missingProperties.keySet().stream()
.anyMatch(missingProperty -> oldSchema.getRequired().contains(missingProperty));
boolean compatibleForResponse =
missingProperties.isEmpty() && (oldSchema == null || newSchema != null);
!missingRequiredProperties && (oldSchema == null || newSchema != null);
if ((context.isRequest() && compatibleForRequest()
|| context.isResponse() && compatibleForResponse)
&& !changedType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.openapitools.openapidiff.core;

import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardIncompatible;
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardCompatible;

import org.junit.jupiter.api.Test;

Expand All @@ -16,6 +16,6 @@ public void testDiffSame() {

@Test
public void testDiffDifferent() {
assertOpenApiBackwardIncompatible(OPENAPI_DOC1, OPENAPI_DOC2);
assertOpenApiBackwardCompatible(OPENAPI_DOC1, OPENAPI_DOC2, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test actually covers the use case in #198, just has incorrect assertion.

}
}
3 changes: 2 additions & 1 deletion core/src/test/resources/recursive_model_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ components:
schemas:
B:
type: object
required: ["message2"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test RecursiveSchemaTest expects backwards-incompatible change and by coincidence used removal of optional field from response as a change. Either the field should be required or the test should expect backwards-compatible change. I decided to go with the former.

properties:
message:
type: string
Expand All @@ -27,4 +28,4 @@ components:
details:
type: array
items:
$ref: '#/components/schemas/B'
$ref: '#/components/schemas/B'