Skip to content

draft: move cds import --from asyncapi to plugin - #54

Merged
swaldmann merged 9 commits into
mainfrom
mv-asyncapi
Aug 13, 2026
Merged

swaldmann merged 9 commits into
mainfrom
mv-asyncapi

Conversation

@swaldmann

@swaldmann swaldmann commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Move cds import --from asyncapi to Plugin

New Feature

✨ This PR introduces the cds import --from asyncapi functionality as a native plugin capability within the @cap-js/asyncapi package. It adds a full AsyncAPI-to-CSN conversion pipeline, enabling users to import AsyncAPI specifications directly into CAP projects via the cds import command.

Changes

  • cds-plugin.js: New plugin entry point that registers both cds compile -2 asyncapi and cds import --from asyncapi handlers via the CDS plugin API. The import handler reads an AsyncAPI file, converts it to CSN using asyncapi2csn, and sets the input kind to odata.

  • index.js: Updated to export the new lib/import module alongside the existing lib/compile module.

  • lib/import/index.js: Entry point for the import library; validates and parses an AsyncAPI JSON document, then delegates to importAsyncAPI.

  • lib/import/importAsyncAPI.js: Orchestrates the conversion from an AsyncAPI document (via ParserContext) into a CSN object with proper meta, $version, and definitions structure.

  • lib/import/parserContext.js: Core parser class that extracts services, events, types, annotations, and property mappings from an AsyncAPI document. Handles nested objects/arrays, $ref resolution, enum values, defaults, and type conversions.

  • lib/import/utils.js: Provides validateAsyncAPI (structural validation) and getRegExpGroups (regex-based event name parsing for <namespace>.<businessObject>.<operation>[.<version>]).

  • lib/import/message.js: Defines error message constants used across the import library.

  • package.json: Added exports map (exposing ./cds-plugin), added cds-plugin.js to files, added @sap/cds-dk as a dev dependency, and added a comprehensive cds.schema definition covering AsyncAPI compile and import settings.

  • test/lib/import/importAsyncAPI.test.js: Unit tests that iterate over all input AsyncAPI files and compare the generated CSN output against expected .csn fixtures.

  • test/lib/import/input/*.json & test/lib/import/output/*.csn: Test fixtures covering base types, multiple services, and $ref resolution scenarios.

  • 🔄 Regenerate and Update Summary
PR Bot Information

Version: 1.29.18

  • Event Trigger: pull_request.opened
  • Correlation ID: 3f5673f0-9587-11f1-8409-e9821a4709b3
  • LLM: anthropic--claude-4.6-sonnet
  • File Content Strategy: Full file content
  • Summary Prompt: Default Prompt
  • Output Template: Default Template

@swaldmann
swaldmann requested a review from daogrady August 12, 2026 12:45
@swaldmann
swaldmann marked this pull request as ready for review August 12, 2026 12:45
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Move cds import --from asyncapi to Plugin

New Feature

✨ This PR introduces cds import --from asyncapi as a native plugin capability within the @cap-js/asyncapi package. It delivers a full AsyncAPI-to-CSN conversion pipeline, allowing users to import AsyncAPI specifications directly into CAP projects via the cds import command by simply declaring the package as a project dependency.

Changes

  • cds-plugin.js: New plugin entry point that registers both cds compile -2 asyncapi and cds import --from asyncapi handlers by monkey-patching cds.compile.to and cds.import.from. The import handler reads an AsyncAPI file, converts it to CSN via asyncapi2csn, and sets inputFileKind to odata.

  • index.js: Updated to export the new lib/import module alongside the existing lib/compile module.

  • lib/import/index.js: Entry point for the import library; parses and validates an AsyncAPI JSON document, then delegates to importAsyncAPI.

  • lib/import/importAsyncAPI.js: Orchestrates conversion from an AsyncAPI document (via ParserContext) into a CSN object with meta, $version, and definitions structure.

  • lib/import/parserContext.js: Core parser class extracting services, events, types, annotations, and property mappings from an AsyncAPI document. Handles nested objects/arrays, $ref resolution, enum values, defaults, and AsyncAPI-to-CDS type conversions.

  • lib/import/utils.js: Provides validateAsyncAPI (structural validation) and getRegExpGroups (regex-based event name parsing for <namespace>.<businessObject>.<operation>[.<version>]).

  • lib/import/message.js: Defines error message constants used across the import library.

  • package.json: Added exports map exposing ./cds-plugin, added cds-plugin.js to files, added @sap/cds-dk as a dev dependency, and added a comprehensive cds.schema definition covering AsyncAPI compile and import settings.

  • CHANGELOG.md: Added entry for the new plugin integration.

  • test/lib/import/importAsyncAPI.test.js: Unit tests iterating over all input AsyncAPI files and comparing generated CSN output against expected .csn fixtures.

  • test/lib/import/input/*.json & test/lib/import/output/*.csn: Test fixtures covering base types, multiple services, $ref resolution, and schema ref scenarios.


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.29.26

  • File Content Strategy: Full file content
  • Summary Prompt: Default Prompt
  • Correlation ID: aeafb3a0-964b-11f1-8468-de55f337548e
  • Event Trigger: pull_request.ready_for_review
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a solid new cds import --from asyncapi pipeline, but parserContext.js has several correctness issues: types from multiple events on the same service are silently discarded, object schemas without properties crash at runtime, falsy-but-valid path segments break $ref resolution, and known-but-invalid annotations leak into @AsyncAPI.Extensions despite the intention to omit them. Please address all flagged items before merging.

PR Bot Information

Version: 1.29.26

  • File Content Strategy: Full file content
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: aeafb3a0-964b-11f1-8468-de55f337548e
  • Event Trigger: pull_request.ready_for_review

Comment thread lib/import/parserContext.js
Comment thread lib/import/parserContext.js
Comment thread lib/import/parserContext.js
Comment thread lib/import/index.js
Comment thread lib/import/parserContext.js
Comment thread lib/import/parserContext.js
Comment thread lib/import/parserContext.js
@swaldmann

Copy link
Copy Markdown
Contributor Author

Ignoring all the potential fixes for now, this is just to move the code

Comment thread package.json Outdated
daogrady
daogrady previously approved these changes Aug 12, 2026

@daogrady daogrady left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the one export I am unclear on. Rest looks good, as it is just a shift from dk to this package. Thanks for the contribution!

@swaldmann
swaldmann enabled auto-merge (squash) August 12, 2026 15:35
@swaldmann
swaldmann requested a review from daogrady August 12, 2026 15:35
@swaldmann
swaldmann merged commit a5b5c40 into main Aug 13, 2026
6 checks passed
@swaldmann
swaldmann deleted the mv-asyncapi branch August 13, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants