-
Notifications
You must be signed in to change notification settings - Fork 46
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
Adding new rule XmsParameterLocation: Check Global parameters for this extension #149
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86b4dfc
Adding new rule XmsParameterLocation: Check Global parameters for thi…
sarangan12 bf6deb6
PR Comments
sarangan12 8f63918
PR Comments II
sarangan12 61fab6c
Added rule description
sarangan12 39f527d
Minor fix
sarangan12 08b9fde
Modify message
sarangan12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# XmsParameterLocation | ||
## Description | ||
An Open API Document has a section for parameters. Any parameter that is defined in this (global) parameters section will be treated as client parameters(by autorest). So, the service teams must be absolutely sure that this is the expectation (i.e. defining them as client properties) before defining the parameters in this section. | ||
|
||
90% scenario is that subscriptionId and api-version are parameters that should be defined in the global parameters section. | ||
|
||
However, one can define a parameter that is being referenced in multiple operations (example: resourceGroupName) in the global parameters section and apply the extension "x-ms-parameter-location": "method". This will then not be a client property. | ||
|
||
So, when you define a parameter in the global parameters section, apply the extension "x-ms-parameter-location": "method" so this will not be treated as a client property. But, if you actually want the parameter to be client properties then apply the extension "x-ms-parameter-location": "client". | ||
|
||
## How to fix | ||
Apply "x-ms-parameter-location": "method"/"x-ms-parameter-location": "client" on the global parameters (based on your requirements) | ||
|
||
## Reference | ||
Refer [Link](https://github.com/Azure/autorest/blob/master/docs/extensions/readme.md#x-ms-parameter-location) for further details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,7 @@ | |
"description": "foo", | ||
"operationId": "Operations_List", | ||
"x-ms-examples": { | ||
"Get operations": { | ||
|
||
} | ||
"Get operations": {} | ||
}, | ||
"parameters": [ | ||
{ | ||
|
@@ -75,9 +73,7 @@ | |
"pets" | ||
], | ||
"x-ms-examples": { | ||
"The pet we get": { | ||
|
||
} | ||
"The pet we get": {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Ideally json keys should not have spaces as such, consider renaming this to |
||
}, | ||
"parameters": [ | ||
{ | ||
|
@@ -118,9 +114,7 @@ | |
"pets" | ||
], | ||
"x-ms-examples": { | ||
"The pet we post": { | ||
|
||
} | ||
"The pet we post": {} | ||
}, | ||
"responses": { | ||
"201": { | ||
|
@@ -144,9 +138,7 @@ | |
"pets" | ||
], | ||
"x-ms-examples": { | ||
"The pet we get": { | ||
|
||
} | ||
"The pet we get": {} | ||
}, | ||
"parameters": [ | ||
{ | ||
|
@@ -177,9 +169,7 @@ | |
"get": { | ||
"operationId": "Foos_Get", | ||
"x-ms-examples": { | ||
"The foo we get": { | ||
|
||
} | ||
"The foo we get": {} | ||
}, | ||
"description": "foo", | ||
"responses": { | ||
|
@@ -192,9 +182,7 @@ | |
"operationId": "Foos_Post", | ||
"description": "foo", | ||
"x-ms-examples": { | ||
"The foo we post": { | ||
|
||
} | ||
"The foo we post": {} | ||
}, | ||
"parameters": [ | ||
{ | ||
|
@@ -224,9 +212,7 @@ | |
"operationId": "Foos_PostOverload", | ||
"description": "foo", | ||
"x-ms-examples": { | ||
"The foo we post": { | ||
|
||
} | ||
"The foo we post": {} | ||
}, | ||
"parameters": [ | ||
{ | ||
|
@@ -255,7 +241,8 @@ | |
"in": "query", | ||
"name": "FooQueryParam", | ||
"description": "Query parameter for Foo operation", | ||
"type": "string" | ||
"type": "string", | ||
"x-ms-parameter-location": "method" | ||
}, | ||
"SubscriptionIdParameter": { | ||
"name": "subscriptionId", | ||
|
148 changes: 148 additions & 0 deletions
148
src/dotnet/OpenAPI.Validator.Tests/Resource/OpenAPI/Validation/xms-parameter-location.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "Microsoft Azure Redis Cache Management API", | ||
"description": "Some cool documentation.", | ||
"version": "2014-04-01-preview" | ||
}, | ||
"host": "management.azure.com", | ||
"schemes": [ | ||
"https" | ||
], | ||
"basePath": "/", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}": { | ||
"delete": { | ||
"tags": [ | ||
"Redis" | ||
], | ||
"operationId": "Redis_Delete", | ||
"description": "Deletes a Redis cache.", | ||
"x-ms-long-running-operation": true, | ||
"parameters": [ | ||
{ | ||
"name": "resourceGroupName", | ||
"in": "path", | ||
"required": true, | ||
"type": "string", | ||
"description": "The name of the resource group." | ||
}, | ||
{ | ||
"name": "name", | ||
"in": "path", | ||
"required": true, | ||
"type": "string", | ||
"description": "The name of the Redis cache." | ||
}, | ||
{ | ||
"$ref": "#/parameters/ApiVersionParameter" | ||
}, | ||
{ | ||
"$ref": "#/parameters/SubscriptionIdParamterer" | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "" | ||
}, | ||
"204": { | ||
"description": "" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"Sku": { | ||
"description": "The SKU (pricing tier) of the CDN profile.", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"$ref": "#/definitions/SkuName", | ||
"description": "The name." | ||
} | ||
} | ||
}, | ||
"SkuName": { | ||
"type": "string", | ||
"enum": [ | ||
"NotSpecified", | ||
"Free", | ||
"Shared", | ||
"Basic", | ||
"Standard", | ||
"Premium" | ||
], | ||
"x-ms-enum": { | ||
"name": "SkuName", | ||
"modelAsString": false | ||
}, | ||
"description": "The sku name." | ||
}, | ||
"Resource": { | ||
"description": "The Resource model definition.", | ||
"properties": { | ||
"id": { | ||
"readOnly": true, | ||
"type": "string", | ||
"x-ms-client-name": "id2", | ||
"description": "Resource Id" | ||
}, | ||
"name": { | ||
"readOnly": true, | ||
"type": "string", | ||
"description": "Resource name" | ||
}, | ||
"type": { | ||
"readOnly": true, | ||
"type": "string", | ||
"description": "Resource type" | ||
}, | ||
"location": { | ||
"type": "string", | ||
"description": "Resource location" | ||
}, | ||
"tags": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "string" | ||
}, | ||
"description": "Resource tags" | ||
} | ||
}, | ||
"required": [ | ||
"location" | ||
], | ||
"x-ms-azure-resource": true | ||
} | ||
}, | ||
"parameters": { | ||
"SubscriptionIdParamterer": { | ||
"name": "subscriptionId", | ||
"in": "path", | ||
"description": "Subscription ID.", | ||
"required": true, | ||
"type": "string" | ||
}, | ||
"ApiVersionParameter": { | ||
"name": "apiVersion", | ||
"in": "path", | ||
"description": "API ID.", | ||
"required": true, | ||
"type": "string" | ||
}, | ||
"CatalogNameParameter": { | ||
"name": "catalogName", | ||
"in": "path", | ||
"required": true, | ||
"type": "string", | ||
"description": "The name of the data catlog in the specified subscription and resource group." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to add a positive test case as well.