Skip to content

fix #358 - correction of regex problem + tests + auto formatting #359

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

Merged
merged 3 commits into from
Jun 7, 2022
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 @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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());
}
}
}
92 changes: 92 additions & 0 deletions core/src/test/resources/path_5.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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
92 changes: 92 additions & 0 deletions core/src/test/resources/path_6.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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