Feature/protobuf java payload generation#147
Merged
bascunansalvador merged 18 commits intoJun 18, 2026
Merged
Conversation
Introduce shared message header analysis so generated Spring Kafka producers and consumers can use typed header DTOs when AsyncAPI message headers are defined. The Spring Kafka model preparation now carries header type metadata through the analyzer, payload model, Java/Kotlin factories, and templates. Generated producer and consumer APIs now include typed header parameters for messages with headers, while no-header messages keep the existing simpler signatures. Producer templates now map non-null typed header values into Kafka record headers, and consumer templates expose the generated header type in handler signatures. Add tests covering header analysis, Java Spring Kafka generation, and Kotlin Spring Kafka generation so typed header imports, method signatures, and producer header mapping remain stable.
Feature/kafka client contract
f8cb7ae
into
feature/external-native-schema-files
1 check passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous implementation could preserve native Protobuf schemas as
.protoartifacts, and generated Spring Kafka clients could reference Protobuf payload types when the schema declared the right package information. However, the generator did not actually generate the Java Protobuf message classes itself.That meant the type-safe Protobuf Kafka path was incomplete. A generated producer or consumer could reference
com.example.protobuf.UserCreated, but the consuming project still had to run Protobuf code generation separately to make that class exist.For the proposed solution, native Protobuf generation now supports Java message source generation from Protobuf
schemaFormatpayloads. The generator writes the.protoschema artifact to the resource output directory and, by default, also runsprotocto generate Java Protobuf message sources into the Java source output directory.This keeps the Protobuf payload model contract-driven. A native Protobuf AsyncAPI schema can now produce both the native schema artifact and the Java message type that Spring Kafka APIs reference.
The Protobuf schema must provide enough information for Java generation. It needs either
option java_package = "...";or a Protobufpackage ...;, it must enableoption java_multiple_files = true;, and it must contain a top-level message matching the AsyncAPI payload name. When those requirements are not met, the generator now fails with a domain-specific error explaining what is missing.The new behavior is exposed through the typed generator configuration and through all frontends.
For Maven, native Protobuf configuration now supports
generateJavaMessageTypes.For Gradle,
schemas.nativeProtobuf.generateJavaMessageTypesis available on the extension and wired into the task input.For CLI usage, the new option is
--schemas-native-protobuf-generate-java-message-types true|false.Java message generation defaults to
truewhen native Protobuf generation is enabled. Users can set it tofalsewhen they only want.protoartifacts.The generated Java message sources are routed as
JAVA_SOURCEartifacts, so they are written to the Java source output directory instead of the resource output directory. The.protofiles remain resource/schema artifacts.The implementation uses
protocthroughprotoc-jar, with an explicit Protobuf compiler version aligned with theprotobuf-javaruntime dependency. This is important because the older bundled/default compiler path does not work reliably on Apple Silicon.The test coverage was expanded in several layers.
Core generator tests now verify that native Protobuf generation returns
.protoartifacts and Java source artifacts when Java message generation is enabled. The generated Java sources are also compiled in tests against the current test classpath.A runtime-style Protobuf test was added as well. It loads the generated
UserCreatedclass, builds a message through the generated builder API, serializes it withtoByteArray(), parses it back withparseFrom(...), and verifies that the values survive the round trip. This gives us stronger confidence that the generated payload can become real Protobuf bytes.Output contract tests verify that generated Protobuf Java message sources are written to the Java source output directory while
.protoartifacts remain in the resource output directory.Configuration, factory, and planner tests verify that the new
generateJavaMessageTypesflag flows through the typed generator configuration into the planned native Protobuf artifact task.CLI, Maven, and Gradle tests now cover both the default behavior and the opt-out behavior. When native Protobuf generation is enabled by default,
UserCreated.javais generated. WhengenerateJavaMessageTypesis set tofalse, the.protofile is still generated, but the Java message source is not.The README and generator strategy documentation were updated to explain that native Protobuf generation now produces Java Protobuf message sources by default, while Kafka serializer/deserializer configuration and schema registry runtime wiring are still owned by the consuming application.