-
Notifications
You must be signed in to change notification settings - Fork 49
Added new rule LroAzureAsyncOperationHeader #749
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
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7229d93
Added new rule LroAzureAsyncOperationHeader
tejaswiMinnu ed01a3b
Merge branch 'main' of https://github.com/Azure/azure-openapi-validat…
tejaswiMinnu 688c43a
I've addressed the comments and tweaked the logic to fit the rule for…
tejaswiMinnu 032a1d2
build failure
tejaswiMinnu c6c1e07
addressed comments
tejaswiMinnu f154e44
Reverted to initial logic to address all LRO operations to have Azure…
tejaswiMinnu 68964e2
added new function to check existence of both headers and Azure-Async…
tejaswiMinnu 8e6d248
somehow few changes not reflected pushing them again, and also addres…
tejaswiMinnu 449b5e4
trying to push changes again
tejaswiMinnu 0908e86
removed extra .
tejaswiMinnu c9519ad
added one more bad example
tejaswiMinnu 6a466c3
Merge branch 'main' into tejaswis/AddRPC-Async-V1-06
tejaswiMinnu a26684b
Merge branch 'main' into tejaswis/AddRPC-Async-V1-06
tejaswiMinnu 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 hidden or 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,67 @@ | ||
# LroAzureAsyncOperationHeader | ||
|
||
## Category | ||
|
||
ARM Error | ||
|
||
## Applies to | ||
|
||
ARM OpenAPI(swagger) specs | ||
|
||
## Related ARM Guideline Code | ||
|
||
- RPC-Async-V1-06 | ||
|
||
## Output Message | ||
|
||
All long-running operations must include an Azure-AsyncOperation response header. | ||
|
||
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Description | ||
|
||
Azure-AsyncOperation header must be supported for all async long-running operations. | ||
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## CreatedAt | ||
|
||
Oct 11, 2024 | ||
|
||
## How to fix the violation | ||
|
||
Adding the Azure-AsyncOperation header to the response.. | ||
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Good Example | ||
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```json | ||
"/api/configServers": { | ||
"put": { | ||
"operationId": "ConfigServers_Update", | ||
"responses": { | ||
"202": { | ||
"description": "Accepted", | ||
"headers": { | ||
"Azure-AsyncOperation": { | ||
"type": "string", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
``` | ||
|
||
## Bad Example | ||
|
||
```json | ||
"/api/configServers": { | ||
"put": { | ||
"operationId": "ConfigServers_Update", | ||
"responses": { | ||
"202": { | ||
"description": "Success", | ||
"headers": { | ||
//No Azure-AsyncOperation header | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
``` |
This file contains hidden or 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 hidden or 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 hidden or 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
186 changes: 186 additions & 0 deletions
186
packages/rulesets/src/spectral/test/lro-azure-async-operation-header.test.ts
This file contains hidden or 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,186 @@ | ||
import { Spectral } from "@stoplight/spectral-core" | ||
import linterForRule from "./utils" | ||
|
||
let linter: Spectral | ||
|
||
beforeAll(async () => { | ||
linter = await linterForRule("LroAzureAsyncOperationHeader") | ||
return linter | ||
}) | ||
|
||
const ERROR_MESSAGE = "Azure-AsyncOperation header must be supported for all async long-running operations." | ||
|
||
test("LroAzureAsyncOperationHeader should find no errors", () => { | ||
const myOpenApiDocument = { | ||
swagger: "2.0", | ||
paths: { | ||
"/foo1/operations": { | ||
get: { | ||
operationId: "foo_get", | ||
responses: { | ||
200: { | ||
description: "Success", | ||
}, | ||
202: { | ||
description: "Accepted", | ||
// no header scenario | ||
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
tejaswiMinnu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
post: { | ||
operationId: "foo_post", | ||
"x-ms-long-running-operation": true, | ||
responses: { | ||
200: { | ||
description: "Success", | ||
}, | ||
202: { | ||
description: "Accepted", | ||
headers: { | ||
"Azure-AsyncOperation": { | ||
description: "The URL where the status of the asynchronous operation can be checked.", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
put: { | ||
operationId: "foo_put", | ||
"x-ms-long-running-operation": true, | ||
responses: { | ||
204: { | ||
description: "Accepted", | ||
headers: { | ||
"Azure-AsyncOperation": { | ||
description: "The URL where the status of the asynchronous operation can be checked.", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
delete: { | ||
operationId: "foo_put", | ||
responses: { | ||
204: { | ||
description: "No x-ms-long-running-operation ", | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return linter.run(myOpenApiDocument).then((results) => { | ||
expect(results.length).toBe(0) | ||
}) | ||
}) | ||
|
||
test("LroAzureAsyncOperationHeader should find errors with no Azure-AsyncOperation header", () => { | ||
const myOpenApiDocument = { | ||
swagger: "2.0", | ||
paths: { | ||
"/foo1/operations": { | ||
get: { | ||
operationId: "foo_get", | ||
"x-ms-long-running-operation": true, | ||
responses: { | ||
200: { | ||
description: "Success", | ||
}, | ||
202: { | ||
description: "Accepted", | ||
headers: { | ||
Location: { | ||
description: "No Azure-AsyncOperation header", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
post: { | ||
operationId: "foo_post", | ||
"x-ms-long-running-operation": false, | ||
responses: { | ||
200: { | ||
description: "Success", | ||
}, | ||
202: { | ||
description: "Empty header case", | ||
headers: { | ||
Location: { | ||
description: "No Azure-AsyncOperation header", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
put: { | ||
operationId: "foo_put", | ||
"x-ms-long-running-operation": true, | ||
responses: { | ||
200: { | ||
description: "Success", | ||
}, | ||
202: { | ||
description: "Accepted", | ||
headers: { | ||
"azure-asyncOperation1": { | ||
description: "check the wrong wording", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
default: { | ||
description: "Error", | ||
}, | ||
}, | ||
}, | ||
delete: { | ||
operationId: "foo_put", | ||
"x-ms-long-running-operation": true, | ||
responses: { | ||
202: { | ||
description: "Accepted", | ||
headers: { | ||
"azure-asyncOperation": { | ||
description: "Check case sensitive scenario", | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return linter.run(myOpenApiDocument).then((results) => { | ||
expect(results.length).toBe(3) | ||
expect(results[0].path.join(".")).toBe("paths./foo1/operations.get.responses.202.headers.Location") | ||
expect(results[0].message).toEqual(ERROR_MESSAGE) | ||
expect(results[1].path.join(".")).toBe("paths./foo1/operations.put.responses.202.headers.azure-asyncOperation1") | ||
expect(results[1].message).toEqual(ERROR_MESSAGE) | ||
expect(results[2].path.join(".")).toBe("paths./foo1/operations.delete.responses.202.headers.azure-asyncOperation") | ||
expect(results[2].message).toEqual(ERROR_MESSAGE) | ||
}) | ||
}) |
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.
Uh oh!
There was an error while loading. Please reload this page.