Skip to content

fix: respect wire type for endpoint params in ClientSettings#10088

Merged
jorgerangel-msft merged 5 commits intomainfrom
copilot/handle-string-endpoint-params
Mar 19, 2026
Merged

fix: respect wire type for endpoint params in ClientSettings#10088
jorgerangel-msft merged 5 commits intomainfrom
copilot/handle-string-endpoint-params

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

ClientSettingsProvider unconditionally typed endpoint properties as Uri and used Uri.TryCreate binding, ignoring the actual wire type. A string-typed endpoint like fullyQualifiedNamespace: string should produce string?, not Uri?.

Changes

  • ClientSettingsProvider.cs: Consolidated EndpointPropertyName and EndpointPropertyType into a single EndpointProperty of type PropertyProvider, created in the constructor from the input endpoint parameter's wire type. BuildProperties() includes the pre-created property directly, and BuildMethods() routes through AppendBindingForProperty() instead of hardcoding Uri.
  • ClientProvider.cs: Updated BuildSettingsConstructors() to use ClientSettings.EndpointProperty instead of the removed ClientSettings.EndpointPropertyName.
  • ClientSettingsProviderTests.cs: Tests combine inline assertions (property types, BindCore method signature and binding patterns) with TestData-based validation using TypeProviderWriter to compare full generated output. Added TestGeneratedSettings_WithStringEndpoint, TestGeneratedSettings_WithUrlEndpoint, and TestGeneratedSettings_WithNamedStringEndpoint (for fullyQualifiedNamespace: string pattern) to validate generated settings. Added TestSettingsConstructor_WithStringEndpoint and TestSettingsConstructor_WithUrlEndpoint with TestData to validate the full generated client including the settings constructor for both endpoint types.

Before/After

// Before: string endpoint → Uri property + Uri.TryCreate binding
public Uri? Endpoint { get; set; }

// After: string endpoint → string property + string.IsNullOrEmpty binding
public string? Endpoint { get; set; }

// url endpoint still produces Uri as expected
public Uri? Endpoint { get; set; }

// Named string endpoint (fullyQualifiedNamespace: string) → string property
public string? FullyQualifiedNamespace { get; set; }
Original prompt

This section details on the original issue you should resolve

<issue_title>Handle String Endpoint Client Params in ClientSettings</issue_title>
<issue_description>Consider a client with a string client parameter as below:

@server(
  "https://{fullyQualifiedNamespace}",
  "The Schema Registry service endpoint.",
  {
    @doc("The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'.")
    fullyQualifiedNamespace: string,
  }
)

This leads to a generated property in ClientSettings:

 public Uri FullyQualifiedNamespace { get; set; }

In this case, the type should not be Uri but string unless it's defined as so in the spec. We should always follow the wire type for endpoint params as well.</issue_description>

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.

…lways Uri

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 19, 2026
Copilot AI changed the title [WIP] Fix endpoint parameter type in ClientSettings fix: respect wire type for endpoint params in ClientSettings Mar 19, 2026
Copilot AI requested a review from jorgerangel-msft March 19, 2026 18:03
Copy link
Contributor

@jorgerangel-msft jorgerangel-msft left a comment

Choose a reason for hiding this comment

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

@copilot lets also add a test to validate the generated internal ctor when the endpoint param is a string or a uri

…ointProperty PropertyProvider, add TestData-based tests and constructor tests

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

Copilot AI commented Mar 19, 2026

@copilot lets also add a test to validate the generated internal ctor when the endpoint param is a string or a uri

Done in 82a38d4. Added TestSettingsConstructor_WithStringEndpoint and TestSettingsConstructor_WithUrlEndpoint that validate the settings constructor on ClientProvider — existence, public modifier, this() initializer, argument count, and that the endpoint argument references the Endpoint property.

Copy link
Contributor

@jorgerangel-msft jorgerangel-msft left a comment

Choose a reason for hiding this comment

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

@copilot lets also add a test case to validate the generated clientsettings when a client is defined like:

@server(
  "https://{fullyQualifiedNamespace}",
  "The Schema Registry service endpoint.",
  {
    @doc("The Schema Registry service endpoint, for example 'my-namespace.servicebus.windows.net'.")
    fullyQualifiedNamespace: string,
  }
)

…ctor + named string endpoint tests

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

Copilot AI commented Mar 19, 2026

@copilot lets also add a test case to validate the generated clientsettings when a client is defined like:

Added TestGeneratedSettings_WithNamedStringEndpoint that uses fullyQualifiedNamespace: string with serverUrlTemplate: "https://{fullyQualifiedNamespace}". It validates the property is string? (not Uri?) and the BindCore uses string.IsNullOrEmpty, with full TestData comparison. Done in 2ba3662.

…lid generated code

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@jorgerangel-msft jorgerangel-msft marked this pull request as ready for review March 19, 2026 19:49
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 19, 2026

Open in StackBlitz

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

commit: 46a68a4

@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit a4a9e74 Mar 19, 2026
25 checks passed
@jorgerangel-msft jorgerangel-msft deleted the copilot/handle-string-endpoint-params branch March 19, 2026 21:03
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.

Handle String Endpoint Client Params in ClientSettings

3 participants