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

Add new rule for new flag "x-ms-long-running-operation-options" #172

Closed
lmazuel opened this issue Jun 8, 2018 · 6 comments
Closed

Add new rule for new flag "x-ms-long-running-operation-options" #172

lmazuel opened this issue Jun 8, 2018 · 6 comments

Comments

@lmazuel
Copy link
Member

lmazuel commented Jun 8, 2018

Operation marked ad LRO can now have a new flag called "x-ms-long-running-operation-options":

"x-ms-long-running-operation": true,
"x-ms-long-running-operation-options": {
    "final-state-via":"location"
}

For the linter to check the correct usage of this new flag:

Rule 1: If the operation is the POST LRO and with return type, the option "x-ms-long-running-operation-options" is required, and the option "final-state-via" is required.

Rule 2: The only authorized values of "final-state-via" are "location" or "azure-async-operation" or "original-uri" or "default"

@fearthecowboy
Copy link
Member

azure-async-operation

@lmazuel
Copy link
Member Author

lmazuel commented Jun 8, 2018

@fearthecowboy fixed

@lmazuel
Copy link
Member Author

lmazuel commented Jun 8, 2018

Edit: updated values list with "original-uri"

@lmazuel
Copy link
Member Author

lmazuel commented Sep 25, 2018

Edit: added default thanks to @sarangan12

@sarangan12
Copy link
Contributor

sarangan12 commented Sep 27, 2018

I found this issue has 3 parts to this:

  1. If the operation is the POST LRO and with return type, the option "x-ms-long-running-operation-options" is required.
  2. If the operation is the POST LRO and with return type, the option "x-ms-long-running-operation-options" is required
    && the option "final-state-via" is required.
  3. The only authorized values of "final-state-via" are "location" or "azure-async-operation" or "original-uri" or "default"

Among these parts, Only Part 1 needs to be implemented. You do NOT need to implement Part 2 & Part 3. They are automatically handled by Autorest Schema Validator (which gets executed before linter.). So, if these parts are violated then the autorest will error out even before the linter starts its execution.

Example 1
If you have "x-ms-long-running-operation-options" without "final-state-via" value, the output will look like:

$ autorest --input-file=long-running-operations-options-missing.json --validation --azure-validator

AutoRest code generation utility [version: 2.0.4283; node: v8.6.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/Users/saranganrajamanickam/.autorest/@[email protected]/node_modules/@microsoft.azure/autorest-core/dist' (2.0.4289)
   Loading AutoRest extension '@microsoft.azure/classic-openapi-validator' (~1.0.9->1.0.13)
   Loading AutoRest extension '@microsoft.azure/openapi-validator' (~1.0.2->1.0.4)
ERROR: Schema violation: Missing required property: final-state-via
    - file:///Users/saranganrajamanickam/Projects/azure-openapi-validator/src/dotnet/OpenAPI.Validator.Tests/Resource/OpenAPI/Validation/long-running-operations-options-missing.json:20:8 ($.paths["/foo"].post["x-ms-long-running-operation-options"])
FATAL: swagger-document/individual/schema-validator - FAILED
FATAL: Error: [OperationAbortedException] Error occurred. Exiting.
Process() cancelled due to exception : [OperationAbortedException] Error occurred. Exiting.

Example 2
If you have an incorrect value for "final-state-via", the output will look like:

$ autorest --input-file=long-running-operations-options-missing.json --validation --azure-validator

AutoRest code generation utility [version: 2.0.4283; node: v8.6.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/Users/saranganrajamanickam/.autorest/@[email protected]/node_modules/@microsoft.azure/autorest-core/dist' (2.0.4289)
   Loading AutoRest extension '@microsoft.azure/classic-openapi-validator' (~1.0.9->1.0.13)
   Loading AutoRest extension '@microsoft.azure/openapi-validator' (~1.0.2->1.0.4)
ERROR: Schema violation: No enum match for: dummy
    - file:///Users/saranganrajamanickam/Projects/azure-openapi-validator/src/dotnet/OpenAPI.Validator.Tests/Resource/OpenAPI/Validation/long-running-operations-options-missing.json:21:10 ($.paths["/foo"].post["x-ms-long-running-operation-options"]["final-state-via"])
FATAL: swagger-document/individual/schema-validator - FAILED
FATAL: Error: [OperationAbortedException] Error occurred. Exiting.
Process() cancelled due to exception : [OperationAbortedException] Error occurred. Exiting

For Part 1, the code changes are ready and available at the PR: #179

@jianyexi
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants