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
Merged
Yuchao Yan (msyyc)
merged 29 commits into
main
from
promote-lintdiff-delete-in-operation-name
Oct 22, 2026
+539
−473
Merged
Changes from all commits
Commits
Show all changes
29 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 e564326
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
msyyc 937f5bc
fix(tcgc): simplify verb naming checks and service traversal
msyyc aaf8b5c
Update packages/typespec-client-generator-core/src/rules/use-correct-…
msyyc 9a8f4f9
docs(tcgc): focus verb naming guidance on spec authors
msyyc 91e0a0f
Merge branch 'main' into promote-lintdiff-delete-in-operation-name
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" | ||
| --- | ||
|
|
||
| Replace the separate SDK verb naming registrations with `@azure-tools/typespec-client-generator-core/use-correct-verb`, disabled by default 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" | ||
| --- | ||
|
|
||
| Consolidate `use-create-for-put`, PATCH naming guidance, and DELETE naming guidance into the opt-in `use-correct-verb` lint rule. Common SDK method names must start with `create` for PUT, `update` for PATCH, and `delete` for DELETE, case-insensitively. Replace `use-create-for-put` in linter configuration and suppressions with `use-correct-verb`; enabling it also checks PATCH and DELETE. Renaming an already-shipped SDK method may be a breaking change. |
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
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
78 changes: 78 additions & 0 deletions
78
packages/typespec-client-generator-core/src/rules/use-correct-verb.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,78 @@ | ||
| Use common SDK method names for resource lifecycle operations. Operation names should begin with `create` for PUT, `update` for PATCH, | ||
| and `delete` for DELETE. Prefix matching is case-insensitive. GET, POST, HEAD, | ||
| and other HTTP verbs are outside this rule. | ||
|
|
||
| This guidance applies to both ARM and data-plane services. To fix a warning, | ||
| rename the operation or use `@clientName` without a language scope, as shown below. | ||
| Changing only a language-specific name or an OpenAPI operation ID does not fix | ||
| the common SDK name. | ||
|
|
||
| The rule is disabled by default in the `client-sdk` ruleset. | ||
|
|
||
| These examples assume `Widget` and `WidgetProperties` are defined ARM resource types. | ||
|
|
||
| #### ❌ Incorrect | ||
|
|
||
| ```typespec | ||
| @armResourceOperations | ||
| interface Widgets { | ||
| replace is ArmResourceCreateOrReplaceAsync<Widget>; | ||
| modify is ArmResourcePatchSync<Widget, Properties = WidgetProperties>; | ||
| remove is ArmResourceDeleteSync<Widget>; | ||
| } | ||
| ``` | ||
|
|
||
| #### ✅ Correct | ||
|
|
||
| ```typespec | ||
| @armResourceOperations | ||
| interface Widgets { | ||
| createOrUpdate is ArmResourceCreateOrReplaceAsync<Widget>; | ||
| update is ArmResourcePatchSync<Widget, Properties = WidgetProperties>; | ||
| delete is ArmResourceDeleteSync<Widget>; | ||
| } | ||
| ``` | ||
|
|
||
| ## Impact | ||
|
|
||
| - **Area:** SDK | ||
|
|
||
| Renaming an already-shipped SDK method may introduce a breaking change. | ||
| Review compatibility before changing names. An unscoped `@clientName` changes | ||
| the common SDK name without renaming the TypeSpec operation: | ||
|
|
||
| ```typespec | ||
| @armResourceOperations | ||
| interface Widgets { | ||
| @clientName("deleteWidget") | ||
| remove is ArmResourceDeleteSync<Widget>; | ||
| } | ||
| ``` | ||
|
|
||
| ## Suppression | ||
|
|
||
| For new methods, fix the name or use an unscoped `@clientName`. When preserving | ||
| an already-shipped name requires an API-reviewer-approved exception, suppress | ||
| the warning on that operation with a justification: | ||
|
|
||
| ```typespec | ||
| @armResourceOperations | ||
| interface Widgets { | ||
| #suppress "@azure-tools/typespec-client-generator-core/use-correct-verb" "Preserve the already-shipped SDK method name." | ||
| remove is ArmResourceDeleteSync<Widget>; | ||
| } | ||
| ``` | ||
|
|
||
| ## Migration | ||
|
|
||
| If you use `use-create-for-put`, replace it with `use-correct-verb` in linter | ||
| configuration and suppressions. Enabling the replacement checks PATCH and DELETE | ||
| names as well as PUT names. | ||
|
|
||
| ## LintDiff Equivalent | ||
|
msyyc marked this conversation as resolved.
|
||
|
|
||
| | Swagger validator | Native SDK naming requirement | | ||
| | -------------------------------------------------------------------------------------------------------------------- | --------------------------------- | | ||
| | [PutInOperationName](https://github.com/Azure/azure-openapi-validator/blob/main/docs/put-in-operation-name.md) | PUT names start with `create`. | | ||
| | [PatchInOperationName](https://github.com/Azure/azure-openapi-validator/blob/main/docs/patch-in-operation-name.md) | PATCH names start with `update`. | | ||
| | [DeleteInOperationName](https://github.com/Azure/azure-openapi-validator/blob/main/docs/delete-in-operation-name.md) | DELETE names start with `delete`. | | ||
81 changes: 81 additions & 0 deletions
81
packages/typespec-client-generator-core/src/rules/use-correct-verb.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,81 @@ | ||
| import { | ||
| createRule, | ||
| fileRef, | ||
| isTemplateDeclaration, | ||
| isTemplateDeclarationOrInstance, | ||
| listServices, | ||
| paramMessage, | ||
| type Namespace, | ||
| } from "@typespec/compiler"; | ||
| import { getHttpOperation } from "@typespec/http"; | ||
| import { createTCGCContext } from "../context.js"; | ||
| import { AllScopes } from "../internal-utils.js"; | ||
| import { getLibraryName } from "../public-utils.js"; | ||
|
|
||
| const verbPrefixes = { put: "create", patch: "update", delete: "delete" }; | ||
|
|
||
| export const useCorrectVerbRule = createRule({ | ||
| name: "use-correct-verb", | ||
| description: | ||
| "PUT, PATCH, and DELETE SDK method names should start with 'create', 'update', and 'delete', respectively.", | ||
| severity: "warning", | ||
| url: "https://azure.github.io/typespec-azure/docs/libraries/typespec-client-generator-core/rules/use-correct-verb", | ||
| docs: fileRef.fromPackageRoot("src/rules/use-correct-verb.md"), | ||
| messages: { | ||
| default: paramMessage`${"verb"} SDK method name '${"operationName"}' should start with '${"prefix"}'. Note: If you have already shipped an SDK on top of this spec, fixing this warning may introduce a breaking change.`, | ||
| }, | ||
| create(context) { | ||
| const tcgcContext = createTCGCContext( | ||
| context.program, | ||
| "@azure-tools/typespec-client-generator-core", | ||
| { mutateNamespace: false }, | ||
| ); | ||
| const serviceNamespaces = new Set(listServices(context.program).map((service) => service.type)); | ||
| const globalNamespace = context.program.getGlobalNamespaceType(); | ||
|
|
||
| return { | ||
| operation: (operation) => { | ||
| if (isTemplateDeclarationOrInstance(operation)) return; | ||
| const container = operation.interface ?? operation.namespace; | ||
| const namespace = operation.interface?.namespace ?? operation.namespace; | ||
| if (!container || !namespace || container.operations.get(operation.name) !== operation) { | ||
| return; | ||
| } | ||
| if ( | ||
| operation.interface && | ||
| (isTemplateDeclaration(operation.interface) || | ||
| namespace.interfaces.get(operation.interface.name) !== operation.interface) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| // HTTP's implicit global service is nonrecursive, including only direct interfaces. | ||
| let eligible = | ||
| namespace === globalNamespace && | ||
| (serviceNamespaces.size === 0 || serviceNamespaces.has(globalNamespace)); | ||
| for ( | ||
| let ancestor: Namespace | undefined = namespace; | ||
| ancestor && ancestor !== globalNamespace; | ||
| ancestor = ancestor.namespace | ||
| ) { | ||
| if (serviceNamespaces.has(ancestor)) { | ||
| eligible = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!eligible) return; | ||
|
|
||
| const [{ verb }] = getHttpOperation(context.program, operation); | ||
| if (verb !== "put" && verb !== "patch" && verb !== "delete") return; | ||
| const prefix = verbPrefixes[verb]; | ||
| const operationName = getLibraryName(tcgcContext, operation, AllScopes); | ||
| if (!operationName.toLowerCase().startsWith(prefix)) { | ||
| context.reportDiagnostic({ | ||
| target: operation, | ||
| format: { verb: verb.toUpperCase(), operationName, prefix }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }); |
82 changes: 0 additions & 82 deletions
82
packages/typespec-client-generator-core/src/rules/use-create-for-put.md
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
packages/typespec-client-generator-core/src/rules/use-create-for-put.ts
This file was deleted.
Oops, something went wrong.
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.