Skip to content
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

Exclude GET verb from LroExtension rule validation #616

Merged
merged 3 commits into from
Nov 10, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft.azure/openapi-validator-rulesets",
"comment": "Update RPC-GET-V1-01(GetResponseCodes) to allow GET with 202 response code if the GET represents the location header polling url. Update RPC-Post-V1-09(LroExtension) to exclude GET from x-ms-long-running-operation presence validation",
"type": "patch"
Copy link
Member

@rkmanda rkmanda Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  "comment": "Update RPC-GET-V1-01(GetOperation200) to allow GET with 202 response code if the GET represents the location header polling url. Update RPC-Post-V1-09(LroExtension) to exclude GET from x-ms-long-running-operation presence validation",

#Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt add
"if the GET represents the location header polling url" cause that isnt being checked in this rule

}
],
"packageName": "@microsoft.azure/openapi-validator-rulesets"
}
33 changes: 0 additions & 33 deletions docs/get-operation200.md

This file was deleted.

137 changes: 137 additions & 0 deletions docs/get-response-codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# GetResponseCodes

## Category

ARM Error

## Applies to

ARM OpenAPI(swagger) specs

## Related ARM Guideline Code

- RPC-Get-V1-01

## Description

The get operation should only return 200, also it should not be a long running operation.
In addition, it can return 202 only if it has location header defined (i.e, if it is a polling action).

## How to fix the violation

Copy link
Member

@rkmanda rkmanda Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include good and bad examples #Closed

Remove all the other response codes except 200 and 202 with "Location" header defined
i.e, remove response codes 201, 202(if no "Location" header defined), 203, 204.

## Good Examples

```json
...
"/providers/Microsoft.Music/songs/{songName}" {
"get" {
"responses": {
"200": {
"description": "Successful completion of the asynchronous operation",
"schema": {
"$ref": "#/definitions/SongName"
}
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
}
...
```

```json
...
"/providers/Microsoft.Music/songOperations/{operationId}" {
"get" {
"responses": {
"200": {
"description": "Successful completion of the asynchronous operation",
"schema": {
"$ref": "#/definitions/SongName"
}
},
"202": {
"description": "Accepted",
"headers": {
"Location": {
"description": "The URL where the status of the asynchronous operation can be checked.",
"type": "string"
},
},
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
}
...
```

## Bad Examples

```json
...
"/providers/Microsoft.Music/songOperations/{operationId}" {
"get" {
"responses": {
"200": {
"description": "Successful completion of the asynchronous operation",
"schema": {
"$ref": "#/definitions/SongName"
}
},
"201": {
"description": "Created",
},
"203": {
"description": "Non authoritative",
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
}
...
```

```json
...
"/providers/Microsoft.Music/songOperations/{operationId}" {
"get" {
"responses": {
"202": {
"description": "Accepted",
"headers": {
"Location": {
"description": "The URL where the status of the asynchronous operation can be checked.",
"type": "string"
},
},
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
}
}
}
...
```
63 changes: 52 additions & 11 deletions docs/lro-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,65 @@ ARM & Data Plane Error
ARM & Data Plane OpenAPI specs

## Related ARM Guideline Code
- RPC-Post-V1-09

## Output Message

Operations with a 202 response should specify `x-ms-long-running-operation: true`.
- RPC-Post-V1-09

## Description

Operations with a 202 response should specify `x-ms-long-running-operation: true`.
Operations with a 202 response should specify `x-ms-long-running-operation: true`.
GET operation is excluded from the validation as GET will have 202 only if it is a polling action & hence x-ms-long-running-operation wouldn't be defined

## CreatedAt
## How to fix the violation

June 18, 2022
Add the `x-ms-long-running-operation: true` extension to PUT, PATCH, POST, DELETE operationS.

## LastModifiedAt
## Good Examples

June 18, 2022
```json
...
"/providers/Microsoft.Music/songs/{songName}" {
"put" {
"responses": {
"202": {
"description": "Accepted",
"schema": {
"$ref": "#/definitions/SongName"
}
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
"x-ms-long-running-operation": true,
}
}
...
```

## How to fix the violation
## Bad Examples

Add the `x-ms-long-running-operation: true` extension to the operation.
```json
...
"/providers/Microsoft.Music/songs/{songName}" {
"put" {
"responses": {
"202": {
"description": "Accepted",
"schema": {
"$ref": "#/definitions/SongName"
}
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
}
},
}
}
...
```
8 changes: 5 additions & 3 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,12 @@ The GET calls are synchronous and it MUST NOT have

Please refer to [get-operation-must-not-be-long-running.md](./get-operation-must-not-be-long-running.md) for details.

### GetOperation200
### GetResponseCodes

The get operation should only return 200, also it should not be a long running operation.
In addition, it can return 202 only if it has location header defined (i.e, if it is a polling action).

Please refer to [get-operation200.md](./get-operation200.md) for details.
Please refer to [get-response-codes.md](./get-response-codes.md) for details.

### GuidUsage

Expand Down Expand Up @@ -494,7 +495,8 @@ Please refer to [lro-error-content.md](./lro-error-content.md) for details.

### LroExtension

Operations with a 202 response should specify `x-ms-long-running-operation: true`.
Operations with a 202 response should specify `x-ms-long-running-operation: true`.
GET operation is excluded from the validation as GET will have 202 only if it is a polling action & hence x-ms-long-running-operation wouldn't be defined

Please refer to [lro-extension.md](./lro-extension.md) for details.

Expand Down
Loading