feat: add eventcatalog input type#365
Open
jonaslagoni wants to merge 4 commits intomainfrom
Open
Conversation
Adds inputType: 'eventcatalog' so codegen can read an EventCatalog directory directly. The loader picks one service via a new required 'service' field, follows its frontmatter, and routes generation through the existing AsyncAPI or OpenAPI pipeline. Native services (no spec file, only sends/receives) get a synthesized AsyncAPI 3.0 document so every existing preset works unchanged. - New loader stack at src/codegen/inputs/eventcatalog/ - Both-specs services require explicit specType disambiguation - Browser entry point rejects 'eventcatalog' (filesystem-bound) - 25 new unit tests + runtime spec + new docs page Closes #360
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for the-codegen-project canceled.
|
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.
Summary
Adds
inputType: 'eventcatalog'so codegen can read an EventCatalog directory directly. The loader picks one service via a new requiredservicefield, follows its frontmatter, and routes generation through the existing AsyncAPI or OpenAPI pipeline (or synthesizes an AsyncAPI 3.0 document for native services with no spec file). No per-generator branching is needed — every existing preset works for EventCatalog inputs.Closes #360.
Type of Change
Changes Made
New Files
src/codegen/inputs/eventcatalog/{index,parser,serviceLoader,eventLoader,types}.ts— full loader stackdocs/inputs/eventcatalog.md— input page covering 3 modes, native synthesis rules, both-specs disambiguation, remote URLs, examples, limitationstest/codegen/inputs/eventcatalog/{serviceLoader,eventLoader,parser}.spec.ts+ 5 fixture catalogs (asyncapi, openapi, native, both-specs, invalid)test/runtime/typescript/codegen-eventcatalog.mjs+test/inputs/eventcatalog.spec.ts+ runtime fixture catalogModified Files
src/codegen/types.ts—zodEventCatalogCodegenConfigurationadded; discriminated union extended to 4 armssrc/codegen/configurations.ts— eventcatalog dispatch arm; mutatesconfiguration.inputTypeto the effective spec type after loading so downstream generators see a familiar'asyncapi'/'openapi'discriminatorsrc/codegen/renderer.ts— narrowed inputType cast formodels/custom(the eventcatalog literal is gone by the time the renderer runs)src/codegen/errors.ts— widenedvalidTypesandexpectedTypeunionsrc/codegen/inputs/index.ts— re-export the new loadersrc/browser/generate.ts— explicit error path: filesystem-bound, not supported in browser bundlesrc/commands/init.ts—eventcatalogandjsonschemachoices added; new--serviceflag; conditional promptsrc/telemetry/events.ts—input_typeunion widenedexamples/eventcatalog-{asyncapi,openapi,native}/codegen.config.mjs— removed "PROPOSED" disclaimerstest/codegen/configurations.spec.ts— 5 new Zod validation teststest/runtime/typescript/package.json—generate:eventcatalog+test:eventcatalogscriptsdocs/{README,configurations,getting-started/README,telemetry,usage}.md— input list, cross-links, telemetry enum, CLI flag listingschemas/configuration-schema-0*.json— auto-regenerated with the new union armKey Implementation Details
Translation, not a fourth first-class input
The loader populates
asyncapiDocumentoropenapiDocumentonRunGeneratorContextand mutatescontext.configuration.inputTypeto the effective tag. Every existing generator-side switch (~30 files) keeps working unchanged — only the type/config/dispatch layer touches the new literal.Native-mode synthesis
Services with no
specificationsblock but withsends/receivesevents get a synthesized AsyncAPI 3.0 document: one channel per event id, payload from the event'sschema.json,action: 'send'forsends,action: 'receive'forreceives. This makes presets likechannelsandclientwork out-of-the-box without authoring a real AsyncAPI file.Both-specs services (disambiguation, not multiplexing)
If a service declares both
asyncapiPathandopenapiPath, the user must setspecType: 'asyncapi' | 'openapi'. Generating from both specs in one run is out of scope for v1 (would require running the renderer twice or per-generator dual-document support). Workaround documented: two configs, one with eachspecType.Frontmatter parsing
Used the existing
yaml@^2.8.0dep + a manual---split — no new dependency added.Testing
Unit Tests
✅ 638 passed, 1 skipped, 74 snapshots, 51 suites
src/codegen/inputs/eventcatalog/: 87–96% statementsBlackbox Tests
✅ 12/12 syntactic compilation tests pass
Runtime Generation
✅ All five
runtime:typescript:generateconfigs succeed:Manual Example Verification
✅ All three
examples/eventcatalog-*configs run end-to-end and produce code:eventcatalog-asyncapi→ 11 fileseventcatalog-openapi→ 33 fileseventcatalog-native→ 7 files (channels, client/NatsClient, OrderCreated/OrderShipped/OrderShippedCarrierEnum payloads)Build / Lint / Format
✅
npm run build— clean✅
npm run lint:fix— clean (max-warnings 0 + tsconfig.test.json typecheck)✅
npm run format— cleanRuntime NATS spec
The runtime spec at
test/runtime/typescript/test/inputs/eventcatalog.spec.tswas authored and type-checks against the generated NATS code. Executing it requiresnpm run runtime:services:start(Docker NATS), which CI handles.Documentation
docs/inputs/eventcatalog.mddocs/README.md— listed in Inputs indexdocs/getting-started/README.md— extended Input Types blurbdocs/configurations.md— new "Input Types" section with cross-linkdocs/usage.md— regenerated by oclif:--input-type=asyncapi|openapi|jsonschema|eventcatalog, new--serviceflagdocs/telemetry.md— input_type enum comment updatedBreaking Changes
None. All existing input types continue to work identically. The discriminated union is widened, not narrowed. No existing config field types changed.
Out of Scope (deferred follow-ups)
These are documented in the new docs page:
@eventcatalog/sdkintegration (we parse files directly)domains/andflows/traversaloriginalInputTypecapture — types already widened, but the runtime telemetry currently records the translated value after dispatch-site mutation. Easy follow-up.Checklist
tsconfig.jsonandtsconfig.test.json)Example
```javascript
// codegen.config.mjs
export default {
inputType: 'eventcatalog',
inputPath: './eventcatalog',
service: 'order-service',
language: 'typescript',
generators: [
{ preset: 'payloads', outputPath: './src/payloads' },
{ preset: 'channels', outputPath: './src/channels', protocols: ['nats'] },
{ preset: 'client', outputPath: './src/client', protocols: ['nats'] }
]
};
```
For an
order-servicedeclaringsends: [OrderCreated, OrderShipped]with no spec file, this produces a synthesized AsyncAPI document and generates NATS publish/subscribe channels + aNatsClientexactly as if the user had authored an AsyncAPI 3.0 document by hand.