Skip to content

[http-client-csharp] Normalize Url suffixes on operations and enum values - #11642

Merged
JoshLove-msft merged 3 commits into
microsoft:mainfrom
JoshLove-msft:josh/csharp-url-uri-normalization
Aug 13, 2026
Merged

[http-client-csharp] Normalize Url suffixes on operations and enum values#11642
JoshLove-msft merged 3 commits into
microsoft:mainfrom
JoshLove-msft:josh/csharp-url-uri-normalization

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Summary

  • normalize a complete Url suffix to Uri on operation names and fixed/extensible enum values
  • leave embedded or non-suffix text unchanged
  • preserve exact names and matching names from the last contract before applying normalization
  • keep existing model and property behavior unchanged

Validation

  • full Input, core generator, and ClientModel test projects
  • C# emitter build
  • Cop static analysis
  • formatting and spelling checks

Related to Azure/azure-sdk-for-net#61945

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

Copilot-Session: 1c88ef06-4775-4cc2-9a4c-8c807b1d23c4
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11642

commit: 03f3d12

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Normalizes generated C# identifiers by replacing a complete Url suffix with Uri for operation names and enum value names, while preserving isExactName values and retaining names from the last contract to avoid breaking changes in the http-client-csharp generator.

Changes:

  • Added ReplaceUrlSuffixWithUri string helper and unit tests for suffix normalization behavior.
  • Updated enum value name generation (fixed + extensible) to apply UrlUri normalization unless preserved by exact-name or last-contract matching.
  • Updated client operation name cleaning to apply UrlUri normalization unless preserved by exact-name or last-contract method names; refreshed related golden test data.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/Extensions/StringExtensions.cs Adds ReplaceUrlSuffixWithUri helper used by generator naming.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/StringExtensionsTests.cs Adds tests covering UrlUri suffix replacement cases.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/EnumProvider.cs Centralizes enum value generated-name logic and applies suffix normalization with last-contract preservation.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/FixedEnumProvider.cs Uses shared generated-name logic for fixed enums (including suffix normalization/back-compat).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ExtensibleEnumProvider.cs Uses shared generated-name logic for extensible enums (including suffix normalization/back-compat).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/EnumProviderTests.cs Adds coverage for enum value suffix normalization and last-contract preservation.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BuildEnumType_PreservesUrlSuffixFromLastContract(Fixed)/MockInputEnum.cs New last-contract test stub for fixed enum preserving Url suffix.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/TestData/EnumProviderTests/BuildEnumType_PreservesUrlSuffixFromLastContract(Extensible)/MockInputEnum.cs New last-contract test stub for extensible enum preserving Url suffix.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientProvider.cs Applies UrlUri normalization to operation names with last-contract preservation.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/ClientProviderTests.cs Adds tests for operation name normalization and last-contract preservation.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/TestOperationNamePreservesUrlSuffixFromLastContract/TestClient.cs New last-contract client stub to validate preserving GetUrl names.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithSlashQueryInPath.cs Updates golden output to reflect ...FromUri... naming.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithQueryInPath.cs Updates golden output to reflect ...FromUri... naming.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Copilot-Session: 1c88ef06-4775-4cc2-9a4c-8c807b1d23c4
@JoshLove-msft
JoshLove-msft added this pull request to the merge queue Aug 13, 2026
Merged via the queue into microsoft:main with commit d5fd8fd Aug 13, 2026
29 checks passed
@JoshLove-msft
JoshLove-msft deleted the josh/csharp-url-uri-normalization branch August 13, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants