Skip to content

Name Java identifiers with engine naming - #40

Merged
eunomie merged 10 commits into
mainfrom
identifier-casing
Nov 21, 2026
Merged

eunomie merged 10 commits into
mainfrom
identifier-casing

Conversation

@vito

@vito vito commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Port of the identifier casing work (dagger/dagger#14501, reference implementation dagger/dagger#14680) to java-sdk.

Note

Rebased on main (a8ac904); stacked with #45, which moves the e2e checks to the engine that runs them and ports collections to filtered views; the engine-e2e floor and below-floor checks of this PR's CI are removed there, so this PR alone is red until the stack merges.

A module on the entrypoint targets v1.0.0-beta.28. The SDK module declares the floor v1.0.0-beta.26 (engineVersion), whose view spells introspectionSchemaJson. sdk-helpers is v1.0.12.

How the names are formatted

Generated Java names follow Java's conventions, as the engine formats them. There is no version gate: codegen always asks the engine, with Query.naming(version:).formatIdentifiers (engines from v1.0.0-beta.26). The Maven codegen plugin asks the engine directly:

  • Inside the SDK's Maven exec: the plugin POSTs to the nested session ($DAGGER_SESSION_PORT, $DAGGER_SESSION_TOKEN). The batched query has three aliases, CAMEL:CAPITALIZED, PASCAL:CAPITALIZED and SCREAMING_SNAKE:UPPERCASE, and always passes version: <the schema's __schemaVersion>, so the naming dictionary follows the schema and not the session's view.
  • Without a session: it asks through dagger query --var-json.
  • From a names file: a names.json beside a plan's schema, or daggerengine.names, can supply the names offline.
  • Failure: if the names can't be formatted, codegen fails with an error that says why. It never falls back to the schema's names.

Warning

This relies on undocumented engine behaviour. An exec started by a module on the legacy dang runtime carries no module context: withExecDynamicInputs only attaches one for v2 entrypoint modules. A nested-session request without client metadata headers is then served at engine.Version, the engine's own view.

What changes

Codegen plugin

FormattedNames and EngineQueries are new. Names are formatted like this:

name Java
members asJSON, withGPU, insecureSkipTLSVerify asJson(), withGpu(), insecureSkipTlsVerify
classes JSON, ID, LLM, JSONValue, HTTPState, ... Json, Id, Llm, JsonValue, HttpState, ...
enum constants PerSession, Gzip PER_SESSION, GZIP
  • The wire format is unchanged: selections, argument names, input keys, enum values and type names keep the schema's spelling.
  • Renamed classes carry @GraphQLType("…").
  • Enums whose constants are renamed implement GraphQLEnum, so they serialize and deserialize through their values. A value and its alias share one constant.
  • Renamed methods, with… setters, input accessors and enum constants keep their schema names as @Deprecated aliases. Interfaces keep them as default methods. A name the schema already spells the Java way gets no alias.
  • …Arguments classes keep their names.

Runtime

  • New classes: GraphQLType, GraphQLEnum, GraphQLEnums, GraphQLEnum{Serializer,Deserializer}.
  • Arguments sends a GraphQLEnum constant as its value.
  • QueryBuilder reads a returned enum back by its value.
  • JsonConverter.toJSON also converts enums inside lists and arrays. JSON-B skips an enum's class-level serializer for list elements.
  • ModuleDispatcher is generic over the JSON scalar class, which it can no longer name.

Annotation processor

  • Uses whichever of ID/JSON or Id/Json the SDK has, found by reflection.
  • Registers a class carrying @GraphQLType under its GraphQL name.
  • Emits FunctionCachePolicy.NEVER/PER_SESSION/DEFAULT when the SDK has them.
  • The generated Entrypoint passes JSON::from (or Json::from) to ModuleDispatcher.
  • The Dang entrypoint spells cache policies NEVER, PER_SESSION and DEFAULT, the only spellings engines from v1.0.0-beta.26 resolve.

Entrypoint dang.toml

The entrypoint's dang.toml has one writer, the one #44 added. This PR no longer adds a second writer, nor its logic that never moved an existing module.

Packager

unit-tests also generates and tests the SDK and the annotation processor at the engine's own view, which covers the engine-formatted names.

Breaking changes

  • Class renames can't be aliased:
    • ID→Id, JSON→Json, JSONValue→JsonValue, HTTPState→HttpState, SDKConfig→SdkConfig, WorkspaceSDK→WorkspaceSdk, and every LLM*→Llm*.
    • Dependency and client types are renamed the same way, e.g. HTTPClient→HttpClient.
    • Java can't alias a class, and JSON.java and Json.java would collide on case-insensitive file systems.
  • No core aliases at v1.0.0-beta.28: the API spells asJson and PER_SESSION, so the deprecated aliases asJSON() and FunctionCachePolicy.PerSession are no longer generated for core. Code that uses them moves to asJson() and PER_SESSION.
  • Renamed enum constants keep their schema spelling as @Deprecated static final fields. They are not constants: on a schema that spells PerSession, case PerSession: doesn't compile, name() returns PER_SESSION, and Enum.valueOf(…, "PerSession") throws.
  • Renamed members keep working as deprecated forwarders, but -Werror builds break.
  • ModuleDispatcher's signatures changed. It's internal and regenerated with the entrypoint, but every module's Entrypoint.java and sha256sums change once on the next dagger generate.

Tests

Ran on a v1.0.0-beta.28 engine:

  • packager:unit-tests: plugin, SDK and processor unit tests, plus the run at the engine's own view.
    • New: FormattedNamesTest, FormattedNamesCodegenTest, EngineQueriesTest and GraphQLEnumsTest. They cover a names file, the engine query (the nested session with basic auth and no client metadata, or the CLI), and the failure path (engine error, short answer, HTTP errors).
  • packager:generate:stale and templates:generate:stale.
  • The e2e entrypoint/* checks.

CI on this PR alone:

vito and others added 10 commits November 21, 2026 10:39
Add GraphQLType, which names the GraphQL type of a generated class
called apart from it (JsonValue for JSONValue), and GraphQLEnum, for
enums whose constants follow Java's convention (PER_SESSION) and
carry the schema value they stand for. Arguments sends such a
constant as its value, and QueryBuilder reads one back by value.

Nothing implements them yet: codegen does once a schema's names are
formatted by the engine.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
The SDK's core classes are named after the schema it was generated
from: ID and JSON, or Id and Json once the engine formats the names.
The hand-written runtime and the annotation processor compile against
whichever was generated, so neither may name them.

ModuleDispatcher now takes the JSON scalar class as a type parameter
and its from factory from the generated entrypoint. The processor
finds the ID and JSON classes, and the FunctionCachePolicy constants,
by reflection, and registers a class carrying @GraphQLType under that
type. The tests follow the SDK they are compiled with.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
On a schema with Query.formatIdentifiers (views from
v1.0.0-beta.21), Java names follow Java's conventions as the engine
formats them: members camelCase (asJson, withGpu), classes PascalCase
(Json, Id, Llm, JsonValue), enum constants SCREAMING_SNAKE
(PER_SESSION), with acronyms written as words. A schema without it
generates the same code as before, and the engine is never asked.

The names come from a names.json beside a plan's schema
(daggerengine.names for a single schema), or from the engine, with
the schema's __schemaVersion as the dictionary version. Codegen runs
in a Maven exec of the SDK module, which joins the session as a
nested client; a request without client metadata is served at the
engine's own view, which has formatIdentifiers whatever the SDK
module's pinned engineVersion is. Without a session it asks through
the dagger CLI. When the gate is on and the names can't be formatted,
codegen fails rather than generating the schema's names.

Renamed methods, setters, accessors and enum constants keep their
old names as deprecated aliases. Renamed classes carry @GraphQLType
and can't be aliased. Arguments classes keep their names.

The prebuilt plugin is rebuilt.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
unit-tests also generates and tests the SDK and the annotation
processor from the templates module's schema at the engine's version.
From v1.0.0-beta.21 that schema has Query.formatIdentifiers, so this
covers the engine-formatted names, formatted through the exec's
nested session; the existing run covers the module's own view.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
JSON-B applies an enum's class-level serializer to a field, but not
to an element of a list it serializes, so a function returning a
list of a renamed core enum sent the constants' names (PER_SESSION)
instead of their values (PerSession). Under formatted names,
JsonConverter.toJSON now replaces enum constants with their values in
collections and arrays too, through GraphQLEnums.values.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
The second test run generates into the target/ the first one filled,
and codegen leaves the classes formatted names rename (JSON.java,
...) in place, so they compiled beside Json.java.

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
Engines from v1.0.0-beta.26 format names only under Query.naming and
spell cache policies NEVER, PER_SESSION and DEFAULT. The SDK module
declares the floor, whose view spells introspectionSchemaJson.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
@eunomie
eunomie added this pull request to stack #46 November 21, 2026 13:40
@eunomie eunomie changed the title Name Java identifiers with engine naming from v1.0.0-beta.21 Name Java identifiers with engine naming Nov 21, 2026
@eunomie
eunomie marked this pull request as ready for review November 21, 2026 16:58
@eunomie
eunomie merged commit 663c31a into main Nov 21, 2026
8 of 11 checks passed
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.

2 participants