Fix message payload type generation for allOf schema references #291
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.
Fix message payload type generation for allOf schema references
Problem
Fixes #290
When generating Go code from AsyncAPI v2 specifications, message payloads that reference schemas using
allOf
composition were not generating proper type names. This resulted in compilation errors like:The generated code would fail to compile with: undefined: Payload
Root Cause
The issue was in the schema-name.tmpl template logic. Message payloads with allOf composition had both
.Type="object"
and.Reference
set. The templateprioritized .Type
over.Reference
, attempting to use{{ namify .Name }}
when.Name
was empty, resulting in missing type names.Solution
Reorganized the template logic in
schema-name.tmpl
to prioritize reference resolution:.ReferenceTo
and.Reference
cases nowprecede .Type
handlingallOf
references now resolve correctlyChanges
pkg/codegen/generators/v2/templates/schema_name.tmpl
: Reordered conditional logic to prioritizereferences
pkg/asyncapi/v2/schema.go
: Prevent name overwriting for schemas with referencespkg/codegen/generators/v2/templates/helpers.go
: Added reference extraction helper (unchanged)Testing
test/v2/issues/290/
following project guidelinesGenerated Code (After Fix)