Skip to content

Auto-generate ConfigurationSchema.json for JSON IntelliSense#10139

Open
Copilot wants to merge 25 commits intomainfrom
copilot/add-auto-generate-configuration-schema-json
Open

Auto-generate ConfigurationSchema.json for JSON IntelliSense#10139
Copilot wants to merge 25 commits intomainfrom
copilot/add-auto-generate-configuration-schema-json

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

  • Add WriteAdditionalFiles() virtual method to CodeModelGenerator
  • Create ConfigurationSchemaGenerator class in Microsoft.TypeSpec.Generator.ClientModel
  • Override WriteAdditionalFiles() in ScmCodeModelGenerator to invoke schema generation
  • Hook into CSharpGen.ExecuteAsync() to write additional output files
  • Add 19 unit tests for ConfigurationSchemaGenerator (all passing)
  • Verify all existing tests still pass
  • Code review feedback: Remove Azure-specific logic from base emitter
  • Code review feedback: Delete chronus changelog file
  • Run regeneration to generate ConfigurationSchema.json for test projects
  • Common definitions (credential, options) are inherited from the System.ClientModel base schema and referenced via $ref — not duplicated locally
  • Add local definitions for additional non-base types (e.g., enums, models used as custom option properties) referenced via $ref
  • Model options type inheritance: each client's options type is a named local definition that extends the base options via allOf (matching the Azure emitter pattern from azure-sdk-for-net#57548)
  • Re-run generation to update all ConfigurationSchema.json files
  • Update Check-GitChanges.ps1 to also detect new untracked files so the CI regen check catches newly generated files
  • Add test cases for options types with additional properties (string, integer, and multiple mixed types)
  • Add test case and support for options properties that contain model definitions (with properties exposed in local definitions)
  • Add test case for model type used as a constructor parameter (appears as top-level client property with $ref to local definition)
  • Verify ConfigurationSchema.json works end-to-end via local pack and JSON Schema draft-07 meta-validation
  • Use m is ModelProvider instead of !(m is EnumProvider) for precise type checking
  • Add null check for Path.GetDirectoryName result in WriteAdditionalFiles
  • Add TestData golden file validation for 3 representative tests
  • Fix CI: scope untracked file check to generator/ directory to avoid false positive on README.md
  • Remove $schema line from generated ConfigurationSchema.json output (not needed since the consuming tool already knows the schema version)
  • Update System.ClientModel dependency to 1.10.0 for both the generator itself and generated project scaffolding

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Add schema generation for appsettings.json IntelliSense when a client
library has ClientSettings. The schema includes well-known client names
under 'Clients' (SCM) or 'AzureClients' (Azure) sections, with $ref to
shared credential/options definitions and allOf for client-specific
option extensions.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/555ac5bb-bd9c-4d73-90ca-f2922cf55fa5
@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 25, 2026
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/555ac5bb-bd9c-4d73-90ca-f2922cf55fa5
Copilot AI changed the title [WIP] Add auto-generate ConfigurationSchema.json for JSON IntelliSense Auto-generate ConfigurationSchema.json for JSON IntelliSense Mar 25, 2026
Copilot AI requested a review from JoshLove-msft March 25, 2026 19:32
…rator

The base emitter should not contain Azure-specific code. Removed the
namespace-based Azure detection and made Generate() always use "Clients"
and "options" as defaults, with parameters allowing overrides by
derived emitters.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/78f8c1a0-1d00-4e19-89d1-e9090dc2aeab
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/7703f03f-8937-43a3-b716-e0e5f8090658
@JoshLove-msft
Copy link
Copy Markdown
Contributor

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 27, 2026

Open in StackBlitz

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

commit: 0a2c3bd

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

I hadn't run Generate.ps1 after adding the feature. Running it now generated 72 schema/ConfigurationSchema.json files across all test projects (Sample-TypeSpec + Spector). Committed in 2c0a31e.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/bin/astro.mjs build node s/.b�� tput-dir ../../w--llmstxt . .2_tmp_4499_0/no../../website/src/content/docs/docs/emitters/openapi3/reference --import @typespec/librar/home/REDACTED/work/typespec/typespec/packages/http-specs/node_modules�� --no-emit node /nod�� gen-extern-signature sh _modules/.bin/sh node scripts/buinode l/reference n/sh sh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@JoshLove-msft
Copy link
Copy Markdown
Contributor

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

I hadn't run Generate.ps1 after adding the feature. Running it now generated 72 schema/ConfigurationSchema.json files across all test projects (Sample-TypeSpec + Spector). Committed in 2c0a31e.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

But why didn't the Regen check step fail on the diff then?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

I hadn't run Generate.ps1 after adding the featur...

Check-GitChanges.ps1 uses git diff (line 18), which only detects modifications to tracked files. Since the ConfigurationSchema.json files were brand new (untracked), they were invisible to the diff check. The script would need to also check for untracked files (e.g., via git status --porcelain) to catch newly generated files that aren't yet checked in.

"type": "string"
},
"Credential": {
"$ref": "#/definitions/credential"
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.

@copilot where are the definitions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a BuildDefinitions() method that generates the definitions section with credential (authentication configuration with Type property) and options (base ClientPipelineOptions properties including NetworkTimeout and RetryPolicy). All $ref pointers now resolve correctly. Fixed in 27184ed.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot verify that the configurationschema works using local pack of the test project

Verified the ConfigurationSchema.json works:

  1. dotnet pack on Sample-TypeSpec succeeds — project builds cleanly with the schema file in the schema/ directory
  2. JSON Schema draft-07 meta-validation passes for all generated schemas (using Python jsonschema library)
  3. Structure validation confirmed:
    • All well-known clients have Credential ($ref#/definitions/credential) and Options ($ref → named local definition)
    • Options definitions use allOf to inherit from base options type
    • Enum types (e.g., clientType in Spector client-structure tests) are correctly defined with enum values
    • additionalProperties on the section allows custom-named instances
  4. Spector test projects with enums also pass validation (e.g., clientType with 5 known values)

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

The regen step didn't fail because Check-GitChanges.ps1 originally used only git diff, which doesn't detect new untracked files. This has been fixed — the script now also checks for untracked files via git ls-files --others --exclude-standard (fixed in be700ca).

@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project?

I hadn't run Generate.ps1 after adding the featur...

The Regen check step didn't fail because Check-GitChanges.ps1 only used git diff which detects changes to tracked files. Since the ConfigurationSchema.json files were brand new (untracked), they were invisible. This was fixed in be700ca — the script now also checks git ls-files --others --exclude-standard for untracked files.

Check-GitChanges

@copilot let's make that update

Already done in be700caCheck-GitChanges.ps1 now checks for both tracked modifications (git diff) and untracked files (git ls-files --others --exclude-standard).

// Search for the model provider in the output library
var modelProvider = CodeModelGenerator.Instance.OutputLibrary.TypeProviders
.SelectMany(t => new[] { t }.Concat(t.NestedTypes))
.FirstOrDefault(m => !(m is EnumProvider) && m.Type.Equals(modelType));
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.

should the condition check m is a ModelProvider instead of !(m is EnumProvider) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed to use m is ModelProvider in d0fd621.

- Use 'm is ModelProvider' instead of '!(m is EnumProvider)' for more
  precise type checking in GetJsonSchemaForModel
- Add null check for Path.GetDirectoryName result in WriteAdditionalFiles
  instead of using null-forgiving operator
- Add TestData golden file validation for 3 representative tests:
  Generate_ReturnsSchema_ForClientWithSettings,
  Generate_ConstructorParameter_IncludesModelDefinition,
  Generate_HandlesMultipleClients

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Use ReplaceLineEndings to ensure consistent LF line endings across
platforms and append trailing newline to match prettier expectations.
Regenerated all ConfigurationSchema.json files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft
Copy link
Copy Markdown
Contributor

@copilot CI is somehow failing on the git diff check on linux:

git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code -- ":(exclude)/mnt/vss/_work/1/s/packages/http-client-csharp/package.json" ":(exclude)/mnt/vss/_work/1/s/packages/http-client-csharp/package-lock.json"
Command completed (00:00:02.5868706)

git ls-files --others --exclude-standard -- /mnt/vss/_work/1/s/packages/http-client-csharp
Command completed (00:00:00.0424453)

Untracked files detected:
README.md

…itive on README.md

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/ff462cc0-505c-42c6-8027-7678fda9721b

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 30, 2026

@copilot CI is somehow failing on the git diff check on linux:

git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code -- ":(exclude)/mnt/vss/_work/1/s/packages/http-cli...

The untracked file check was scoped to the entire $packageRoot (packages/http-client-csharp), which picks up README.md at the package root. Scoped it to $packageRoot/generator instead, since that's where generated files (including ConfigurationSchema.json) live. Fixed in 50acbc4.

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/26d73adf-067b-48e0-b996-36827bf3f448

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft
Copy link
Copy Markdown
Contributor

@copilot we need to update the version of SCM that we use as dependency to 1.10.0. Do this for both the generated dep and the dep of the generator itself.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot we need to update the version of SCM that we use as dependency to 1.10.0. Do this for both the generated dep and the dep of the generator itself.

Updated in 010e432:

  • Packages.Data.props: System.ClientModel → 1.10.0
  • NewProjectScaffolding.cs: generated dependency → 1.10.0
  • All 72 test project .csproj files: → 1.10.0
  • Also bumped transitive deps required by SCM 1.10.0: Microsoft.Extensions.Configuration.Abstractions → 10.0.3, System.Memory.Data → 10.0.3


<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.9.0" />
<PackageReference Include="System.ClientModel" Version="1.10.0" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For standalone packages we probably need to add the targets file and the pack of that targets fine into the csproj?

For azure emitter this isn't needed central build system will take care of it, but as a standalone package you won't get what you think you are getting since no packing is happening.

JoshLove-msft and others added 3 commits March 30, 2026 18:34
- Generate .targets file alongside ConfigurationSchema.json in WriteAdditionalFiles
- Add PackItems support to CSharpProjectWriter for NuGet pack items
- Add pack items to NewProjectScaffolding for schema + .targets files
- Swap order: write additional files before project scaffolding so schema exists

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

5 participants