-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removal of 'deprecated' not detected (#743)
* Fix issue #485 - Removal of 'deprecated' is not detected on schema, operation, parameter, and header level. * Reorganize tests structure * Extend test coverage for CchemaDiff, OperationDiff, ParameterDiff, HeaderDiff
- Loading branch information
Showing
61 changed files
with
1,015 additions
and
1,103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
core/src/test/java/org/openapitools/openapidiff/core/AddPropDiffTest.java
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
core/src/test/java/org/openapitools/openapidiff/core/AddPropPutDiffTest.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
core/src/test/java/org/openapitools/openapidiff/core/AdditionalPropertiesTest.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
core/src/test/java/org/openapitools/openapidiff/core/ChangesResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.openapitools.openapidiff.core; | ||
|
||
import io.swagger.v3.oas.models.PathItem.HttpMethod; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
import org.openapitools.openapidiff.core.model.ChangedApiResponse; | ||
import org.openapitools.openapidiff.core.model.ChangedContent; | ||
import org.openapitools.openapidiff.core.model.ChangedHeaders; | ||
import org.openapitools.openapidiff.core.model.ChangedMediaType; | ||
import org.openapitools.openapidiff.core.model.ChangedOpenApi; | ||
import org.openapitools.openapidiff.core.model.ChangedOperation; | ||
import org.openapitools.openapidiff.core.model.ChangedParameter; | ||
import org.openapitools.openapidiff.core.model.ChangedParameters; | ||
import org.openapitools.openapidiff.core.model.ChangedRequestBody; | ||
import org.openapitools.openapidiff.core.model.ChangedResponse; | ||
import org.openapitools.openapidiff.core.model.ChangedSchema; | ||
|
||
public class ChangesResolver { | ||
|
||
@Nullable | ||
public static ChangedOperation getChangedOperation( | ||
ChangedOpenApi changedOpenApi, HttpMethod method, String path) { | ||
return changedOpenApi.getChangedOperations().stream() | ||
.filter( | ||
operation -> | ||
operation.getHttpMethod().equals(method) && operation.getPathUrl().equals(path)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
@Nullable | ||
public static ChangedParameter getChangedParameter( | ||
ChangedOpenApi changedOpenApi, HttpMethod method, String path, String parameterName) { | ||
ChangedOperation changedOperation = getChangedOperation(changedOpenApi, method, path); | ||
|
||
if (changedOperation == null) { | ||
return null; | ||
} | ||
|
||
return Optional.ofNullable(changedOperation.getParameters()) | ||
.map(ChangedParameters::getChanged) | ||
.flatMap( | ||
changedParameters -> | ||
changedParameters.stream() | ||
.filter(changedParameter -> changedParameter.getName().equals(parameterName)) | ||
.findFirst()) | ||
.orElse(null); | ||
} | ||
|
||
@Nullable | ||
public static ChangedHeaders getChangedResponseHeaders( | ||
ChangedOpenApi changedOpenApi, HttpMethod method, String path, String responseCode) { | ||
return Optional.ofNullable(getChangedOperation(changedOpenApi, method, path)) | ||
.map(ChangedOperation::getApiResponses) | ||
.map(ChangedApiResponse::getChanged) | ||
.map(responses -> responses.get(responseCode)) | ||
.map(ChangedResponse::getHeaders) | ||
.orElse(null); | ||
} | ||
|
||
@Nullable | ||
public static ChangedSchema getRequestBodyChangedSchema( | ||
ChangedOperation changedOperation, String mediaType) { | ||
return Optional.ofNullable(changedOperation) | ||
.map(ChangedOperation::getRequestBody) | ||
.map(ChangedRequestBody::getContent) | ||
.map(ChangedContent::getChanged) | ||
.map(changedMediaTypes -> changedMediaTypes.get(mediaType)) | ||
.map(ChangedMediaType::getSchema) | ||
.orElse(null); | ||
} | ||
} |
62 changes: 54 additions & 8 deletions
62
core/src/test/java/org/openapitools/openapidiff/core/OperationDiffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,69 @@ | ||
package org.openapitools.openapidiff.core; | ||
|
||
import static io.swagger.v3.oas.models.PathItem.HttpMethod.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.openapitools.openapidiff.core.ChangesResolver.getChangedOperation; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.openapidiff.core.model.ChangedOpenApi; | ||
import org.openapitools.openapidiff.core.model.ChangedOperation; | ||
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"; | ||
private final String OPENAPI_DOC1 = "operationDiff/operation_diff_1.yaml"; | ||
private final String OPENAPI_DOC2 = "operationDiff/operation_diff_2.yaml"; | ||
|
||
@Test | ||
public void testContentDiffWithOneEmptyMediaType() { | ||
public void testOperationIdChanged() { | ||
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(); | ||
ChangedOperation changedOperation = | ||
getChangedOperation(changedOpenApi, GET, "/operation/operation-id"); | ||
|
||
assertThat(changedOperation).isNotNull(); | ||
assertThat(changedOperation.isChanged()).isEqualTo(DiffResult.METADATA); | ||
assertThat(changedOperation.getOperationId().getRight()).isEqualTo("changed"); | ||
} | ||
|
||
@Test | ||
public void testOperationSummaryChanged() { | ||
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
ChangedOperation changedOperation = | ||
getChangedOperation(changedOpenApi, GET, "/operation/summary"); | ||
|
||
assertThat(changedOperation).isNotNull(); | ||
assertThat(changedOperation.isChanged()).isEqualTo(DiffResult.METADATA); | ||
assertThat(changedOperation.getSummary().getRight()).isEqualTo("changed"); | ||
} | ||
|
||
@Test | ||
public void testOperationDescriptionChanged() { | ||
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
ChangedOperation changedOperation = | ||
getChangedOperation(changedOpenApi, GET, "/operation/description"); | ||
|
||
assertThat(changedOperation).isNotNull(); | ||
assertThat(changedOperation.isChanged()).isEqualTo(DiffResult.METADATA); | ||
assertThat(changedOperation.getDescription().getRight()).isEqualTo("changed"); | ||
} | ||
|
||
@Test | ||
public void testOperationBecomesDeprecated() { | ||
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
ChangedOperation changedOperation = | ||
getChangedOperation(changedOpenApi, GET, "/operation/becomes-deprecated"); | ||
|
||
assertThat(changedOperation).isNotNull(); | ||
assertThat(changedOperation.isDeprecated()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testOperationBecomesNotDeprecated() { | ||
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
ChangedOperation changedOperation = | ||
getChangedOperation(changedOpenApi, GET, "/operation/becomes-not-deprecated"); | ||
|
||
assertThat(changedOperation).isNotNull(); | ||
assertThat(changedOperation.isDeprecated()).isTrue(); | ||
} | ||
} |
Oops, something went wrong.