Skip to content

Include custom code properties in ConfigurationSchema.json and ClientSettings binding#10243

Merged
JoshLove-msft merged 4 commits intomicrosoft:mainfrom
JoshLove-msft:fix/schema-custom-options-properties
Apr 2, 2026
Merged

Include custom code properties in ConfigurationSchema.json and ClientSettings binding#10243
JoshLove-msft merged 4 commits intomicrosoft:mainfrom
JoshLove-msft:fix/schema-custom-options-properties

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

@JoshLove-msft JoshLove-msft commented Apr 1, 2026

Problem

The ConfigurationSchemaGenerator, ClientOptionsProvider config constructor, and ClientSettingsProvider only discover properties from the TypeSpec input model (BuildProperties()). Hand-written properties added via partial classes (e.g., Audience on ConfigurationClientOptions in Azure.Data.AppConfiguration) are silently dropped when:

  • The JSON schema is regenerated
  • The configuration section constructor binds values
  • The settings BindCore method binds values

This was discovered via Azure/azure-sdk-for-net#57682 where bumping the emitter version caused the Audience property to disappear from the generated ConfigurationSchema.json.

Fix

ConfigurationSchemaGenerator

  • BuildOptionsSchema: After collecting generated properties, also merges public properties from clientOptions.CustomCodeView?.Properties
  • BuildClientEntry: After collecting generated required params, discovers custom constructor parameters from client.CustomCodeView?.Constructors

ClientOptionsProvider

  • BuildConfigurationSectionConstructor: Now also binds custom code properties from the configuration section

ClientSettingsProvider

  • BuildProperties: Now includes custom constructor parameters as settings properties
  • BuildMethods (BindCore): Now binds custom constructor parameters from configuration

Tests

Added 5 new tests across 3 test classes:

  • ConfigurationSchemaGeneratorTests.Generate_IncludesCustomCodeOptionsProperties
  • ConfigurationSchemaGeneratorTests.Generate_IncludesCustomConstructorParameters
  • ClientOptionsProviderTests.TestConfigurationSectionConstructorBody_BindsCustomCodeProperties
  • ClientSettingsProviderTests.TestProperties_IncludesCustomConstructorParameters
  • ClientSettingsProviderTests.TestBindCoreMethod_BindsCustomConstructorParameters

All 91 related tests pass.

…nSchema.json

The ConfigurationSchemaGenerator now includes properties from CustomCodeView
on client options types, and custom constructor parameters from client types.

Previously, only properties from the TypeSpec input model were included in the
generated schema. Hand-written properties added via partial classes (e.g.,
Audience on ConfigurationClientOptions) were silently dropped when the schema
was regenerated.

Changes:
- BuildOptionsSchema: merges CustomCodeView properties with generated ones
- BuildClientEntry: discovers custom constructor parameters from CustomCodeView
- Added tests for both scenarios with custom code compilation

Co-authored-by: Copilot <223556219+Copilot@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 Apr 1, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 1, 2026

Open in StackBlitz

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

commit: d0464ab

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

No changes needing a change description found.

JoshLove-msft and others added 2 commits April 1, 2026 15:33
…constructors

Apply the same custom code property discovery to:
- ClientOptionsProvider.BuildConfigurationSectionConstructor: binds custom
  code properties from configuration section
- ClientSettingsProvider.BuildProperties: includes custom constructor params
  as settings properties
- ClientSettingsProvider.BuildMethods (BindCore): binds custom constructor
  params from configuration section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- ClientOptionsProviderTests: verify config section constructor binds
  custom code properties (e.g., Audience from partial class)
- ClientSettingsProviderTests: verify custom constructor parameters
  appear in settings properties and BindCore method

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft changed the title Include custom code properties and constructor params in Configuratio… Include custom code properties in ConfigurationSchema.json and ClientSettings binding Apr 1, 2026
…andard types

- Move knownProps HashSet allocation inside the custom constructors null
  check to avoid unnecessary allocation (PR feedback from jorgerangel-msft)
- Add IsStandardParameterType helper to filter out credential types
  (AuthenticationTokenProvider), endpoint types (Uri), and options types
  from custom constructor parameter discovery
- Compare by both type equality and name to handle Roslyn vs typeof
  CSharpType mismatch

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft added this pull request to the merge queue Apr 2, 2026
Merged via the queue into microsoft:main with commit 978bb9f Apr 2, 2026
29 checks passed
@JoshLove-msft JoshLove-msft deleted the fix/schema-custom-options-properties branch April 2, 2026 00:46
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