Skip to content

fix: preserve ANY routes when merging API definitions - #4004

Open
proton0210 wants to merge 2 commits into
aws:developfrom
proton0210:feature/sam-merge-definitions-any-method
Open

proton0210 wants to merge 2 commits into
aws:developfrom
proton0210:feature/sam-merge-definitions-any-method

Conversation

@proton0210

Copy link
Copy Markdown

Issue #, if available

Closes #4000. Thanks to @tiagohconte for the reproduction and proposed fix.

Description of changes

With MergeDefinitions: true, SAM writes ANY events under any instead of x-amazon-apigateway-any-method. It also drops generated routes when the inline paths is empty, null or missing.

Use the normalized method name for both lookup and write-back, and retain the paths dictionary in the merged body. Existing inline fields are preserved while SAM's generated integration takes precedence. Correcting the API body changes the deployment hash for affected templates.

Description of how you validated changes

  • make pr on Python 3.12: all checks passed, 4,672 tests passed, 95.63% coverage.
  • Eight new regression cases fail before the fix and pass afterward; a GET control passes in both versions.
  • Transform snapshots cover missing/null paths and an existing OpenAPI ANY operation with CORS in all three partitions.
  • An additional local audit passed 60 transform combinations covering method casing, Swagger/OpenAPI, five paths states, CORS and multiple events.

No live AWS deployment was run.

Checklist

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

@reedham-aws reedham-aws 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.

There is only one thing I'm concerned about in this PR: the existing case where a user has manually defined x-amazon-apigateway-any-method in the DefinitionBody while also providing an ANY method as part of the event source. Previously, that would have worked because of the value already in the definition body, while silently dropping what was in the event method. Now, the code is forcing the opposite and it's the manual DefinitionBody that is getting dropped.

I'm not quite sure what to make of this because it will change the behavior of existing templates, but at the same time that behavior was a bug. Theoretically, we can make the change, and then create an announcement mentioning that this might happen (not sure how many users would run into this).

@proton0210
proton0210 marked this pull request as draft October 21, 2026 06:07
@proton0210
proton0210 marked this pull request as ready for review October 21, 2026 06:09

This branch has not been deployed

No deployments
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.

MergeDefinitions: true merges Method: ANY API events as any instead of x-amazon-apigateway-any-method

2 participants