Skip to content

Add operation-aware C# body suffix linting - #5058

Draft
haiyuazhang wants to merge 9 commits into
Azure:mainfrom
haiyuazhang:haiyzhan/csharp-patch-body-suffix-rule
Draft

Add operation-aware C# body suffix linting#5058
haiyuazhang wants to merge 9 commits into
Azure:mainfrom
haiyuazhang:haiyzhan/csharp-patch-body-suffix-rule

Conversation

@haiyuazhang

@haiyuazhang haiyuazhang commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • make csharp-model-suffix operation-aware for direct PATCH and PUT/POST bodies
  • use Content for immediate nested request models while stopping at the first named model
  • suppress diagnostics when request, response, or HTTP verb roles conflict
  • add C#-scoped code fixes, documentation, and comprehensive tests

Addresses the design for #4447.

Detection algorithm

  1. Resolve all HTTP operations and collect each model's usage roles:
    • direct PATCH body → patch
    • direct PUT/POST body → content
    • immediate nested model in a PATCH/PUT/POST body → content
    • response body → response
    • direct body for another HTTP verb → other
  2. For nested content, inspect only properties directly declared or inherited by the body model. Unwrap arrays, records, tuples, unions, and anonymous models, then stop at the first named model instead of recursively inspecting its properties.
  3. Resolve the effective C# model name with getLibraryName(..., "csharp"), including any existing @clientName override.
  4. Check only names ending in Parameter, Parameters, or Request:
    • an unambiguous patch role recommends Patch
    • an unambiguous content role recommends Content
  5. Produce no diagnostic when roles conflict, such as direct PATCH plus PUT/POST, direct PATCH plus nested content, or request plus response usage. Multiple PATCH uses and combined PUT/POST uses are compatible.
  6. Offer a C#-scoped @@clientName code fix when the expected suffix is deterministic.

The rule intentionally does not require every PATCH body name to end in Patch; names with other suffixes remain outside #4447.

Why only Parameter, Parameters, and Request?

This boundary keeps the rule deterministic and aligned with #4447:

A broader rule requiring every PATCH body name to end in Patch would produce approximately 653 existing diagnostics. Many affected names end in Update, Contract, Payload, Resource, or domain-specific terms whose correct replacement requires semantic context. For example, Settings may need to become FaceSettingsPatch, while ResourceUpdateModel may need to become AgriServiceResourcePatch. The linter cannot reliably infer those service or resource prefixes.

The targeted suffix list is therefore a safety boundary: it reports only cases where both the violation and recommended name are deterministic.

Dependency

This PR is stacked on #4867 because it extends the csharp-model-suffix rule introduced there. Until #4867 merges, this PR's diff also includes the batch1 commits. After #4867 merges, the branch will be synchronized with main so only the PATCH/Content changes remain.

Haiyuan Zhang and others added 9 commits July 20, 2026 01:21
Add csharp-no-options-suffix, csharp-no-request-suffix, csharp-no-response-suffix, and csharp-use-standard-acronyms for C# SDK model naming.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d02f6a96-81e2-4256-b6f5-798e382049b8
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d02f6a96-81e2-4256-b6f5-798e382049b8
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d02f6a96-81e2-4256-b6f5-798e382049b8
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c0af1189-afe1-444d-9911-3e98e456f3b9
Consolidate model suffix checks, broaden augment targets, and dedent multiline code fix expectations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c0af1189-afe1-444d-9911-3e98e456f3b9
Move the new linter documentation into the source-based docs flow introduced on main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c0af1189-afe1-444d-9911-3e98e456f3b9
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 12e46e52-385e-444f-a3fc-ee8cd7d97c83
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 12e46e52-385e-444f-a3fc-ee8cd7d97c83
@microsoft-github-policy-service microsoft-github-policy-service Bot added int:azure-specs Run integration tests against azure-rest-api-specs lib:tcgc Issues for @azure-tools/typespec-client-generator-core library meta:website TypeSpec.io updates linter Issues related to linter rules labels Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-azure-rulesets
  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - feature ✏️

Add csharp-model-suffix and csharp-use-standard-acronyms linter rules for C# SDK model,> naming, including operation-aware Patch and Content suffixes for request body models.

@azure-tools/typespec-azure-rulesets - feature ✏️

Add csharp-model-suffix and csharp-use-standard-acronyms linter rules for C# SDK model,> naming, including operation-aware Patch and Content suffixes for request body models.

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-azure-rulesets@5058
npm i https://pkg.pr.new/@azure-tools/typespec-client-generator-core@5058

commit: 14b0392

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

int:azure-specs Run integration tests against azure-rest-api-specs lib:tcgc Issues for @azure-tools/typespec-client-generator-core library linter Issues related to linter rules meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant