Skip to content

Commit fe0aeaa

Browse files
author
Konrad Jamrozik
committed
add tests for desired param order change behavior
1 parent 5651050 commit fe0aeaa

6 files changed

+186
-6
lines changed

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

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

1111
<ItemGroup>
1212
<None Remove="Resource\Swagger\new\enum_as_string.json" />
13-
<None Remove="Resource\Swagger\new\parameter_order_change_global.json" />
13+
<None Remove="Resource\Swagger\new\global_parameter_no_order_change.json" />
14+
<None Remove="Resource\Swagger\new\global_parameter_order_change.json" />
1415
<None Remove="Resource\Swagger\old\enum_as_string.json" />
15-
<None Remove="Resource\Swagger\old\parameter_order_change_global.json" />
16+
<None Remove="Resource\Swagger\old\global_parameter_no_order_change.json" />
17+
<None Remove="Resource\Swagger\old\global_parameter_order_change.json" />
1618
</ItemGroup>
1719

1820
<ItemGroup>
@@ -23,14 +25,17 @@
2325
<Content Include="Resource\Swagger\new\changed_operation_id.json" />
2426
<Content Include="Resource\Swagger\new\enum_as_string.json" />
2527
<Content Include="Resource\Swagger\new\enum_values_changed.json" />
28+
<Content Include="Resource\Swagger\new\global_parameter_no_order_change.json">
29+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
30+
</Content>
2631
<Content Include="Resource\Swagger\new\misc_checks_01.json" />
2732
<Content Include="Resource\Swagger\new\misc_checks_02.json" />
2833
<Content Include="Resource\Swagger\new\operation_check_01.json" />
2934
<Content Include="Resource\Swagger\new\operation_check_02.json" />
3035
<Content Include="Resource\Swagger\new\operation_check_03.json" />
3136
<Content Include="Resource\Swagger\new\operation_check_04.json" />
3237
<Content Include="Resource\Swagger\new\operation_check_05.json" />
33-
<Content Include="Resource\Swagger\new\parameter_order_change_global.json">
38+
<Content Include="Resource\Swagger\new\global_parameter_order_change.json">
3439
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3540
</Content>
3641
<Content Include="Resource\Swagger\new\param_check_01.json" />
@@ -60,7 +65,10 @@
6065
<Content Include="Resource\Swagger\old\added_required_property.json">
6166
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6267
</Content>
63-
<Content Include="Resource\Swagger\old\parameter_order_change_global.json">
68+
<Content Include="Resource\Swagger\old\global_parameter_no_order_change.json">
69+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
70+
</Content>
71+
<Content Include="Resource\Swagger\old\global_parameter_order_change.json">
6472
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6573
</Content>
6674
<Content Include="Resource\Swagger\old\recursive_model.json" />
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"$ref": "#/parameters/MethodLocationParam1"
2020
},
2121
{
22-
"$ref": "#/parameters/ImplicitLocationParam"
22+
"$ref": "#/parameters/ClientLocationParam"
2323
},
2424
{
2525
"$ref": "#/parameters/MethodLocationParam2"
2626
},
2727
{
28-
"$ref": "#/parameters/ClientLocationParam"
28+
"$ref": "#/parameters/ImplicitLocationParam"
2929
}
3030
]
3131
}
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": "required_parameter",
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: 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": "required_parameter",
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+
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,48 @@ public void XmsEnumModelAsString()
888888
[Fact]
889889
public void ChangedParameterOrder()
890890
{
891+
// Reference:
892+
// https://github.com/Azure/autorest/blob/main/docs/generate/how-autorest-generates-code-from-openapi.md#specifying-required-parameters-and-properties
891893
var messages = CompareSwagger("parameter_order_change.json").ToArray();
892894
Assert.Equal(2, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
893895
}
894896

897+
[Fact]
898+
public void ChangedGlobalParameterOrder()
899+
{
900+
var messages = CompareSwagger("global_parameter_order_change.json").ToArray();
901+
902+
// Changed order from:
903+
// ( Implicit , Method1 , Client , Method2 )
904+
// to ( Method2 , Implicit , Method1 , Client )
905+
//
906+
// So there are two errors reported:
907+
// - On Method1, as now it is before Method2
908+
// - On Method2, as now it is after Method1
909+
//
910+
// There are no errors for Implicit and Client as their order doesn't matter.
911+
//
912+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
913+
Assert.Equal(2, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
914+
}
915+
916+
[Fact]
917+
public void DidNotChangeGlobalParameterOrder()
918+
{
919+
var messages = CompareSwagger("global_parameter_order_no_change.json").ToArray();
920+
921+
// Changed order from:
922+
// ( Implicit , Method1 , Client , Method2 )
923+
// to ( Method1 , Client , Method2 , Implicit )
924+
//
925+
// So there is no issue with order change:
926+
// The Method1 param still comes before Method2 param, and order
927+
// of Implicit and Client doesn't matter.
928+
//
929+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
930+
Assert.Equal(0, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
931+
}
932+
895933
[Fact]
896934
public void ChangedXmsLongRunningOperation()
897935
{

0 commit comments

Comments
 (0)