diff --git a/Dockerfile b/Dockerfile index 72bd50130..a8b94cf02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM openjdk:8-jdk-slim AS build WORKDIR /build -COPY ./ /build -RUN ./mvnw -V -B -ff -P docker package -q +COPY ./ . +RUN sh ./mvnw -V -B -ff -P docker package -q FROM openjdk:8-jre-slim WORKDIR /app diff --git a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedEnum.java b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedEnum.java index 0dcd5e6e9..959733934 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedEnum.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/model/schema/ChangedEnum.java @@ -13,8 +13,12 @@ public ChangedEnum(List oldValue, List newValue, DiffContext context) { @Override public DiffResult isItemsChanged() { - if (context.isRequest() && getMissing().isEmpty() - || context.isResponse() && getIncreased().isEmpty()) { + + if ( + (context.isRequest() && getMissing().isEmpty() || context.isResponse()) + && newValue.containsAll(oldValue) + ) + { return DiffResult.COMPATIBLE; } return DiffResult.INCOMPATIBLE; diff --git a/core/src/test/java/org/openapitools/openapidiff/core/EnumDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/EnumDiffTest.java new file mode 100644 index 000000000..454626c2a --- /dev/null +++ b/core/src/test/java/org/openapitools/openapidiff/core/EnumDiffTest.java @@ -0,0 +1,21 @@ +package org.openapitools.openapidiff.core; + +import org.junit.jupiter.api.Test; +import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals; +import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiBackwardCompatible; + +class EnumDiffTest { + + private final String OPENAPI_PATH1 = "enum_1.yaml"; + private final String OPENAPI_PATH2 = "enum_2.yaml"; + + @Test + public void testDiffSame() { + assertOpenApiAreEquals(OPENAPI_PATH1, OPENAPI_PATH1); + } + + @Test + void appendedEnumsAreNotBreakingChanges() { + assertOpenApiBackwardCompatible(OPENAPI_PATH1, OPENAPI_PATH2, false); + } +} diff --git a/core/src/test/resources/enum_1.yaml b/core/src/test/resources/enum_1.yaml new file mode 100644 index 000000000..9ba53443d --- /dev/null +++ b/core/src/test/resources/enum_1.yaml @@ -0,0 +1,48 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.' + version: 1.0.0 + title: Swagger Petstore + termsOfService: 'http://swagger.io/terms/' + contact: + email: apiteam@swagger.io + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +paths: + '/pet/{petId}': + get: + tags: + - pet + summary: gets a pet by id + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' +components: + schemas: + Pet: + title: Pet + type: object + properties: + name: + type: string + enum: + - Cat + - Dog + required: + - name diff --git a/core/src/test/resources/enum_2.yaml b/core/src/test/resources/enum_2.yaml new file mode 100644 index 000000000..6b20a3e5e --- /dev/null +++ b/core/src/test/resources/enum_2.yaml @@ -0,0 +1,49 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.' + version: 1.0.0 + title: Swagger Petstore + termsOfService: 'http://swagger.io/terms/' + contact: + email: apiteam@swagger.io + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' +paths: + '/pet/{petId}': + get: + tags: + - pet + summary: gets a pet by id + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' +components: + schemas: + Pet: + title: Pet + type: object + properties: + name: + type: string + enum: + - Cat + - Dog + - Lemon + required: + - name diff --git a/mvnw b/mvnw index fc7efd17d..e1941292c 100755 --- a/mvnw +++ b/mvnw @@ -17,7 +17,6 @@ # specific language governing permissions and limitations # under the License. # ---------------------------------------------------------------------------- - # ---------------------------------------------------------------------------- # Maven2 Start Up Batch script # @@ -33,7 +32,6 @@ # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- - if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -f /etc/mavenrc ] ; then