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

[ProvisioningStateMustBeReadOnly] Rule ignores siblings of $ref #637

Open
cataggar opened this issue Dec 14, 2023 · 3 comments
Open

[ProvisioningStateMustBeReadOnly] Rule ignores siblings of $ref #637

cataggar opened this issue Dec 14, 2023 · 3 comments
Assignees

Comments

@cataggar
Copy link
Member

cataggar commented Dec 14, 2023

I am working on https://github.com/Azure/azure-rest-api-specs-pr/pull/15631 and there are many instances of ProvisioningStateMustBeReadOnly errors that are false positives.
https://github.com/Azure/azure-rest-api-specs-pr/pull/15631/checks?check_run_id=19650955197

All of the provisioningStates are marked as readOnly, for example:

        "provisioningState": {
          "$ref": "#/definitions/AddonProvisioningState",
          "description": "The state of the addon provisioning",
          "readOnly": true
        }

I see this test was considered flaky before in #561. cc @AkhilaIlla

@cataggar
Copy link
Member Author

I saw this discussed in Azure/azure-sdk-tools#6191. The solution was to add use-read-only-status-schema: true to the tspconfig.yml:

options:
  "@azure-tools/typespec-autorest":
    azure-resource-provider-folder: "resource-manager"
    emitter-output-dir: "{project-root}/.."
    examples-directory: examples
    output-file: "{azure-resource-provider-folder}/{service-name}/{version-status}/{version}/vmware.json"
    omit-unreachable-types: true
    use-read-only-status-schema: true

@mikeharder
Copy link
Member

mikeharder commented Jun 7, 2024

This should be fixed in coordination wtih Azure/oav#848.

Overview

The rule is a "false positive" from the perspective of autorest, but it's correct from the perspective of OpenAPI 2.0. Siblings of $ref are allowed in the former, but ignored in the latter (#706).

Spectral

ProvisioningStateMustBeReadOnly is a "spectral" rule:

ProvisioningStateMustBeReadOnly: {
rpcGuidelineCode: "RPC-Async-V1-16",
description: "This is a rule introduced to validate if provisioningState property is set to readOnly or not.",
message: "{{error}}",
severity: "error",
disableForTypeSpec: false,
disableForTypeSpecReason: "Covered by TSP's '@azure-tools/typespec-azure-resource-manager/arm-resource-provisioning-state' rule.",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths'].*.*.responses.*.schema"],
then: {
function: provisioningStateMustBeReadOnly,
},
},

It's probably ignoring the readonly property, because the OpenAPI 2.0 spec says it should be ignored. It might be possible to configure spectral allow siblings of $ref, but I'm not sure if or how yet, other than converting the autorest to OpenAPI 3.1 which allows siblings of $ref.

Relevant unit test from spectral:

https://github.com/stoplightio/spectral/blob/9e906eaa0e792d229e1fd553f018ab8e6afef12e/packages/rulesets/src/oas/__tests__/no-%24ref-siblings.test.ts

Convert to Native

Otherwise, this rule could be converted from spectral to native, which should be able to allow siblings of $ref.

Documentation

Until fixed, we should improve the documentation:

  1. Add a bullet to https://github.com/Azure/azure-rest-api-specs/blob/main/documentation/ci-fix.md#swagger-lintdiff-for-typespec-troubleshooting-guides
  2. Add a suggestion to add use-read-only-status-schema: true to the rule error message.

@mikeharder mikeharder changed the title False positives for ProvisioningStateMustBeReadOnly [ProvisioningStateMustBeReadOnly] Rule ignores siblings of $ref Jun 7, 2024
@mikeharder mikeharder reopened this Jun 7, 2024
@mikeharder mikeharder self-assigned this Jun 7, 2024
@mikeharder
Copy link
Member

@markcowl: How would you characterize setting use-read-only-status-schema: true in tspconfig.yaml? Is this a "workaround" for the bugs in azure-openapi-validator and oav? Or should specs configure this for other reasons, and the errors are just a good reminder?

Put another way, if the bugs in azure-openapi-validator and oav are fixed, is TypeSpec setting use-read-only-status-schema still useful? Ignoring our tooling, how does this setting impact the spec, the SDKs, or customers?

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

No branches or pull requests

2 participants