Skip to content

sdk/dotnet: name identifiers with engine-formatted names - #14676

Draft
vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5h-dotnet-codegen
Draft

vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5h-dotnet-codegen

Conversation

@vito

@vito vito commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Part 5h/N of the stack splitting #14501 (identifier casing): the .NET SDK. Plan: #14501 (comment)

Refs #13668

Stacked on #14673. That PR has the shared cmd/codegen infra (codegen introspect --names-out) and engine-dev's IntrospectionNames.

What changes for .NET users

The source generator now names C# identifiers with the names the engine formats (Query.formatIdentifiers). They follow the .NET Framework Design Guidelines:

  • types, methods, properties and enum members are PascalCase;
  • parameters are camelCase;
  • acronyms are written like words.
schema name before now
type JSONValue / scalar JSON JSONValue / JSON JsonValue / Json
type LLM, LLMMessage, ... LLM, LLMMessage Llm, LlmMessage
field withMCPServer WithMcpserver WithMcpServer
argument insecureSkipTLSVerify insecureSkipTLSVerify insecureSkipTlsVerify
input field skipTLSVerify SkipTlsverify SkipTlsVerify
enum value NetworkProtocol.TCP TCP Tcp

Only C# identifiers change. Field names, argument names, input object fields, enum values and GraphQL type names are still sent to the engine exactly as the schema spells them.

Breaking changes

The .NET SDK maintainers need to decide on these:

  • Renamed types are a hard break, with no alias. C# can't export a type alias from a library (a using alias only applies to its own file). Code that names these 17 core types stops compiling:

    • JSON → Json, JSONValue → JsonValue
    • HTTPState → HttpState, SDKConfig → SdkConfig, WorkspaceSDK → WorkspaceSdk
    • every LLM* type: LLM, LLMContent, LLMContentBlock, LLMContentBlockInput, LLMContentBlockKind, LLMMessage, LLMMessageOrigin, LLMMessageOriginInput, LLMMessageOriginKind, LLMMessageRole, LLMSkill, LLMTokenUsage

    Code that only chains calls or uses var (dag.Llm()...) still compiles.

  • Named arguments with the old parameter spelling stop compiling where the method keeps its name. C# can't overload on parameter names, so there's no forwarder. In the core API this affects:

    • insecureSkipTLSVerify: → insecureSkipTlsVerify: (Container.From, Container.PublishAsync)
    • expectedRemoteSHA: → expectedRemoteSha: (GitRef.Push)

    Positional calls are unaffected.

  • Enum members are renamed (NetworkProtocol.TCP → Tcp) in 27 of the 28 core enums. The old members stay as [Obsolete] aliases with the same value, so existing code compiles with warnings. Behaviour still changes:

    • ToString() and Enum.GetNames return the new names.
    • Enum.Parse("TCP") resolves to the alias, which equals Tcp.
    • Two schema values that format alike (Gzip/GZIP in ImageLayerCompression) now share one member, which sends the first value.

    The values sent to the engine are unchanged. The enum's JSON converter is now GraphQLEnumConverter<T> instead of JsonStringEnumConverter<T>, and it maps each member to its [GraphQLValue] schema value.

  • Deprecated, still compiling:

    • A renamed method keeps its old name, with the old parameter names, as an [Obsolete] forwarder. On interfaces the forwarder is a default interface method.
    • Input object properties keep [Obsolete] getters under their old names.
    • Proposed lifetime for these: through 1.0.

