Skip to content

Commit 8d825f6

Browse files
author
David DE CARVALHO
committed
fix OpenAPITools#358 - correction of regex problem + tests
1 parent bccb97a commit 8d825f6

File tree

4 files changed

+201
-1
lines changed

4 files changed

+201
-1
lines changed

core/src/main/java/org/openapitools/openapidiff/core/compare/PathsDiff.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.openapitools.openapidiff.core.model.deferred.DeferredChanged;
1616

1717
public class PathsDiff {
18-
private static final String REGEX_PATH = "\\{([^/]+)}";
18+
private static final String REGEX_PATH = "\\{([^/{}]+)}";
1919
private final OpenApiDiff openApiDiff;
2020

2121
public PathsDiff(OpenApiDiff openApiDiff) {

core/src/test/java/org/openapitools/openapidiff/core/PathDiffTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.junit.jupiter.api.Assertions.fail;
56
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
67

78
import org.junit.jupiter.api.Test;
@@ -13,6 +14,8 @@ public class PathDiffTest {
1314
private final String OPENAPI_PATH2 = "path_2.yaml";
1415
private final String OPENAPI_PATH3 = "path_3.yaml";
1516
private final String OPENAPI_PATH4 = "path_4.yaml";
17+
private final String OPENAPI_PATH5 = "path_5.yaml";
18+
private final String OPENAPI_PATH6 = "path_6.yaml";
1619

1720
@Test
1821
public void testEqual() {
@@ -35,4 +38,17 @@ public void testSameTemplateDifferentMethods() {
3538
assertThat(endpoint.getOperation().getOperationId()).isEqualTo("deletePet"));
3639
assertThat(changedOpenApi.isCompatible()).isTrue();
3740
}
41+
42+
@Test
43+
public void testDiffWithSimilarBeginningPaths() {
44+
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_PATH5, OPENAPI_PATH6);
45+
try {
46+
ChangedOpenApi diff =
47+
OpenApiCompare.fromSpecifications(
48+
changedOpenApi.getOldSpecOpenApi(), changedOpenApi.getNewSpecOpenApi());
49+
assertThat(diff.getChangedOperations()).hasSize(4);
50+
} catch (IllegalArgumentException e) {
51+
fail(e.getMessage());
52+
}
53+
}
3854
}

core/src/test/resources/path_5.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: >-
6+
This is a sample server Petstore server. You can find out more about
7+
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
8+
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
9+
`special-key` to test the authorization filters.
10+
version: 1.0.0
11+
title: Swagger Petstore
12+
termsOfService: 'http://swagger.io/terms/'
13+
contact:
14+
15+
license:
16+
name: Apache 2.0
17+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
18+
paths:
19+
/pet/{petId}:
20+
get:
21+
tags:
22+
- pet
23+
summary: gets a pet by id
24+
description: ''
25+
operationId: updatePetWithForm
26+
parameters:
27+
- name: petId
28+
in: path
29+
description: ID of pet that needs to be updated
30+
required: true
31+
schema:
32+
type: integer
33+
responses:
34+
'405':
35+
description: Invalid input
36+
/pet/{petId2}:
37+
post:
38+
tags:
39+
- pet
40+
summary: deletes a pet
41+
description: ''
42+
operationId: deletePet
43+
parameters:
44+
- name: petId2
45+
in: path
46+
description: Pet ID to delete
47+
required: true
48+
schema:
49+
type: integer
50+
responses:
51+
'405':
52+
description: Invalid input
53+
/pet/by_owner-{ownerId}:
54+
get:
55+
tags:
56+
- pet
57+
summary: gets a pet by its owner id
58+
description: ''
59+
operationId: getPetFromOwner
60+
parameters:
61+
- ownerid: ownerId
62+
in: path
63+
description: Owner id of pet that needs to be get
64+
required: true
65+
schema:
66+
type: integer
67+
responses:
68+
'405':
69+
description: Invalid input
70+
/pet/by_owner-{ownerId}_name-{petName}:
71+
get:
72+
tags:
73+
- pet
74+
summary: gets a pet by its owner id and its name
75+
description: ''
76+
operationId: getPetFromOwnerAndPetName
77+
parameters:
78+
- ownerid: ownerId
79+
in: path
80+
description: Owner id of pet that needs to be get
81+
required: true
82+
schema:
83+
type: integer
84+
- name: petName
85+
in: path
86+
description: Name of pet that needs to be get
87+
required: true
88+
schema:
89+
type: string
90+
responses:
91+
'405':
92+
description: Invalid input

core/src/test/resources/path_6.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: >-
6+
This is a sample server Petstore server. You can find out more about
7+
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
8+
#swagger](http://swagger.io/irc/). For this sample, you can use the api key
9+
`special-key` to test the authorization filters.
10+
version: 1.0.0
11+
title: Swagger Petstore
12+
termsOfService: 'http://swagger.io/terms/'
13+
contact:
14+
15+
license:
16+
name: Apache 2.0
17+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
18+
paths:
19+
/pet/{petId}:
20+
get:
21+
tags:
22+
- pet
23+
summary: gets a pet by id
24+
description: ''
25+
operationId: updatePetWithForm
26+
parameters:
27+
- name: petId
28+
in: path
29+
description: ID of pet that needs to be updated
30+
required: true
31+
schema:
32+
type: integer
33+
responses:
34+
'405':
35+
description: Invalid input
36+
/pet/{petId2}:
37+
post:
38+
tags:
39+
- pet
40+
summary: deletes a pet
41+
description: ''
42+
operationId: deletePet
43+
parameters:
44+
- name: petId2
45+
in: path
46+
description: Pet ID to delete
47+
required: true
48+
schema:
49+
type: integer
50+
responses:
51+
'405':
52+
description: Invalid input
53+
/pet/by_owner-{ownerId}:
54+
get:
55+
tags:
56+
- pet
57+
summary: gets a pet by its owner id
58+
description: ''
59+
operationId: getPetFromOwner
60+
parameters:
61+
- ownerid: ownerId
62+
in: path
63+
description: Owner id of pet that needs to be get
64+
required: true
65+
schema:
66+
type: integer
67+
responses:
68+
'405':
69+
description: Invalid input
70+
/pet/by_owner-{ownerId}_name-{petName}:
71+
get:
72+
tags:
73+
- pet
74+
summary: gets a pet by its owner id and its name
75+
description: ''
76+
operationId: getPetFromOwnerAndPetName
77+
parameters:
78+
- ownerid: ownerId
79+
in: path
80+
description: Owner id of pet that needs to be get
81+
required: true
82+
schema:
83+
type: integer
84+
- name: petName
85+
in: path
86+
description: Name of pet that needs to be get
87+
required: true
88+
schema:
89+
type: string
90+
responses:
91+
'405':
92+
description: Invalid input

0 commit comments

Comments
 (0)