Generator strategy
This page is for maintainers changing code generation in
asyncapi-generator-core, package
dev.banking.asyncapi.generator.core.generator. The user-level view is
How the generation pipeline works. The generation contexts
and their packages are listed in the
code conventions.
Input and entry point
Frontends call AsyncApiGenerator in the root package
dev.banking.asyncapi.generator.core: configure(settings) checks the settings
and returns a ConfiguredGeneration, which also tells the build plugins whether
sources or schemas are written and whether protoc runs. configure never
touches the file system, so the Gradle plugin can call it while it configures.
generate(inputSpec, generation, reportWarnings) checks the output paths on
disk, loads, validates and bundles the contract and hands it to
GenerationPipeline. Every failure reaches the frontend as an
AsyncApiGenerationException. requireInputFile lets a frontend report a
missing contract before any settings error, and inputFiles lists every file
of a contract for incremental builds.
The entry point exists for the CLI, Maven, and Gradle frontends. Core is not a library for other code, and the entry point has no compatibility promise between versions.
GenerationPipeline.generate(bundled, configuration) accepts only a
BundledAsyncApiDocument, which only the bundler can create, and a
GeneratorConfiguration built by GeneratorConfigurationFactory. Unbundled
or unvalidated documents therefore cannot reach generation. The pipeline
receives a ProtocProvider from its frontend; it never decides on its own how
protoc is obtained.
Configuration
GeneratorSettings mirrors the documented settings one to one and keeps their
raw values. The CLI, Maven, and Gradle only copy their own syntax into it; none
of them checks a setting itself.
The configuration package turns the settings into a typed
GeneratorConfiguration:
- It runs every check and reports each problem under the public name of the
setting, such as
modelPackageorclientConfig.topicParameterProperties. It fails at the first invalid setting. - Client settings are checked on every execution, including one without
clientPackage, because builds share them between executions. - Valid settings that have no effect become a
ConfigurationWarninginstead of being ignored silently.
Stages
Generation runs these stages in order. Each hands a complete result to the next.
- Plan (
plan). The configuration becomes an ordered list of tasks: the bundled document, models, Kafka key models, the Spring Kafka client, Avro Projection, native Avro, native Protobuf, and JSON Schema. Each task refers to the configuration value it plans, so a setting is defined once. - Prepare input (
catalog,normalizer,analyzer,messaging,input). The bundled document becomes the input every task shares: the schema catalog, the analyzed schemas, and the analyzed channels and messages. This runs when the first task needs it, so a request that only writes documents never analyzes schemas. - Check compatibility (
task,input, and the task's own package). Every task checks that its output can represent the contract, andPayloadFormatChecks(ininput) checks that every native payload has an output that handles it. These are target-specific failures; see the validation boundary. Every check runs before any task renders. - Render (
artifactand the format packages). Each task renders its artifacts in memory. Nothing is written until every task has rendered. A plan that renders nothing fails. - Write (
output). Artifacts are written under the output directory at their relative paths. Bundled documents go to their own file.
Rules
- Typed entry. Generation accepts only a
BundledAsyncApiDocument, so unbundled or unvalidated documents cannot reach it. - One decision, one place. Choices that affect the wire format, such as
enum constant names, property identifiers, and access annotations, are made
once in the language-neutral type model (
sourcemodel) or in shared JVM support (jvm). The Kotlin and Java emitters only choose syntax, so both produce the same JSON. When adding a feature, put the decision in shared code and only the syntax in the emitters. - Declared output kinds. Every task declares whether it writes
SOURCEorSCHEMAartifacts, and a task that renders another kind fails. The Maven and Gradle plugins read the plan to decide whether the output directory is compiled, packaged as resources, or both. - No partial render. A rendering failure leaves no earlier artifact in a destination.
- Safe write. The writer rejects two artifacts with the same destination, stages every file, skips files whose content is unchanged, and replaces the rest atomically where the file system allows. With a manifest, it removes files the execution no longer generates and never removes other files.
- Names are kept, not repaired. Invalid Avro names, reserved model names, and schema name collisions fail instead of being rewritten.
- Adding a task type needs a task subtype, a planner branch, a renderer,
and one branch in the task dispatch. Adding a language needs a
SourceLanguageentry and its source target.
Tests
Generated output is protected by ApprovalTests under
asyncapi-generator-core/src/test/resources/approvals/generator, and by the
system-test scenarios, which compile and run the generated code. Update an
approval only when output changes deliberately. See
Development setup.