What's in it

  • Runtime (Dagger.SDK/GraphQLEnum.cs): [GraphQLValue("TCP")], GraphQLEnum.ToValue/FromValue, and GraphQLEnumConverter<T>. Members without the attribute serialize by their names, as before.

  • Source generator:

    • Namer reads names.json next to introspection.json. It uses the formats PASCAL:CAPITALIZED and CAMEL:CAPITALIZED, as codegen introspect --names-out writes them.
    • Dagger.SDK.csproj adds names.json as an AdditionalFiles item when the file exists. A file that can't be parsed raises diagnostic DAG005.
    • Fallback: the old naming applies when names.json is missing (schemas from engines without formatIdentifiers), or when a name or format is missing from it. Older schemas generate exactly the same code.
    • CodeRenderer uses the Namer everywhere it used Formatter/GetVarName, and it renders the obsolete forwarders, old-name properties and enum aliases.
  • Dev module (.dagger/modules/dotnet-client-dev): test and install write names.json from engine-dev's IntrospectionNames. sourceGeneratorTest no longer starts an engine, since its tests don't need one.

  • Tests (IdentifierNamingTests):

    • naming with and without the names file;
    • enum members and values, obsolete forwarders, and fallbacks;
    • the source generator reading a names file and rejecting an invalid one;
    • compiling the whole core client against the runtime sources, with and without the names file.

    The fixtures (Fixtures/core-schema.json, core-names.json) are regenerated from docs/docs-graphql/schema.graphqls by Fixtures/generate.go, which calls engine/naming directly.

There's no committed generated client to update, because the source generator runs at build time. There's also no in-repo .NET module runtime, so there's no engineVersion bump here.

Not in it

  • Old names of renamed core fields (the RenamedCoreNames table: shortSHA, callID, FunctionCachePolicy values, ...) go with PR 6.

Testing

  • dotnet-client/source-generator-test (27 tests), dotnet-client/test (17 SDK tests against a from-source engine, with names.json) and dotnet-client/csharpier all pass.
  • core/integration has no .NET suite, so no integration tests ran.

vito added 3 commits October 14, 2026 02:52
Add [GraphQLValue] and GraphQLEnumConverter<T> to the runtime, so a
generated enum member can be named by .NET's convention (Tcp) while it is
sent and parsed as its schema value (TCP). Members without the attribute
go by their names, as before. GraphQLEnum.ToValue/FromValue do the
conversion for argument values and responses.

Signed-off-by: Alex Suraci <[email protected]>
Write the engine's formatted names (IntrospectionNames, in the formats the
source generator reads: PASCAL:CAPITALIZED and CAMEL:CAPITALIZED) next to
introspection.json in `test` and `install`, and include the source
generator's test fixtures in the workspace. sourceGeneratorTest runs
without an engine, since its tests need none.

The source generator ignores names.json until it learns to read it.

Signed-off-by: Alex Suraci <[email protected]>
The source generator reads a names.json next to introspection.json, as
`codegen introspect --names-out` writes it (formats PASCAL:CAPITALIZED and
CAMEL:CAPITALIZED), and names C# identifiers by the .NET guidelines:
types, methods, properties and enum members PascalCase, parameters
camelCase, acronyms written like words (JsonValue, Llm, WithMcpServer,
insecureSkipTlsVerify, NetworkProtocol.Tcp). The schema's own names still
go over the wire.

Without names.json, or for a name or format missing from it, the legacy
conversion applies, so older schemas generate the same code.

With formatted names:
- methods renamed by them keep their legacy names, with legacy parameter
  names, as [Obsolete] forwarders (default implementations on
  interfaces);
- input object properties keep [Obsolete] getters under legacy names;
- enum members carry their schema values with [GraphQLValue] and
  serialize with GraphQLEnumConverter<T>; values that format alike share
  one member, and the old members stay as [Obsolete] aliases.

Types have no alias: C# can't export one, so renamed types (JSON,
JSONValue, LLM*, HTTPState, SDKConfig, WorkspaceSDK) are a hard break.

Tests cover both paths, and compile the whole core client against the
runtime from fixtures of the core schema and its names, regenerated by
Fixtures/generate.go.

Signed-off-by: Alex Suraci <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Nov 6, 2026
@vito vito reopened this Nov 24, 2026
@vito vito removed the kind/stale label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant