Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bc910ec

Browse files
author
Konrad Jamrozik
authoredJun 21, 2024··
Add new rule: 1050 - ParameterLocationHasChanged; Change behavior of ChangedParameterOrder rule with regards to x-ms-parameter-location (#334)
1 parent 8dd40e9 commit bc910ec

22 files changed

+924
-93
lines changed
 

‎docs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@
9696

9797
[1048 - AddedXmsEnum](rules/1048.md)
9898

99-
[1049 - RemovedXmsEnum](rules/1049.md)
99+
[1049 - RemovedXmsEnum](rules/1049.md)
100+
101+
[1050 - ParameterLocationHasChanged](rules/1050.md)

‎docs/rules/1007.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
**Cause**: This is considered a breaking change.
66

7+
**Related rules**
8+
9+
- [1050 - ParameterLocationHasChanged](1050.md)
10+
711
**Change Example**: Parameter `resourceGroupName` is removed in the new version.
812

913
Old specification

‎docs/rules/1042.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
**Cause**: This is considered a breaking change.
66

7+
**Related rules**
8+
9+
- [1050 - ParameterLocationHasChanged](1050.md)
10+
711
**Example**: Parameter order change from `a, b, e` to `a, e, b`.
812

913
Old specification

‎docs/rules/1050.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
### 1050 - ParameterLocationHasChanged
2+
3+
**Description**: Checks whether any parameter's location ([`x-ms-parameter-location`]) is changed from the previous specification.
4+
This is AutoRest-specific rule. Per the example provided in [specifying required parameters and properties],
5+
and per the documentation of [`x-ms-parameter-location`]:
6+
7+
- non-global parameters have implicitly `method` location and this cannot be changed.
8+
- global parameters have implicitly `client` location and this can be changed to `method` via [`x-ms-parameter-location`].
9+
10+
**Cause**: Changing parameter location from `client` to `method` or vice-versa is considered a breaking change.
11+
12+
**Related rules**
13+
14+
- [1007 - RemovedClientParameter](1007.md)
15+
- [1042 - ChangedParameterOrder](1042.md)
16+
17+
**Example**: Parameter `foo` is changed from being non-global parameter to global parameter in the new version,
18+
hence changing its location from `method` to `client`.
19+
20+
Old specification
21+
```json5
22+
{
23+
"swagger": "2.0",
24+
"info": {
25+
"title": "swagger",
26+
"description": "The Azure Management API.",
27+
"version": "2016-12-01",
28+
...
29+
...
30+
"paths": {
31+
"/subscriptions/{subscriptionId}/providers/Microsoft.Contoso/resource1/{a}": {
32+
"get": {
33+
...
34+
...
35+
"parameters": [
36+
{
37+
"name": "foo",
38+
"in": "path",
39+
"type": "string"
40+
}
41+
]
42+
...
43+
...
44+
}
45+
}
46+
...
47+
...
48+
```
49+
50+
New specification
51+
```json5
52+
{
53+
"swagger": "2.0",
54+
"info": {
55+
"title": "swagger",
56+
"description": "The Azure Management API.",
57+
"version": "2016-12-01",
58+
...
59+
...
60+
"paths": {
61+
"/subscriptions/{subscriptionId}/providers/Microsoft.Contoso/resource1/{a}": {
62+
"get": {
63+
...
64+
...
65+
"parameters": [
66+
{
67+
"ref": "#/parameters/foo"
68+
}
69+
]
70+
...
71+
...
72+
}
73+
}
74+
...
75+
...
76+
"parameters": {
77+
"foo": {
78+
"name": "foo",
79+
"in": "path",
80+
"type": "string"
81+
}
82+
}
83+
```
84+
85+
[`x-ms-parameter-location`]: https://github.com/Azure/autorest/blob/765bc784b0cad173d47f931a04724936a6948b4c/docs/extensions/readme.md#x-ms-parameter-location
86+
[specifying required parameters and properties]: https://github.com/Azure/autorest/blob/765bc784b0cad173d47f931a04724936a6948b4c/docs/generate/how-autorest-generates-code-from-openapi.md#specifying-required-parameters-and-properties

‎openapi-diff/src/core/OpenApiDiff.Core/OpenApiDiff.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PropertyGroup>
88
<AssemblyName>OpenApiDiff.Core</AssemblyName>
99
<PackageTags>Microsoft AutoRest</PackageTags>
10-
<LangVersion>7.1</LangVersion>
10+
<LangVersion>7.3</LangVersion>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

‎openapi-diff/src/core/OpenApiDiff/OpenApiDiff.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageProjectUrl>https://github.com/Azure/openapi-diff</PackageProjectUrl>
1616
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1717
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
18-
<LangVersion>7.1</LangVersion>
18+
<LangVersion>7.3</LangVersion>
1919
</PropertyGroup>
2020

2121
<ItemGroup>

‎openapi-diff/src/modeler/AutoRest.Swagger.Tests/AutoRest.Swagger.Tests.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
<PropertyGroup>
77
<TargetFramework>netcoreapp6.0</TargetFramework>
8-
<LangVersion>7.1</LangVersion>
8+
<LangVersion>7.3</LangVersion>
99
</PropertyGroup>
1010

11-
12-
1311
<ItemGroup>
1412
<Content Include="Resource\Swagger\new\added_path.json" />
1513
<Content Include="Resource\Swagger\new\added_readonly_required_property.json" />
@@ -24,9 +22,13 @@
2422
<Content Include="Resource\Swagger\new\operation_check_03.json" />
2523
<Content Include="Resource\Swagger\new\operation_check_04.json" />
2624
<Content Include="Resource\Swagger\new\operation_check_05.json" />
25+
<Content Include="Resource\Swagger\new\global_parameter_order_change.json" />
26+
<Content Include="Resource\Swagger\new\global_parameter_no_order_change.json" />
27+
<Content Include="Resource\Swagger\new\parameter_location_change.json" />
2728
<Content Include="Resource\Swagger\new\param_check_01.json" />
2829
<Content Include="Resource\Swagger\new\removed_definition.json" />
2930
<Content Include="Resource\Swagger\new\removed_operation.json" />
31+
<Content Include="Resource\Swagger\new\removed_parameter.json" />
3032
<Content Include="Resource\Swagger\new\removed_path.json" />
3133
<Content Include="Resource\Swagger\new\required_parameter.json" />
3234
<Content Include="Resource\Swagger\new\response_check_01.json" />
@@ -50,6 +52,10 @@
5052
<Content Include="Resource\Swagger\new\version_check_04.json" />
5153
<Content Include="Resource\Swagger\old\added_readonly_required_property.json" />
5254
<Content Include="Resource\Swagger\old\added_required_property.json" />
55+
<Content Include="Resource\Swagger\old\global_parameter_no_order_change.json" />
56+
<Content Include="Resource\Swagger\old\global_parameter_order_change.json" />
57+
<Content Include="Resource\Swagger\old\parameter_location_change.json" />
58+
<Content Include="Resource\Swagger\old\removed_parameter.json" />
5359
<Content Include="Resource\Swagger\old\recursive_model.json" />
5460
<Content Include="Resource\Swagger\old\changed_operation_id.json" />
5561
<Content Include="Resource\Swagger\old\added_path.json" />
@@ -94,4 +100,4 @@
94100
</ItemGroup>
95101

96102
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
97-
</Project>
103+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "global_parameter_no_order_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"$ref": "#/parameters/MethodLocationParam1"
20+
},
21+
{
22+
"$ref": "#/parameters/ClientLocationParam"
23+
},
24+
{
25+
"$ref": "#/parameters/MethodLocationParam2"
26+
},
27+
{
28+
"$ref": "#/parameters/ImplicitLocationParam"
29+
}
30+
]
31+
}
32+
}
33+
},
34+
"parameters": {
35+
"ImplicitLocationParam": {
36+
"name": "implicit_location_param",
37+
"in": "query",
38+
"required": true,
39+
"type": "string",
40+
"description": "Implicit x-ms-parameter-location param"
41+
},
42+
"ClientLocationParam": {
43+
"name": "current_location_param",
44+
"in": "query",
45+
"required": true,
46+
"type": "string",
47+
"description": "client x-ms-parameter-location param",
48+
"x-ms-parameter-location": "client"
49+
},
50+
"MethodLocationParam1": {
51+
"name": "method_location_param_1",
52+
"in": "query",
53+
"required": true,
54+
"type": "string",
55+
"description": "method x-ms-parameter-location param 1",
56+
"x-ms-parameter-location": "method"
57+
},
58+
"MethodLocationParam2": {
59+
"name": "method_location_param_2",
60+
"in": "query",
61+
"required": true,
62+
"type": "string",
63+
"description": "method x-ms-parameter-location param 2",
64+
"x-ms-parameter-location": "method"
65+
}
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "global_parameter_order_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"$ref": "#/parameters/MethodLocationParam2"
20+
},
21+
{
22+
"$ref": "#/parameters/ImplicitLocationParam"
23+
},
24+
{
25+
"$ref": "#/parameters/MethodLocationParam1"
26+
},
27+
{
28+
"$ref": "#/parameters/ClientLocationParam"
29+
}
30+
]
31+
}
32+
}
33+
},
34+
"parameters": {
35+
"ImplicitLocationParam": {
36+
"name": "implicit_location_param",
37+
"in": "query",
38+
"required": true,
39+
"type": "string",
40+
"description": "Implicit x-ms-parameter-location param"
41+
},
42+
"ClientLocationParam": {
43+
"name": "current_location_param",
44+
"in": "query",
45+
"required": true,
46+
"type": "string",
47+
"description": "client x-ms-parameter-location param",
48+
"x-ms-parameter-location": "client"
49+
},
50+
"MethodLocationParam1": {
51+
"name": "method_location_param_1",
52+
"in": "query",
53+
"required": true,
54+
"type": "string",
55+
"description": "method x-ms-parameter-location param 1",
56+
"x-ms-parameter-location": "method"
57+
},
58+
"MethodLocationParam2": {
59+
"name": "method_location_param_2",
60+
"in": "query",
61+
"required": true,
62+
"type": "string",
63+
"description": "method x-ms-parameter-location param 2",
64+
"x-ms-parameter-location": "method"
65+
}
66+
}
67+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "parameter_location_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"$ref": "#/parameters/ImplicitFromMethodToClient"
20+
},
21+
{
22+
"$ref": "#/parameters/GlobalFromClientToMethodParam"
23+
},
24+
{
25+
"$ref": "#/parameters/GlobalFromClientToClientParam"
26+
},
27+
{
28+
"name": "from_implicit_global_client_to_implicit_method",
29+
"in": "query",
30+
"type": "string"
31+
}
32+
]
33+
}
34+
}
35+
},
36+
"parameters": {
37+
"ImplicitFromMethodToClient": {
38+
"name": "implicit_from_method_to_client",
39+
"in": "query",
40+
"type": "string"
41+
},
42+
"GlobalFromClientToMethodParam": {
43+
"name": "global_from_client_to_method",
44+
"in": "query",
45+
"type": "string",
46+
"x-ms-parameter-location": "method"
47+
},
48+
"GlobalFromClientToClientParam": {
49+
"name": "global_from_client_to_client",
50+
"in": "query",
51+
"type": "string",
52+
"x-ms-parameter-location": "client"
53+
}
54+
}
55+
}

‎openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/new/parameter_order_change.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"swagger": 2.0,
33
"info": {
4-
"title": "required_parameter",
4+
"title": "parameter_order_change",
55
"version": "1.0"
66
},
77
"host": "localhost:8000",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "removed_parameter",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters/{a}": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": []
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "global_parameter_no_order_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"$ref": "#/parameters/ImplicitLocationParam"
20+
},
21+
{
22+
"$ref": "#/parameters/MethodLocationParam1"
23+
},
24+
{
25+
"$ref": "#/parameters/ClientLocationParam"
26+
},
27+
{
28+
"$ref": "#/parameters/MethodLocationParam2"
29+
}
30+
]
31+
}
32+
}
33+
},
34+
"parameters": {
35+
"ImplicitLocationParam": {
36+
"name": "implicit_location_param",
37+
"in": "query",
38+
"required": true,
39+
"type": "string",
40+
"description": "Implicit x-ms-parameter-location param"
41+
},
42+
"ClientLocationParam": {
43+
"name": "current_location_param",
44+
"in": "query",
45+
"required": true,
46+
"type": "string",
47+
"description": "client x-ms-parameter-location param",
48+
"x-ms-parameter-location": "client"
49+
},
50+
"MethodLocationParam1": {
51+
"name": "method_location_param_1",
52+
"in": "query",
53+
"required": true,
54+
"type": "string",
55+
"description": "method x-ms-parameter-location param 1",
56+
"x-ms-parameter-location": "method"
57+
},
58+
"MethodLocationParam2": {
59+
"name": "method_location_param_2",
60+
"in": "query",
61+
"required": true,
62+
"type": "string",
63+
"description": "method x-ms-parameter-location param 2",
64+
"x-ms-parameter-location": "method"
65+
}
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "global_parameter_order_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"$ref": "#/parameters/ImplicitLocationParam"
20+
},
21+
{
22+
"$ref": "#/parameters/MethodLocationParam1"
23+
},
24+
{
25+
"$ref": "#/parameters/ClientLocationParam"
26+
},
27+
{
28+
"$ref": "#/parameters/MethodLocationParam2"
29+
}
30+
]
31+
}
32+
}
33+
},
34+
"parameters": {
35+
"ImplicitLocationParam": {
36+
"name": "implicit_location_param",
37+
"in": "query",
38+
"required": true,
39+
"type": "string",
40+
"description": "Implicit x-ms-parameter-location param"
41+
},
42+
"ClientLocationParam": {
43+
"name": "current_location_param",
44+
"in": "query",
45+
"required": true,
46+
"type": "string",
47+
"description": "client x-ms-parameter-location param",
48+
"x-ms-parameter-location": "client"
49+
},
50+
"MethodLocationParam1": {
51+
"name": "method_location_param_1",
52+
"in": "query",
53+
"required": true,
54+
"type": "string",
55+
"description": "method x-ms-parameter-location param 1",
56+
"x-ms-parameter-location": "method"
57+
},
58+
"MethodLocationParam2": {
59+
"name": "method_location_param_2",
60+
"in": "query",
61+
"required": true,
62+
"type": "string",
63+
"description": "method x-ms-parameter-location param 2",
64+
"x-ms-parameter-location": "method"
65+
}
66+
}
67+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "parameter_location_change",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"name": "implicit_from_method_to_client",
20+
"in": "query",
21+
"type": "string"
22+
},
23+
{
24+
"$ref": "#/parameters/GlobalFromClientToMethodParam"
25+
},
26+
{
27+
"$ref": "#/parameters/GlobalFromClientToClientParam"
28+
},
29+
{
30+
"$ref": "#/parameters/FromImplicitGlobalClientToImplicitMethod"
31+
}
32+
]
33+
}
34+
}
35+
},
36+
"parameters": {
37+
"GlobalFromClientToMethodParam": {
38+
"name": "global_from_client_to_method",
39+
"in": "query",
40+
"type": "string"
41+
},
42+
"GlobalFromClientToClientParam": {
43+
"name": "global_from_client_to_client",
44+
"in": "query",
45+
"type": "string"
46+
},
47+
"FromImplicitGlobalClientToImplicitMethod": {
48+
"name": "from_implicit_global_client_to_implicit_method",
49+
"in": "query",
50+
"type": "string"
51+
}
52+
}
53+
}

‎openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/old/parameter_order_change.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"swagger": 2.0,
33
"info": {
4-
"title": "required_parameter",
4+
"title": "parameter_order_change",
55
"version": "1.0"
66
},
77
"host": "localhost:8000",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"swagger": 2.0,
3+
"info": {
4+
"title": "removed_parameter",
5+
"version": "1.0"
6+
},
7+
"host": "localhost:8000",
8+
"schemes": [ "http", "https" ],
9+
"paths": {
10+
"/api/Parameters/{a}": {
11+
"get": {
12+
"tag": [ "Parameters" ],
13+
"operationId": "Parameters_Get",
14+
"produces": [
15+
"text/plain"
16+
],
17+
"parameters": [
18+
{
19+
"name": "path_param_req",
20+
"in": "path",
21+
"required": true,
22+
"type": "string"
23+
},
24+
{
25+
"name": "query_param_req",
26+
"in": "query",
27+
"required": true,
28+
"type": "string"
29+
},
30+
{
31+
"name": "body_param_req",
32+
"in": "body",
33+
"required": true,
34+
"type": "string"
35+
},
36+
{
37+
"name": "path_param",
38+
"in": "path",
39+
"type": "string"
40+
},
41+
{
42+
"name": "query_param",
43+
"in": "query",
44+
"type": "string"
45+
},
46+
{
47+
"name": "body_param",
48+
"in": "body",
49+
"type": "string"
50+
},
51+
]
52+
}
53+
}
54+
}
55+
}

‎openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,58 @@ public void XmsEnumModelAsString()
903903
[Fact]
904904
public void ChangedParameterOrder()
905905
{
906+
// Reference:
907+
// https://github.com/Azure/autorest/blob/main/docs/generate/how-autorest-generates-code-from-openapi.md#specifying-required-parameters-and-properties
906908
var messages = CompareSwagger("parameter_order_change.json").ToArray();
909+
ComparisonMessage[] paramOrderChangedMessages =
910+
messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).ToArray();
911+
Assert.All(paramOrderChangedMessages, message => Assert.Equal(Category.Error, message.Severity));
912+
Assert.Equal(2, paramOrderChangedMessages.Length);
913+
Assert.Equal(
914+
"The order of parameter with Name: 'd', In: 'Query', was changed. Expected param at index '2' but instead found it at index '3'.",
915+
paramOrderChangedMessages[0].Message);
916+
Assert.Equal(
917+
"The order of parameter with Name: 'e', In: 'Query', was changed. Expected param at index '3' but instead found it at index '2'.",
918+
paramOrderChangedMessages[1].Message);
919+
920+
}
921+
922+
[Fact]
923+
public void ChangedGlobalParameterOrder()
924+
{
925+
var messages = CompareSwagger("global_parameter_order_change.json").ToArray();
926+
927+
// Changed order from:
928+
// ( Implicit , Method1 , Client , Method2 )
929+
// to ( Method2 , Implicit , Method1 , Client )
930+
//
931+
// So there are two errors reported:
932+
// - On Method1, as now it is before Method2
933+
// - On Method2, as now it is after Method1
934+
//
935+
// There are no errors for Implicit and Client as their order doesn't matter.
936+
//
937+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
907938
Assert.Equal(2, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
908939
}
909940

941+
[Fact]
942+
public void DidNotChangeGlobalParameterOrder()
943+
{
944+
var messages = CompareSwagger("global_parameter_no_order_change.json").ToArray();
945+
946+
// Changed order from:
947+
// ( Implicit , Method1 , Client , Method2 )
948+
// to ( Method1 , Client , Method2 , Implicit )
949+
//
950+
// So there is no issue with order change:
951+
// The Method1 param still comes before Method2 param, and order
952+
// of Implicit and Client doesn't matter.
953+
//
954+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
955+
Assert.Equal(0, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
956+
}
957+
910958
[Fact]
911959
public void ChangedXmsLongRunningOperation()
912960
{
@@ -954,5 +1002,57 @@ public void ReferenceChanged()
9541002
Assert.Single(redirected);
9551003
Assert.Equal("new/xms_client_name_changed.json#/paths/~1api~1Parameters/post/parameters/0/schema", redirected[0].NewJsonRef);
9561004
}
1005+
1006+
[Fact]
1007+
public void ParameterLocationChanged()
1008+
{
1009+
ComparisonMessage[] messages = CompareSwagger("parameter_location_change.json").ToArray();
1010+
1011+
// We assert there are no ComparisonMessages.ChangedParameterOrder breaking changes because
1012+
// the compared swaggers do not reorder any parameters.
1013+
Assert.Empty(messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id));
1014+
1015+
ComparisonMessage[] locationChangedMessages = messages.Where(m => m.Id == ComparisonMessages.ParameterLocationHasChanged.Id).ToArray();
1016+
Assert.Equal(3, locationChangedMessages.Length);
1017+
Assert.All(locationChangedMessages, message => Assert.Equal(Category.Error, message.Severity));
1018+
Assert.Equal(
1019+
"Parameter location has changed. Name: 'implicit_from_method_to_client'. In: 'Query'. Old location is method: 'True'. New location is method: 'False'.",
1020+
locationChangedMessages[0].Message);
1021+
Assert.Equal(
1022+
"Parameter location has changed. Name: 'global_from_client_to_method'. In: 'Query'. Old location is method: 'False'. New location is method: 'True'.",
1023+
locationChangedMessages[1].Message);
1024+
Assert.Equal(
1025+
"Parameter location has changed. Name: 'from_implicit_global_client_to_implicit_method'. In: 'Query'. Old location is method: 'False'. New location is method: 'True'.",
1026+
locationChangedMessages[2].Message);
1027+
}
1028+
1029+
[Fact]
1030+
public void ParameterRemoved()
1031+
{
1032+
ComparisonMessage[] messages = CompareSwagger("removed_parameter.json")
1033+
.Where(msg => msg.Severity == Category.Error).ToArray();
1034+
1035+
ComparisonMessage[] removedReqParamMessages = messages.Where(m => m.Id == ComparisonMessages.RemovedRequiredParameter.Id).ToArray();
1036+
ComparisonMessage[] removedOptParamMessages = messages.Where(m => m.Id == ComparisonMessages.RemovedOptionalParameter.Id).ToArray();
1037+
1038+
Assert.Equal(6, messages.Length);
1039+
Assert.Equal(4, removedReqParamMessages.Length);
1040+
Assert.Equal(2, removedOptParamMessages.Length);
1041+
1042+
string[] reqParamNames = { "path_param", "path_param_req", "query_param_req", "body_param_req" };
1043+
string[] optParamNames = { "body_param", "query_param" };
1044+
1045+
string[] reqParamMessageStrings = removedReqParamMessages.Select(msg => msg.Message).ToArray();
1046+
string[] optParamMessageStrings = removedOptParamMessages.Select(msg => msg.Message).ToArray();
1047+
1048+
foreach (var reqParamName in reqParamNames)
1049+
{
1050+
Assert.True(reqParamMessageStrings.Any(str => str.Contains(reqParamName)));
1051+
}
1052+
foreach (var optParamName in optParamNames)
1053+
{
1054+
Assert.True(optParamMessageStrings.Any(str => str.Contains(optParamName)));
1055+
}
1056+
}
9571057
}
9581058
}

‎openapi-diff/src/modeler/AutoRest.Swagger/AutoRest.Swagger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PropertyGroup>
88
<AssemblyName>AutoRest.Swagger</AssemblyName>
99
<PackageTags>Microsoft AutoRest Generator Extensions</PackageTags>
10-
<LangVersion>7.1</LangVersion>
10+
<LangVersion>7.3</LangVersion>
1111
</PropertyGroup>
1212
<ItemGroup>
1313
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />

‎openapi-diff/src/modeler/AutoRest.Swagger/ComparisonMessages.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static class ComparisonMessages
110110
{
111111
Id = 1042,
112112
Code = nameof(ComparisonMessages.ChangedParameterOrder),
113-
Message = "The order of parameter '{0}' was changed. ",
113+
Message = "The order of parameter with Name: '{0}', In: '{1}', was changed. Expected param at index '{2}' but instead found it at index '{3}'.",
114114
Type = MessageType.Update
115115
};
116116

@@ -392,5 +392,12 @@ public static class ComparisonMessages
392392
Message = "The new version is missing a 'x-ms-enum' found in the old version.",
393393
Type = MessageType.Removal
394394
};
395+
public static MessageTemplate ParameterLocationHasChanged = new MessageTemplate
396+
{
397+
Id = 1050,
398+
Code = nameof(ComparisonMessages.ParameterLocationHasChanged),
399+
Message = "Parameter location has changed. Name: '{0}'. In: '{1}'. Old location is method: '{2}'. New location is method: '{3}'.",
400+
Type = MessageType.Update
401+
};
395402
}
396403
}

‎openapi-diff/src/modeler/AutoRest.Swagger/Model/Operation.cs

Lines changed: 251 additions & 81 deletions
Large diffs are not rendered by default.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/oad",
3-
"version": "0.10.10",
3+
"version": "0.10.11",
44
"author": {
55
"name": "Microsoft Corporation",
66
"email": "azsdkteam@microsoft.com",

0 commit comments

Comments
 (0)
Please sign in to comment.