Skip to content
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 @@ -12,6 +12,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.openapitools.openapidiff.core.compare.MapKeyDiff;
import org.openapitools.openapidiff.core.compare.OpenApiDiff;
import org.openapitools.openapidiff.core.compare.SchemaDiff;
import org.openapitools.openapidiff.core.model.ChangedSchema;
import org.openapitools.openapidiff.core.model.DiffContext;
import org.openapitools.openapidiff.core.model.deferred.DeferredBuilder;
Expand Down Expand Up @@ -98,11 +99,24 @@ public <T extends Schema<X>, X> DeferredChanged<ChangedSchema> diff(
.build()
.flatMap(
values -> super.diff(refSet, leftComponents, rightComponents, left, right, context));
} else if (isResolvedToPlainSchema(right)) {
// `right` is a composed schema whose allOf/anyOf members have already been merged into it
// by SchemaDiff#resolveComposedSchema, so structurally it is a plain schema. Types and
// formats were compared in SchemaDiff#computeDiffForReal before this result was selected,
// so diff both sides with the result matching the left-hand schema instead of reporting a
// type change.
return SchemaDiff.getSchemaDiffResult(left.getClass(), openApiDiff)
.diff(refSet, leftComponents, rightComponents, left, right, context);
} else {
return openApiDiff.getSchemaDiff().getTypeChangedSchema(left, right, context);
}
}

private static boolean isResolvedToPlainSchema(Schema<?> schema) {
return schema instanceof ComposedSchema
&& CollectionUtils.isEmpty(((ComposedSchema) schema).getOneOf());
}

private Map<String, Schema> getSchema(
Components components, Map<String, String> mapping, ComposedSchema composedSchema) {
Map<String, Schema> result = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.openapitools.openapidiff.core;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;

import org.junit.jupiter.api.Test;
Expand All @@ -11,19 +10,12 @@ public class Issue887Test {
private final String DIRECT_ARRAY = "issue-887-2.yaml";

@Test
public void testAllOfArrayToDirectArrayDoesNotThrow() {
assertThatCode(() -> OpenApiCompare.fromLocations(ALLOF_ARRAY, DIRECT_ARRAY))
.doesNotThrowAnyException();
}

@Test
public void testDirectArrayToAllOfArrayDoesNotThrow() {
assertThatCode(() -> OpenApiCompare.fromLocations(DIRECT_ARRAY, ALLOF_ARRAY))
.doesNotThrowAnyException();
public void testAllOfArrayToDirectArrayAreEquals() {
assertOpenApiAreEquals(ALLOF_ARRAY, DIRECT_ARRAY);
}

@Test
public void testAllOfArrayToDirectArrayAreEquals() {
assertOpenApiAreEquals(ALLOF_ARRAY, DIRECT_ARRAY);
public void testDirectArrayToAllOfArrayAreEquals() {
assertOpenApiAreEquals(DIRECT_ARRAY, ALLOF_ARRAY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openapitools.openapidiff.core;

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

import org.junit.jupiter.api.Test;

public class Issue920Test {

private final String DIRECT_ARRAY_STRING_ITEM = "issue-920-1.yaml";
private final String ALLOF_ARRAY_INTEGER_ITEM = "issue-920-2.yaml";

/**
* Items must still be compared when a direct array is replaced by an allOf-wrapped array,
* otherwise falling through to a plain schema diff would silently hide item changes.
*/
@Test
public void testDirectArrayToAllOfArrayDetectsChangedItemType() {
assertOpenApiBackwardIncompatible(DIRECT_ARRAY_STRING_ITEM, ALLOF_ARRAY_INTEGER_ITEM);
}

@Test
public void testAllOfArrayToDirectArrayDetectsChangedItemType() {
assertOpenApiBackwardIncompatible(ALLOF_ARRAY_INTEGER_ITEM, DIRECT_ARRAY_STRING_ITEM);
}
}
31 changes: 31 additions & 0 deletions core/src/test/resources/issue-920-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.3
info:
title: Test API
version: 1.0.0

paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'

components:
schemas:
TestResponse:
type: object
properties:
valuations:
type: array
items:
$ref: '#/components/schemas/Valuation'

Valuation:
type: object
properties:
value:
type: string
32 changes: 32 additions & 0 deletions core/src/test/resources/issue-920-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.3
info:
title: Test API
version: 1.0.0

paths:
/test:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'

components:
schemas:
TestResponse:
type: object
properties:
valuations:
allOf:
- $ref: '#/components/schemas/Valuations'

Valuations:
type: array
items:
type: object
properties:
value:
type: integer