Skip to content

feat: add support for @clientOption("includeRootSlash") in C# emitter#9934

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-support-for-includerootslash
Draft

feat: add support for @clientOption("includeRootSlash") in C# emitter#9934
Copilot wants to merge 4 commits intomainfrom
copilot/add-support-for-includerootslash

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

  • Add includeRootSlash client option support to C# emitter
    • Add SdkClientType<SdkHttpOperation> parameter to fromSdkServiceMethod and related functions
    • Add resolveIncludeRootSlash helper function that checks operation first, then walks up client hierarchy
    • Strip leading / from operation.path when includeRootSlash is false (explicit first-char check)
    • Pass client context from client-converter.ts to operation-converter.ts
    • Create ClientOptions internal type with const strings for supported option names
  • Add unit tests for:
    • Client-level includeRootSlash option (interface with option strips slash)
    • Default behavior (no option set, slash preserved)
    • Operation-level option (strips slash on specific operation)
    • Sub-client overriding parent client option
    • Operation overriding client-level option
    • Sub-client inheriting from parent client option
    • Multiple sub-clients with multiple operations each using different clientOption values
  • Validate all emitter tests pass (16 passed)
  • Fix formatting issues (npm run format)
Original prompt

This section details on the original issue you should resolve

<issue_title>add support for @clientoption("includeRootSlash")</issue_title>
<issue_description>Some legacy services require routes to not be prefixed with the / character. In example an operation with @route("?restype=container") should yield the following request uri: https://myuri/test-container-d1401e73-0567-7e68-91e8-2105f4d5001b?restype=container instead of https://myuri/test-container-d1401e73-0567-7e68-91e8-2105f4d5001b/?restype=container. The / is added by default by typespec to all routes.

We should add a new clientOption to override this behavior. When enabled, it will strip the / character from any prefixed path string.

Example usage on a client:

@@clientOption(Storage.Blob, "includeRootSlash", false, "csharp");

Example usage on an operation:

@@clientOption(Storage.Blob.foo, "includeRootSlash", false, "csharp");

Support for this option should be added for clients, sub-clients / interfaces, and operations. Sub-clients + operations should be able to override the option set by their parent.</issue_description>

<agent_instructions>You are a senior software engineer. Update the http-client-csharp emitter https://github.com/microsoft/typespec/tree/main/packages/http-client-csharp/emitter to support this new option. Add unit tests exercising the different scenarios outlined in the issue. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Add support for @clientoption("includeRootSlash") in the http-client-csharp emitter.
When set to false, strips the leading '/' from operation paths.
Supports client-level, sub-client-level, and operation-level configuration,
with child elements able to override parent settings.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 5, 2026
Copilot AI changed the title [WIP] Add support for @clientOption("includeRootSlash") feat: add support for @clientOption("includeRootSlash") in C# emitter Mar 5, 2026
client?: SdkClientType,
): boolean {
// First check the method/operation level
const methodOption = getClientOptions(method, "includeRootSlash");
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot lets create a new internal type ClientOptions that will have the const strings / config of the supported options by the emitter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in a0aab22. Created emitter/src/type/client-options.ts with a ClientOptions const object that centralizes the supported option name strings (includeRootSlash, collectionHeaderPrefix). Updated all getClientOptions() call sites to use these constants.

it("should allow operation to override client includeRootSlash option", async () => {
const program = await typeSpecCompile(
`
#suppress "@azure-tools/typespec-client-generator-core/client-option" "test"
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot lets add a new test that has multiple subclients and each subclient has multiple operations each with different clientOption values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in a0aab22. New test "should handle multiple sub-clients with different includeRootSlash values per operation" covers three sub-clients (BlobClient, ContainerClient, DefaultClient) each with multiple operations using different clientOption values, verifying client-level inheritance and per-operation overrides.

- Remove duplicate SdkClientType alias from operation-converter.ts (use SdkClientType<SdkHttpOperation> directly)
- Make slash removal more explicit: check first character instead of regex
- Create ClientOptions type with const strings for supported option names
- Add comprehensive test with multiple sub-clients and mixed per-operation values

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

Open in StackBlitz

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

commit: 910227f

@jorgerangel-msft
Copy link
Contributor

@copilot run npm run format to fix this lint / format issues

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot run npm run format to fix this lint / format issues

Fixed in d799987. Ran npm run format — it adjusted one line wrapping in the test file.

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.

add support for @clientOption("includeRootSlash")

2 participants