Skip to content

Conversation

@mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Nov 17, 2025

Reason for this change

The current spec2cdk code generator (AstBuilder) is tightly coupled to aws-cdk-lib's specific structure, making it difficult to generate code for other targets like preview packages. We need a more flexible architecture that can support different library structures while maintaining the existing aws-cdk-lib generation.

Description of changes

This PR refactors the code generation architecture to separate concerns between generic library building and aws-cdk-lib-specific implementation:

Why LibraryBuilder base class?

  • Enables reuse of core generation logic across different library types (aws-cdk-lib, preview packages, etc.)
  • Provides extension points for customizing file patterns, import paths, and module structure
  • Makes the codebase testable and maintainable by reducing coupling

Why ServiceSubmodule abstraction?

  • Encapsulates all modules related to a service (resources, augmentations, metrics, interfaces) in one place
  • Simplifies tracking of cross-module dependencies and selective imports
  • Provides a cleaner API for the generation process

Key changes:

  • Extract LibraryBuilder base class with generic service submodule support
  • Create AwsCdkLibBuilder as specialized implementation for aws-cdk-lib
  • Introduce BaseServiceSubmodule to manage service-specific modules and imports
  • Move selective import logic from RelationshipDecider to ServiceSubmodule
  • Add TypeConverter.forMixin() for partial type definitions

Describe any new or updated permissions being added

None.

Description of how you validated changes

  • All existing tests pass
  • The refactoring preserves existing behavior and code generation output

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Nov 17, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 17, 2025 08:21
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 17, 2025
@mrgrain mrgrain force-pushed the mrgrain/chore/spec2cdk-li-builder branch 4 times, most recently from 5d0c245 to 414234a Compare November 17, 2025 08:47
* Output debug messages
* @default false
*/
readonly augmentationsSupport?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was an unused option that silently got ignored. Instead augmentations were always enabled.

…tion

Introduces a new LibraryBuilder base class to abstract the code generation
process for CDK libraries. This refactoring separates concerns between the
general library building logic and aws-cdk-lib-specific implementation.

Key changes:
- Create LibraryBuilder base class with generic service submodule support
- Extract AwsCdkLibBuilder as a specialized implementation
- Introduce ServiceSubmodule abstraction for better modularity
- Move selective imports logic to service-submodule
- Update TypeConverter to support partial type definitions for mixins
- Adjust import paths and file patterns configuration
@mrgrain mrgrain force-pushed the mrgrain/chore/spec2cdk-li-builder branch from 0d5b24a to 50d3abe Compare November 17, 2025 11:23
@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Nov 17, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 15494b1 into main Nov 17, 2025
18 of 19 checks passed
@mergify mergify bot deleted the mrgrain/chore/spec2cdk-li-builder branch November 17, 2025 12:49
@github-actions
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants