Skip to content

Commit 204ebad

Browse files
authored
feat: generate type-safe event publishers from AsyncAPI specs (#1320)
* feat: generate type-safe event publishers from AsyncAPI specs Add a Go code generator (tools/gen-event-publishers/) that reads AsyncAPI 3.0.0 YAML specs and generates typed event publisher packages in gen/events/. Each generated Publisher wraps OutboxPublisher with methods that accept the correct proto event type, topic, and event type string, eliminating string-based configuration errors. The generator validates proto types against actual .proto files, skipping services whose proto definitions are not yet available (audit, financial-accounting, market-information). Generated packages: current_account (4 events), internal_account (2), party (3), payment_order (7), position_keeping (9), reconciliation (6). Also adds `make gen-event-publishers` Makefile target. * fix: follow explicit $ref chain in event publisher generator Resolve message-to-schema mapping through the explicit AsyncAPI $ref chain (message -> component message -> payload schema) instead of assuming message keys match schema names directly. Extract channel message resolution into resolveChannelEvents to reduce cognitive complexity. Iterate channel messages in sorted order for deterministic output regardless of Go map iteration order. Also add gen-event-publishers to Makefile help target. * fix: clean stale gen/events packages before regeneration Remove the output directory before generating publishers so that removed or renamed AsyncAPI specs do not leave orphaned packages. * fix: fail fast on spec errors and add diagnostic warnings Fail with log.Fatalf instead of silently skipping when an AsyncAPI spec file has read or parse errors. Add WARN log messages when $ref chains resolve to unknown channels or component messages to surface spec drift. --------- Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 142368f commit 204ebad

8 files changed

Lines changed: 1364 additions & 1 deletion

File tree

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ GOMOD=$(GOCMD) mod
3232
GOGET=$(GOCMD) get
3333
GOFMT=$(GOCMD) fmt
3434

35-
.PHONY: all help build seed-dev seed-dev-build test lint clean proto proto-v1 proto-v2 proto-openapi proto-lint proto-breaking proto-descriptors docker deploy-local fmt tidy deps coverage install proto-validate proto-deps-update proto-deps-graph proto-plugins-info validate-tilt validate-semconv validate-sagas proto-jsonschema validate-manifest-jsonschema validate-manifests control-plane-ci test-control-plane migrate-diff-all migrate-diff-current migrate-diff-position migrate-apply-all migrate-status-all migrate-lint-all migrate-hash-all migrate-apply-orgs migrate-status-orgs docs generate-saga-docs swagger-split swagger-ui dev-up dev-down dev-clean asyncapi
35+
.PHONY: all help build seed-dev seed-dev-build test lint clean proto proto-v1 proto-v2 proto-openapi proto-lint proto-breaking proto-descriptors docker deploy-local fmt tidy deps coverage install proto-validate proto-deps-update proto-deps-graph proto-plugins-info validate-tilt validate-semconv validate-sagas proto-jsonschema validate-manifest-jsonschema validate-manifests control-plane-ci test-control-plane migrate-diff-all migrate-diff-current migrate-diff-position migrate-apply-all migrate-status-all migrate-lint-all migrate-hash-all migrate-apply-orgs migrate-status-orgs docs generate-saga-docs swagger-split swagger-ui dev-up dev-down dev-clean asyncapi gen-event-publishers
3636

3737
# Default target
3838
all: help
@@ -87,6 +87,7 @@ help:
8787
@echo ""
8888
@echo "Documentation targets:"
8989
@echo " make generate-saga-docs - Generate Markdown and JSON Schema docs for saga handlers"
90+
@echo " make gen-event-publishers - Generate typed event publishers from AsyncAPI specs"
9091
@echo ""
9192
@echo "API Explorer targets:"
9293
@echo " make swagger-split - Split monolithic swagger into per-service files"
@@ -496,6 +497,10 @@ asyncapi:
496497
@./scripts/gen-asyncapi.sh
497498
@echo "AsyncAPI specs generated in api/asyncapi/"
498499

500+
## gen-event-publishers: Generate typed event publishers from AsyncAPI specs
501+
gen-event-publishers:
502+
@$(GOCMD) run ./tools/gen-event-publishers
503+
499504
## validate-manifests: Validate example manifests against protobuf schema, CEL, and Starlark
500505
validate-manifests:
501506
@echo "Validating example manifests..."

gen/events/current_account/publisher.go

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/events/internal_account/publisher.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/events/party/publisher.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)