Skip to content

Commit 51d89f1

Browse files
fix: skip ConfigurationSchema.json generation for non-public clients (#10284)
ConfigurationSchemaGenerator was generating schemas for clients that had been made internal by visitors (e.g., management RestClientVisitor). ClientSettings was set during construction when DeclarationModifiers was still Public, and the generator only checked ClientSettings != null. Added a DeclarationModifiers.HasFlag(Public) check so only clients that are still public after visitors have run are included in the schema. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 34fbe57 commit 51d89f1

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ConfigurationSchemaGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal static class ConfigurationSchemaGenerator
3838
{
3939
var clientsWithSettings = output.TypeProviders
4040
.OfType<ClientProvider>()
41-
.Where(c => c.ClientSettings != null)
41+
.Where(c => c.ClientSettings != null && c.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public))
4242
.ToList();
4343

4444
if (clientsWithSettings.Count == 0)

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ConfigurationSchemaGeneratorTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ public void Generate_ReturnsNull_WhenNoClientsWithSettings()
4646
Assert.IsNull(result);
4747
}
4848

49+
[Test]
50+
public void Generate_ReturnsNull_WhenClientMadeInternalAfterConstruction()
51+
{
52+
var client = InputFactory.Client("TestService");
53+
var clientProvider = new ClientProvider(client);
54+
55+
Assert.IsNotNull(clientProvider.ClientSettings, "ClientSettings should not be null for individually-initialized client");
56+
57+
// Simulate a visitor changing the client from public to internal (e.g., management RestClientVisitor)
58+
var modifiers = clientProvider.DeclarationModifiers;
59+
modifiers &= ~TypeSignatureModifiers.Public;
60+
modifiers |= TypeSignatureModifiers.Internal;
61+
clientProvider.Update(modifiers: modifiers);
62+
63+
var output = new TestOutputLibrary([clientProvider]);
64+
var result = ConfigurationSchemaGenerator.Generate(output);
65+
Assert.IsNull(result, "Schema should not be generated for internal clients");
66+
}
67+
4968
[Test]
5069
public void Generate_ReturnsSchema_ForClientWithSettings()
5170
{

0 commit comments

Comments
 (0)