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

fix: allow enums to be appended #304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public ChangedEnum(List<T> oldValue, List<T> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
48 changes: 48 additions & 0 deletions core/src/test/resources/enum_1.yaml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions core/src/test/resources/enum_2.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
Expand All @@ -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
Expand Down