-
Notifications
You must be signed in to change notification settings - Fork 88
[Swagger Linter Migration] LatestVersionOfCommonTypesMustBeUsed #5271
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
base: main
Are you sure you want to change the base?
Changes from all commits
8d2c8c5
440a51d
841b6f3
d8b8176
09df69b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@azure-tools/typespec-azure-resource-manager" | ||
| - "@azure-tools/typespec-azure-rulesets" | ||
| --- | ||
|
|
||
| Add an ARM lint rule that warns when services select or emit older ARM common-types versions instead of the latest available common-types version. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: "use-latest-version-of-common-types" | ||
| --- | ||
|
|
||
| ```text title="Full name" | ||
| @azure-tools/typespec-azure-resource-manager/use-latest-version-of-common-types | ||
| ``` | ||
|
|
||
| ARM services should use the latest ARM common-types version available in | ||
| `Azure.ResourceManager.CommonTypes.Versions`. This keeps TypeSpec services, | ||
| generated SDKs, and Azure tooling aligned with the current ARM common schemas. | ||
|
|
||
| The rule checks the effective `@armCommonTypesVersion` on each ARM service or | ||
| service version. When the selected version is current, it also checks common | ||
| types reachable from HTTP operation parameters and payloads so older legacy | ||
| symbols are not emitted through an otherwise current API version. | ||
|
|
||
| ## Impact | ||
|
|
||
| - **Area:** API, SDK | ||
|
|
||
| Older ARM common-types versions can expose stale shared schemas or parameters in | ||
| generated API surfaces and SDKs even when newer definitions are available. | ||
|
|
||
| ## Incorrect | ||
|
|
||
| ```tsp | ||
| @armProviderNamespace | ||
| @service(#{ title: "Contoso" }) | ||
| @versioned(Versions) | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| namespace Microsoft.Contoso; | ||
|
|
||
| enum Versions { | ||
| @useDependency(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| v2024_01_01: "2024-01-01", | ||
| } | ||
| ``` | ||
|
|
||
| ## Correct | ||
|
|
||
| ```tsp | ||
| @armProviderNamespace | ||
| @service(#{ title: "Contoso" }) | ||
| @versioned(Versions) | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
|
Member
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. This line might become outdated if a new version of common types is added. So maybe we should add a note in the docs to say something like: |
||
| namespace Microsoft.Contoso; | ||
|
|
||
| enum Versions { | ||
| @useDependency(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
| v2024_01_01: "2024-01-01", | ||
| } | ||
| ``` | ||
|
|
||
| ## Incorrect | ||
|
|
||
| This service selects the latest common-types version but still uses a legacy | ||
| common type that resolves to an older common-types file. | ||
|
|
||
| ```tsp | ||
| @armProviderNamespace | ||
| @service(#{ title: "Contoso" }) | ||
| @versioned(Versions) | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
| namespace Microsoft.Contoso; | ||
|
|
||
| enum Versions { | ||
| @useDependency(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
| v2024_01_01: "2024-01-01", | ||
| } | ||
|
|
||
| @route("/identity") | ||
| @get | ||
| op getIdentity(): Azure.ResourceManager.Legacy.ManagedServiceIdentityV4; | ||
| ``` | ||
|
|
||
| ## Correct | ||
|
|
||
| Use a common type supported by the selected latest common-types version, or | ||
| remove the legacy reference when the API shape no longer needs it. | ||
|
|
||
| ```tsp | ||
| @armProviderNamespace | ||
| @service(#{ title: "Contoso" }) | ||
| @versioned(Versions) | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
| namespace Microsoft.Contoso; | ||
|
|
||
| enum Versions { | ||
| @useDependency(Azure.ResourceManager.CommonTypes.Versions.v6) | ||
| v2024_01_01: "2024-01-01", | ||
| } | ||
|
|
||
| model Widget is TrackedResource<WidgetProperties> { | ||
| ...ManagedServiceIdentityProperty; | ||
|
|
||
| @key("widgetName") | ||
| @segment("widgets") | ||
| @path | ||
| name: string; | ||
| } | ||
|
|
||
| model WidgetProperties { | ||
| description?: string; | ||
| } | ||
|
|
||
| @route("/identity") | ||
| @get | ||
| op getIdentity(): Widget; | ||
|
Comment on lines
+94
to
+109
Member
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. This example seems much longer than the |
||
| ``` | ||
|
|
||
| ## LintDiff Equivalent | ||
|
|
||
| This rule corresponds to the LintDiff rule | ||
| [LatestVersionOfCommonTypesMustBeUsed](https://github.com/Azure/azure-openapi-validator/blob/main/docs/latest-version-of-common-types-must-be-used.md). | ||
|
|
||
| ## Suppression | ||
|
|
||
| Suppress only when an API must intentionally emit an older ARM common-types | ||
| schema for compatibility and the service team has accepted the API and SDK | ||
| impact. | ||
Uh oh!
There was an error while loading. Please reload this page.