Auto-generate ConfigurationSchema.json for JSON IntelliSense#10139
Auto-generate ConfigurationSchema.json for JSON IntelliSense#10139
Conversation
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
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
...sharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ConfigurationSchemaGenerator.cs
Outdated
Show resolved
Hide resolved
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
.chronus/changes/auto-generate-configuration-schema-json-2026-03-25.md
Outdated
Show resolved
Hide resolved
…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
|
@copilot why didn't the regen show a diff since we don't have a ConfigurationSchema.json checked in for the Test Project? |
commit: |
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/54e740be-2cdd-4b28-9516-7744e0fcf1dc Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
I hadn't run 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:
If you need me to access, download, or install something from one of these locations, you can either:
|
But why didn't the Regen check step fail on the diff then? |
|
| "type": "string" | ||
| }, | ||
| "Credential": { | ||
| "$ref": "#/definitions/credential" |
There was a problem hiding this comment.
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.
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b9941a61-2c64-4fc1-b403-d6313c2ce775 Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Verified the ConfigurationSchema.json works:
The regen step didn't fail because
The Regen check step didn't fail because
Already done in be700ca — |
| // 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)); |
There was a problem hiding this comment.
should the condition check m is a ModelProvider instead of !(m is EnumProvider) ?
There was a problem hiding this comment.
Yes, fixed to use m is ModelProvider in d0fd621.
...lient-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ScmCodeModelGenerator.cs
Outdated
Show resolved
Hide resolved
...generator/Microsoft.TypeSpec.Generator.ClientModel/test/ConfigurationSchemaGeneratorTests.cs
Show resolved
Hide resolved
- 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>
|
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>
|
@copilot CI is somehow failing on the git diff check on linux:
Untracked files detected: |
…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>
The untracked file check was scoped to the entire |
...p-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/schema/ConfigurationSchema.json
Outdated
Show resolved
Hide resolved
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>
|
@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. |
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/320087f6-326c-40aa-a821-d6efac9b11cb Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Updated in 010e432:
|
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="System.ClientModel" Version="1.9.0" /> | ||
| <PackageReference Include="System.ClientModel" Version="1.10.0" /> |
There was a problem hiding this comment.
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.
- 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>
WriteAdditionalFiles()virtual method toCodeModelGeneratorConfigurationSchemaGeneratorclass inMicrosoft.TypeSpec.Generator.ClientModelWriteAdditionalFiles()inScmCodeModelGeneratorto invoke schema generationCSharpGen.ExecuteAsync()to write additional output filescredential,options) are inherited from the System.ClientModel base schema and referenced via$ref— not duplicated locallydefinitionsfor additional non-base types (e.g., enums, models used as custom option properties) referenced via$refoptionsviaallOf(matching the Azure emitter pattern from azure-sdk-for-net#57548)Check-GitChanges.ps1to also detect new untracked files so the CI regen check catches newly generated filesdefinitions)$refto local definition)m is ModelProviderinstead of!(m is EnumProvider)for precise type checkingPath.GetDirectoryNameresult inWriteAdditionalFilesgenerator/directory to avoid false positive on README.md$schemaline from generated ConfigurationSchema.json output (not needed since the consuming tool already knows the schema version)💡 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.