Skip to content

Commit 5649672

Browse files
DrSatyrAliaksandr Pinchuk
and
Aliaksandr Pinchuk
authored
Add support for distinguishing equivalent paths by parameter format in overloaded parameters (#661)
* Add support for distinguishing equivalent paths by parameter format in overloaded parameters * Fix typos in PathsDiff.java * Add test case for complex path parameter with dot while handling overloaded parameters --------- Co-authored-by: Aliaksandr Pinchuk <[email protected]>
1 parent 6e07252 commit 5649672

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ private static boolean methodsAndParametersIntersect(PathItem a, PathItem b) {
125125
}
126126

127127
/**
128+
* Checks if provided parameter pairs are equal by type and format
129+
*
128130
* @param left parameters from the first compared method
129131
* @param right parameters from the second compared method
130132
* @return <code>true</code> in case each parameter pair is of the same type; <code>false</code>
@@ -134,9 +136,21 @@ private static boolean parametersIntersect(List<Parameter> left, List<Parameter>
134136
int parametersSize = left.size();
135137
long intersectedParameters =
136138
IntStream.range(0, left.size())
137-
.filter(
138-
i -> left.get(i).getSchema().getType().equals(right.get(i).getSchema().getType()))
139+
.filter(i -> parametersTypeEquals(left.get(i), right.get(i)))
139140
.count();
140141
return parametersSize == intersectedParameters;
141142
}
143+
144+
/**
145+
* Checks if provided parameter pair is equal by type and format
146+
*
147+
* @param left parameter from the first compared method
148+
* @param right parameter from the second compared method
149+
* @return <code>true</code> in case parameter pair is of the same type; <code>false</code>
150+
* otherwise
151+
*/
152+
private static boolean parametersTypeEquals(Parameter left, Parameter right) {
153+
return Objects.equals(left.getSchema().getType(), right.getSchema().getType())
154+
&& Objects.equals(left.getSchema().getFormat(), right.getSchema().getFormat());
155+
}
142156
}

core/src/test/resources/parameters_overloading.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ info:
33
title: Projects API
44
version: 1.0.0
55
paths:
6+
/projects/{key}:
7+
get:
8+
parameters:
9+
- in: path
10+
name: key
11+
required: true
12+
schema:
13+
type: string
14+
responses:
15+
'200':
16+
description: 'Success'
17+
content:
18+
application/json:
19+
schema:
20+
$ref: '#/components/schemas/SampleResponse'
621
/projects/{id}:
722
get:
823
parameters:
@@ -35,6 +50,26 @@ paths:
3550
application/json:
3651
schema:
3752
$ref: '#/components/schemas/SampleResponse'
53+
/projects/{id}.{idPostfix}:
54+
get:
55+
parameters:
56+
- in: path
57+
name: id
58+
required: true
59+
schema:
60+
type: string
61+
- in: path
62+
name: idPostfix
63+
required: true
64+
schema:
65+
type: string
66+
responses:
67+
'200':
68+
description: 'Success'
69+
content:
70+
application/json:
71+
schema:
72+
$ref: '#/components/schemas/SampleResponse'
3873
components:
3974
schemas:
4075
SampleResponse:

0 commit comments

Comments
 (0)