Repository navigation
[Swagger Linter Migration] PutInOperationName + PatchInOperationName + DeleteInOperationName -> use-correct-verb #5673
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
Open
Yuchao Yan (msyyc)
wants to merge
24
commits into
main
Choose a base branch
from
promote-lintdiff-delete-in-operation-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+495
−473
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3e7122b
Add ARM use-update-for-patch lint rule
msyyc 5d131d4
Move PATCH SDK naming guidance to TCGC common names
msyyc abeb615
feat(tcgc): add opt-in DELETE SDK naming rule
msyyc ef1e589
Address promotion review feedback
msyyc 6475b75
Use ARM templates in DELETE naming rule documentation
msyyc e3785aa
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 2af91d5
refactor(tcgc): share PATCH and PUT SDK verb-prefix checks
msyyc 6f0eb98
refactor(tcgc): share DELETE and PUT SDK verb-prefix checks
msyyc 5a9015b
test(tcgc): remove PATCH version and suppression-only fixtures
msyyc bdb8b3f
test(tcgc): remove DELETE suppression-only fixture
msyyc fee3ceb
Merge branch 'main' into promote-lintdiff-patch-in-operation-name
msyyc 30ae8a4
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 6fcf466
Share standalone ARM fixtures and isolate DELETE dependency proof
msyyc 90e1e7d
Move native SDK linter emitter isolation to package integration tests
msyyc ed35661
Merge branch 'main' into promote-lintdiff-patch-in-operation-name
msyyc 862100d
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 380a163
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 6b9be23
test(tcgc): simplify naming suites and package isolation
msyyc 50c4b74
test(tcgc): simplify DELETE groups and package isolation
msyyc 5fc361c
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 8710828
Merge main and preserve rule inventory assertions for #5665
msyyc d121756
Consolidate PUT, PATCH, and DELETE SDK naming rules
msyyc e0ee4cd
Merge remote-tracking branch 'origin/main' into promote-lintdiff-dele…
Copilot a93d695
test(tcgc): remove redundant package isolation guard
msyyc 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,7 @@ | ||
| --- | ||
| changeKind: internal | ||
| packages: | ||
| - "@azure-tools/typespec-azure-rulesets" | ||
| --- | ||
|
|
||
| Register the `@azure-tools/typespec-client-generator-core/use-delete-for-delete` lint rule as disabled in the `client-sdk` ruleset. |
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,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@azure-tools/typespec-client-generator-core" | ||
| --- | ||
|
|
||
| Add the opt-in `use-delete-for-delete` lint rule requiring common SDK method names of concrete HTTP DELETE endpoints to start with `delete`, honoring unscoped client names and the supported friendly-name fallback. |
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
76 changes: 76 additions & 0 deletions
76
packages/typespec-client-generator-core/src/rules/use-delete-for-delete.md
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,76 @@ | ||
| Use an SDK method name beginning with `delete` for HTTP DELETE operations, such as | ||
| `delete` or `deleteWidget`. Consistent names make deletion methods easier to | ||
| discover in generated clients. | ||
|
|
||
| The rule checks the common TCGC SDK method name case-insensitively on concrete | ||
| HTTP service endpoints. It applies to ARM and data-plane services without requiring | ||
| `@armProviderNamespace`, and is disabled by default in the `client-sdk` ruleset. | ||
| Client-only declarations that are not service endpoints are not checked. | ||
|
|
||
| Name resolution uses TCGC's `getLibraryName` with `AllScopes`, including an | ||
| unscoped `@clientName`, exact names, and the supported `@friendlyName` fallback. | ||
| Overrides applying only to a particular language, such as | ||
| `@clientName("remove", "csharp")`, do not replace the common name. | ||
|
|
||
| The source program is checked without selecting an emitter or an API-version | ||
| projection. Historical names supplied through `@renamedFrom` are not reconstructed. | ||
|
|
||
| The following examples use generic HTTP authoring: import `@typespec/http`, use | ||
| `TypeSpec.Http`, and place the operation in a `@service` namespace. For ARM | ||
| resources, use the standard | ||
| [resource delete operation templates](https://azure.github.io/typespec-azure/docs/howtos/ARM/resource-operations#resource-delete-operations-delete), | ||
| with a name beginning with `delete`, such as | ||
| `delete is ArmResourceDeleteSync<Widget>;`. | ||
|
|
||
| #### ❌ Incorrect | ||
|
|
||
| ```typespec | ||
| @delete | ||
| @route("/widgets/{id}") | ||
| op remove(@path id: string): void; | ||
| ``` | ||
|
|
||
| #### ✅ Correct | ||
|
|
||
| ```typespec | ||
| @delete | ||
| @route("/widgets/{id}") | ||
| op deleteWidget(@path id: string): void; | ||
| ``` | ||
|
|
||
| ## Impact | ||
|
|
||
| - **Area:** SDK | ||
|
|
||
| Renaming a method in an already-shipped SDK may introduce a breaking change. | ||
| Review compatibility before changing existing names. | ||
|
|
||
| An unscoped `@clientName` can provide the correct SDK name without renaming the | ||
| TypeSpec operation: | ||
|
|
||
| ```typespec | ||
| @Azure.ClientGenerator.Core.clientName("deleteWidget") | ||
| @delete | ||
| @route("/widgets/{id}") | ||
| op remove(@path id: string): void; | ||
| ``` | ||
|
|
||
| Import `@azure-tools/typespec-client-generator-core` to use `@clientName`. | ||
|
|
||
| ## Suppression | ||
|
|
||
| Suppression is appropriate when preserving an already-shipped SDK method name | ||
| requires an exception approved by the API reviewer. For new methods, fix the | ||
| name instead, either by renaming the operation or using an unscoped `@clientName`. | ||
| Use `#suppress "@azure-tools/typespec-client-generator-core/use-delete-for-delete"` | ||
| on the operation with a justification for the compatibility exception. | ||
|
msyyc marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## LintDiff Equivalent | ||
|
|
||
| This rule enforces the SDK naming intent of | ||
| [`DeleteInOperationName`](https://github.com/Azure/azure-openapi-validator/blob/main/docs/delete-in-operation-name.md). | ||
| It does not reproduce serialized `operationId` underscore or group-prefix | ||
| exemptions. Explicit OpenAPI operation IDs do not change the common SDK method | ||
| name checked by this rule. The lintdiff source checks authored operation names; | ||
| the promoted rule intentionally checks common SDK names, including unscoped | ||
| SDK name overrides. | ||
46 changes: 46 additions & 0 deletions
46
packages/typespec-client-generator-core/src/rules/use-delete-for-delete.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,46 @@ | ||
| import { createRule, fileRef, paramMessage } from "@typespec/compiler"; | ||
| import { getAllHttpServices } from "@typespec/http"; | ||
| import { createTCGCContext } from "../context.js"; | ||
| import { AllScopes } from "../internal-utils.js"; | ||
| import { getLibraryName } from "../public-utils.js"; | ||
|
|
||
| export const useDeleteForDeleteRule = createRule({ | ||
| name: "use-delete-for-delete", | ||
| description: "DELETE SDK method names should use 'delete' as the verb prefix.", | ||
| severity: "warning", | ||
| url: "https://azure.github.io/typespec-azure/docs/libraries/typespec-client-generator-core/rules/use-delete-for-delete", | ||
| docs: fileRef.fromPackageRoot("src/rules/use-delete-for-delete.md"), | ||
| messages: { | ||
| default: paramMessage`DELETE SDK method name '${"operationName"}' should start with 'delete'.`, | ||
| }, | ||
| create(context) { | ||
| const tcgcContext = createTCGCContext( | ||
| context.program, | ||
| "@azure-tools/typespec-client-generator-core", | ||
| { mutateNamespace: false }, | ||
| ); | ||
|
|
||
| return { | ||
| root: () => { | ||
| const [services] = getAllHttpServices(context.program); | ||
| for (const service of services) { | ||
| for (const { operation, verb } of service.operations) { | ||
| if (verb !== "delete") { | ||
| continue; | ||
| } | ||
|
|
||
| const operationName = getLibraryName(tcgcContext, operation, AllScopes); | ||
| if (operationName.toLowerCase().startsWith("delete")) { | ||
| continue; | ||
| } | ||
|
|
||
| context.reportDiagnostic({ | ||
| target: operation, | ||
| format: { operationName }, | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.