diff --git a/core/src/main/java/org/openapitools/openapidiff/core/compare/PathsDiff.java b/core/src/main/java/org/openapitools/openapidiff/core/compare/PathsDiff.java index 1da540f3f..0f501bf99 100644 --- a/core/src/main/java/org/openapitools/openapidiff/core/compare/PathsDiff.java +++ b/core/src/main/java/org/openapitools/openapidiff/core/compare/PathsDiff.java @@ -15,7 +15,7 @@ import org.openapitools.openapidiff.core.model.deferred.DeferredChanged; public class PathsDiff { - private static final String REGEX_PATH = "\\{([^/]+)}"; + private static final String REGEX_PATH = "\\{([^/{}]+)}"; private final OpenApiDiff openApiDiff; public PathsDiff(OpenApiDiff openApiDiff) { diff --git a/core/src/test/java/org/openapitools/openapidiff/core/PathDiffTest.java b/core/src/test/java/org/openapitools/openapidiff/core/PathDiffTest.java index 1c8168c41..a20d20f64 100644 --- a/core/src/test/java/org/openapitools/openapidiff/core/PathDiffTest.java +++ b/core/src/test/java/org/openapitools/openapidiff/core/PathDiffTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals; import org.junit.jupiter.api.Test; @@ -13,6 +14,8 @@ public class PathDiffTest { private final String OPENAPI_PATH2 = "path_2.yaml"; private final String OPENAPI_PATH3 = "path_3.yaml"; private final String OPENAPI_PATH4 = "path_4.yaml"; + private final String OPENAPI_PATH5 = "path_5.yaml"; + private final String OPENAPI_PATH6 = "path_6.yaml"; @Test public void testEqual() { @@ -35,4 +38,17 @@ public void testSameTemplateDifferentMethods() { assertThat(endpoint.getOperation().getOperationId()).isEqualTo("deletePet")); assertThat(changedOpenApi.isCompatible()).isTrue(); } + + @Test + public void testDiffWithSimilarBeginningPaths() { + ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_PATH5, OPENAPI_PATH6); + try { + ChangedOpenApi diff = + OpenApiCompare.fromSpecifications( + changedOpenApi.getOldSpecOpenApi(), changedOpenApi.getNewSpecOpenApi()); + assertThat(diff.getChangedOperations()).hasSize(4); + } catch (IllegalArgumentException e) { + fail(e.getMessage()); + } + } } diff --git a/core/src/test/resources/path_5.yaml b/core/src/test/resources/path_5.yaml new file mode 100644 index 000000000..9e44371c3 --- /dev/null +++ b/core/src/test/resources/path_5.yaml @@ -0,0 +1,92 @@ +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: + '405': + description: Invalid input + /pet/{petId2}: + post: + tags: + - pet + summary: deletes a pet + description: '' + operationId: deletePet + parameters: + - name: petId2 + in: path + description: Pet ID to delete + required: true + schema: + type: integer + responses: + '405': + description: Invalid input + /pet/by_owner-{ownerId}: + get: + tags: + - pet + summary: gets a pet by its owner id + description: '' + operationId: getPetFromOwner + parameters: + - ownerid: ownerId + in: path + description: Owner id of pet that needs to be get + required: true + schema: + type: integer + responses: + '405': + description: Invalid input + /pet/by_owner-{ownerId}_name-{petName}: + get: + tags: + - pet + summary: gets a pet by its owner id and its name + description: '' + operationId: getPetFromOwnerAndPetName + parameters: + - ownerid: ownerId + in: path + description: Owner id of pet that needs to be get + required: true + schema: + type: integer + - name: petName + in: path + description: Name of pet that needs to be get + required: true + schema: + type: string + responses: + '405': + description: Invalid input diff --git a/core/src/test/resources/path_6.yaml b/core/src/test/resources/path_6.yaml new file mode 100644 index 000000000..9e44371c3 --- /dev/null +++ b/core/src/test/resources/path_6.yaml @@ -0,0 +1,92 @@ +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: + '405': + description: Invalid input + /pet/{petId2}: + post: + tags: + - pet + summary: deletes a pet + description: '' + operationId: deletePet + parameters: + - name: petId2 + in: path + description: Pet ID to delete + required: true + schema: + type: integer + responses: + '405': + description: Invalid input + /pet/by_owner-{ownerId}: + get: + tags: + - pet + summary: gets a pet by its owner id + description: '' + operationId: getPetFromOwner + parameters: + - ownerid: ownerId + in: path + description: Owner id of pet that needs to be get + required: true + schema: + type: integer + responses: + '405': + description: Invalid input + /pet/by_owner-{ownerId}_name-{petName}: + get: + tags: + - pet + summary: gets a pet by its owner id and its name + description: '' + operationId: getPetFromOwnerAndPetName + parameters: + - ownerid: ownerId + in: path + description: Owner id of pet that needs to be get + required: true + schema: + type: integer + - name: petName + in: path + description: Name of pet that needs to be get + required: true + schema: + type: string + responses: + '405': + description: Invalid input