Skip to content

Add new rule: 1050 - ParameterLocationHasChanged; Change behavior of ChangedParameterOrder rule with regards to x-ms-parameter-location #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@

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

[1049 - RemovedXmsEnum](rules/1049.md)
[1049 - RemovedXmsEnum](rules/1049.md)

[1050 - ParameterLocationHasChanged](rules/1050.md)
4 changes: 4 additions & 0 deletions docs/rules/1007.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

**Related rules**

- [1050 - ParameterLocationHasChanged](1050.md)

**Change Example**: Parameter `resourceGroupName` is removed in the new version.

Old specification
Expand Down
4 changes: 4 additions & 0 deletions docs/rules/1042.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

**Related rules**

- [1050 - ParameterLocationHasChanged](1050.md)

**Example**: Parameter order change from `a, b, e` to `a, e, b`.

Old specification
Expand Down
86 changes: 86 additions & 0 deletions docs/rules/1050.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
### 1050 - ParameterLocationHasChanged

**Description**: Checks whether any parameter's location ([`x-ms-parameter-location`]) is changed from the previous specification.
This is AutoRest-specific rule. Per the example provided in [specifying required parameters and properties],
and per the documentation of [`x-ms-parameter-location`]:

- non-global parameters have implicitly `method` location and this cannot be changed.
- global parameters have implicitly `client` location and this can be changed to `method` via [`x-ms-parameter-location`].

**Cause**: Changing parameter location from `client` to `method` or vice-versa is considered a breaking change.

**Related rules**

- [1007 - RemovedClientParameter](1007.md)
- [1042 - ChangedParameterOrder](1042.md)

**Example**: Parameter `foo` is changed from being non-global parameter to global parameter in the new version,
hence changing its location from `method` to `client`.

Old specification
```json5
{
"swagger": "2.0",
"info": {
"title": "swagger",
"description": "The Azure Management API.",
"version": "2016-12-01",
...
...
"paths": {
"/subscriptions/{subscriptionId}/providers/Microsoft.Contoso/resource1/{a}": {
"get": {
...
...
"parameters": [
{
"name": "foo",
"in": "path",
"type": "string"
}
]
...
...
}
}
...
...
```

New specification
```json5
{
"swagger": "2.0",
"info": {
"title": "swagger",
"description": "The Azure Management API.",
"version": "2016-12-01",
...
...
"paths": {
"/subscriptions/{subscriptionId}/providers/Microsoft.Contoso/resource1/{a}": {
"get": {
...
...
"parameters": [
{
"ref": "#/parameters/foo"
}
]
...
...
}
}
...
...
"parameters": {
"foo": {
"name": "foo",
"in": "path",
"type": "string"
}
}
```

[`x-ms-parameter-location`]: https://github.com/Azure/autorest/blob/765bc784b0cad173d47f931a04724936a6948b4c/docs/extensions/readme.md#x-ms-parameter-location
[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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PropertyGroup>
<AssemblyName>OpenApiDiff.Core</AssemblyName>
<PackageTags>Microsoft AutoRest</PackageTags>
<LangVersion>7.1</LangVersion>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion openapi-diff/src/core/OpenApiDiff/OpenApiDiff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://github.com/Azure/openapi-diff</PackageProjectUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<LangVersion>7.1</LangVersion>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

<PropertyGroup>
<TargetFramework>netcoreapp6.0</TargetFramework>
<LangVersion>7.1</LangVersion>
<LangVersion>7.3</LangVersion>
</PropertyGroup>



<ItemGroup>
<Content Include="Resource\Swagger\new\added_path.json" />
<Content Include="Resource\Swagger\new\added_readonly_required_property.json" />
Expand All @@ -24,9 +22,13 @@
<Content Include="Resource\Swagger\new\operation_check_03.json" />
<Content Include="Resource\Swagger\new\operation_check_04.json" />
<Content Include="Resource\Swagger\new\operation_check_05.json" />
<Content Include="Resource\Swagger\new\global_parameter_order_change.json" />
<Content Include="Resource\Swagger\new\global_parameter_no_order_change.json" />
<Content Include="Resource\Swagger\new\parameter_location_change.json" />
<Content Include="Resource\Swagger\new\param_check_01.json" />
<Content Include="Resource\Swagger\new\removed_definition.json" />
<Content Include="Resource\Swagger\new\removed_operation.json" />
<Content Include="Resource\Swagger\new\removed_parameter.json" />
<Content Include="Resource\Swagger\new\removed_path.json" />
<Content Include="Resource\Swagger\new\required_parameter.json" />
<Content Include="Resource\Swagger\new\response_check_01.json" />
Expand All @@ -50,6 +52,10 @@
<Content Include="Resource\Swagger\new\version_check_04.json" />
<Content Include="Resource\Swagger\old\added_readonly_required_property.json" />
<Content Include="Resource\Swagger\old\added_required_property.json" />
<Content Include="Resource\Swagger\old\global_parameter_no_order_change.json" />
<Content Include="Resource\Swagger\old\global_parameter_order_change.json" />
<Content Include="Resource\Swagger\old\parameter_location_change.json" />
<Content Include="Resource\Swagger\old\removed_parameter.json" />
<Content Include="Resource\Swagger\old\recursive_model.json" />
<Content Include="Resource\Swagger\old\changed_operation_id.json" />
<Content Include="Resource\Swagger\old\added_path.json" />
Expand Down Expand Up @@ -94,4 +100,4 @@
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"swagger": 2.0,
"info": {
"title": "global_parameter_no_order_change",
"version": "1.0"
},
"host": "localhost:8000",
"schemes": [ "http", "https" ],
"paths": {
"/api/Parameters": {
"get": {
"tag": [ "Parameters" ],
"operationId": "Parameters_Get",
"produces": [
"text/plain"
],
"parameters": [
{
"$ref": "#/parameters/MethodLocationParam1"
},
{
"$ref": "#/parameters/ClientLocationParam"
},
{
"$ref": "#/parameters/MethodLocationParam2"
},
{
"$ref": "#/parameters/ImplicitLocationParam"
}
]
}
}
},
"parameters": {
"ImplicitLocationParam": {
"name": "implicit_location_param",
"in": "query",
"required": true,
"type": "string",
"description": "Implicit x-ms-parameter-location param"
},
"ClientLocationParam": {
"name": "current_location_param",
"in": "query",
"required": true,
"type": "string",
"description": "client x-ms-parameter-location param",
"x-ms-parameter-location": "client"
},
"MethodLocationParam1": {
"name": "method_location_param_1",
"in": "query",
"required": true,
"type": "string",
"description": "method x-ms-parameter-location param 1",
"x-ms-parameter-location": "method"
},
"MethodLocationParam2": {
"name": "method_location_param_2",
"in": "query",
"required": true,
"type": "string",
"description": "method x-ms-parameter-location param 2",
"x-ms-parameter-location": "method"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"swagger": 2.0,
"info": {
"title": "global_parameter_order_change",
"version": "1.0"
},
"host": "localhost:8000",
"schemes": [ "http", "https" ],
"paths": {
"/api/Parameters": {
"get": {
"tag": [ "Parameters" ],
"operationId": "Parameters_Get",
"produces": [
"text/plain"
],
"parameters": [
{
"$ref": "#/parameters/MethodLocationParam2"
},
{
"$ref": "#/parameters/ImplicitLocationParam"
},
{
"$ref": "#/parameters/MethodLocationParam1"
},
{
"$ref": "#/parameters/ClientLocationParam"
}
]
}
}
},
"parameters": {
"ImplicitLocationParam": {
"name": "implicit_location_param",
"in": "query",
"required": true,
"type": "string",
"description": "Implicit x-ms-parameter-location param"
},
"ClientLocationParam": {
"name": "current_location_param",
"in": "query",
"required": true,
"type": "string",
"description": "client x-ms-parameter-location param",
"x-ms-parameter-location": "client"
},
"MethodLocationParam1": {
"name": "method_location_param_1",
"in": "query",
"required": true,
"type": "string",
"description": "method x-ms-parameter-location param 1",
"x-ms-parameter-location": "method"
},
"MethodLocationParam2": {
"name": "method_location_param_2",
"in": "query",
"required": true,
"type": "string",
"description": "method x-ms-parameter-location param 2",
"x-ms-parameter-location": "method"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"swagger": 2.0,
"info": {
"title": "parameter_location_change",
"version": "1.0"
},
"host": "localhost:8000",
"schemes": [ "http", "https" ],
"paths": {
"/api/Parameters": {
"get": {
"tag": [ "Parameters" ],
"operationId": "Parameters_Get",
"produces": [
"text/plain"
],
"parameters": [
{
"$ref": "#/parameters/ImplicitFromMethodToClient"
},
{
"$ref": "#/parameters/GlobalFromClientToMethodParam"
},
{
"$ref": "#/parameters/GlobalFromClientToClientParam"
},
{
"name": "from_implicit_global_client_to_implicit_method",
"in": "query",
"type": "string"
}
]
}
}
},
"parameters": {
"ImplicitFromMethodToClient": {
"name": "implicit_from_method_to_client",
"in": "query",
"type": "string"
},
"GlobalFromClientToMethodParam": {
"name": "global_from_client_to_method",
"in": "query",
"type": "string",
"x-ms-parameter-location": "method"
},
"GlobalFromClientToClientParam": {
"name": "global_from_client_to_client",
"in": "query",
"type": "string",
"x-ms-parameter-location": "client"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"swagger": 2.0,
"info": {
"title": "required_parameter",
"title": "parameter_order_change",
"version": "1.0"
},
"host": "localhost:8000",
Expand Down
Loading