Skip to content

Commit 6914784

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

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
@@ -11,9 +11,11 @@
1111

1212
<ItemGroup>
1313
<None Remove="Resource\Swagger\new\enum_as_string.json" />
14-
<None Remove="Resource\Swagger\new\parameter_order_change_global.json" />
14+
<None Remove="Resource\Swagger\new\global_parameter_no_order_change.json" />
15+
<None Remove="Resource\Swagger\new\global_parameter_order_change.json" />
1516
<None Remove="Resource\Swagger\old\enum_as_string.json" />
16-
<None Remove="Resource\Swagger\old\parameter_order_change_global.json" />
17+
<None Remove="Resource\Swagger\old\global_parameter_no_order_change.json" />
18+
<None Remove="Resource\Swagger\old\global_parameter_order_change.json" />
1719
</ItemGroup>
1820

1921
<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" />
@@ -62,7 +67,10 @@
6267
<Content Include="Resource\Swagger\old\added_required_property.json">
6368
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6469
</Content>
65-
<Content Include="Resource\Swagger\old\parameter_order_change_global.json">
70+
<Content Include="Resource\Swagger\old\global_parameter_no_order_change.json">
71+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
72+
</Content>
73+
<Content Include="Resource\Swagger\old\global_parameter_order_change.json">
6674
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6775
</Content>
6876
<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
@@ -903,10 +903,48 @@ 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();
907909
Assert.Equal(2, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
908910
}
909911

912+
[Fact]
913+
public void ChangedGlobalParameterOrder()
914+
{
915+
var messages = CompareSwagger("global_parameter_order_change.json").ToArray();
916+
917+
// Changed order from:
918+
// ( Implicit , Method1 , Client , Method2 )
919+
// to ( Method2 , Implicit , Method1 , Client )
920+
//
921+
// So there are two errors reported:
922+
// - On Method1, as now it is before Method2
923+
// - On Method2, as now it is after Method1
924+
//
925+
// There are no errors for Implicit and Client as their order doesn't matter.
926+
//
927+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
928+
Assert.Equal(2, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
929+
}
930+
931+
[Fact]
932+
public void DidNotChangeGlobalParameterOrder()
933+
{
934+
var messages = CompareSwagger("global_parameter_order_no_change.json").ToArray();
935+
936+
// Changed order from:
937+
// ( Implicit , Method1 , Client , Method2 )
938+
// to ( Method1 , Client , Method2 , Implicit )
939+
//
940+
// So there is no issue with order change:
941+
// The Method1 param still comes before Method2 param, and order
942+
// of Implicit and Client doesn't matter.
943+
//
944+
// Reference: https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-parameter-location
945+
Assert.Equal(0, messages.Where(m => m.Id == ComparisonMessages.ChangedParameterOrder.Id).Count());
946+
}
947+
910948
[Fact]
911949
public void ChangedXmsLongRunningOperation()
912950
{

0 commit comments

Comments
 (0)