Skip to content

chore(enum-updater): support adding manual static enum mappings #34441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

paulhcsun
Copy link
Contributor

Issue # (if applicable)

Closes #.

Reason for this change

Manual changes to the static-enum-mapping.json would be overwritten the next time the workflow was run.

Description of changes

Add a new file manual-enum-mapping.json that allows maintainers to add manual mappings that will be used over any matching mapping that the script calculates.

Manual mappings should be added in the form:

{
    "serviceName": {
      "CdkEnumName": {
        "cdk_path": "path/to/cdkEnum",
        "sdk_service": "serviceName",
        "sdk_enum_name": "AwsEnumThatWeWantThisToMapTo",
        "match_percentage": 1.0,
        "manual": true
      }
    }
}

For example:

{
    "ec2": {
      "VpcEndpointIpAddressType": {
        "cdk_path": "aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts",
        "sdk_service": "ec2",
        "sdk_enum_name": "IpAddressType",
        "match_percentage": 1.0,
        "manual": true
      }
    }
}

Description of how you validated changes

Manual + unit testing

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team May 13, 2025 01:06
@github-actions github-actions bot added the p2 label May 13, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 13, 2025
@paulhcsun paulhcsun marked this pull request as ready for review May 13, 2025 01:09
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 13, 2025
@@ -103,6 +104,16 @@ interface UnmatchedEnums {
};
}

export interface ManualMappingEntry extends StaticMappingEntry {
manual: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

would this always be true? what if user accidentally add a entry to the manual-enum-mapping.json but add it as false?
how does manual get used?

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 should always be true but the value doesnt actually matter. When creating the static mapping, we only check if an entry for the specific enum exists by the enum name, if so, we just use the entry in the manual mapping instead which would include this manual field.

Basically the manual field just exists so that we know a static mapping was manually updated when we look at the entry in static-enum-mapping.json.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this field from the manual mapping file and let the code logic add it.

sdk_service: "amplify",
sdk_enum_name: "OverrideManualEnum",
match_percentage: 1.0,
manual: true
Copy link
Contributor

Choose a reason for hiding this comment

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

what happen if you add it as false? would it still override?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we check for the enum by its name, not by whether or not manual == true.

if (!staticMapping[module]) {
staticMapping[module] = {};
}
staticMapping[module][enumName] = manualEnumMappings[module][enumName];
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the manual: true could be added here if it was not in the manual mapping file, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to add the manual: true here instead of having it specified in the manual overrides json file.

@@ -103,6 +104,16 @@ interface UnmatchedEnums {
};
}

export interface ManualMappingEntry extends StaticMappingEntry {
manual: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this field from the manual mapping file and let the code logic add it.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: ade53e1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants