Skip to content

refactor(apigatewayv2): split resolve_action by endpoint shape#335

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+apigatewayv2-splits
Apr 13, 2026
Merged

refactor(apigatewayv2): split resolve_action by endpoint shape#335
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+apigatewayv2-splits

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 13, 2026

Summary

`resolve_action` was a single 107-line match that enumerated 33 (Method, path-length, collection-name) combinations, each arm performing a `segs[N].clone()` for `api_id` and sometimes another `segs[4].clone()` for `resource_id`.

Collapse by resolving `api_id` / `resource_id` / `collection` once at the top of the function, and then dispatching to two smaller helpers:

  • `resolve_collection_action` handles the 4-segment `/v2/apis/{id}/{collection}` endpoints (POST creates, GET lists) for routes, integrations, stages, deployments, and authorizers.
  • `resolve_resource_action` handles the 5-segment `/v2/apis/{id}/{collection}/{resource-id}` endpoints (GET, PATCH, DELETE) for the same five collections.

`resolve_action` itself is now a 30-line outer match that only decides which sub-helper to consult and wraps the result with the shared `api_id` / `resource_id` it already computed. The total number of `segs` clones drops from ~33 to 2 (the upfront `Option` bindings). No behavior change.

Test plan

  • `cargo fmt`
  • `cargo clippy --workspace --all-targets -- -D warnings`
  • `cargo test -p fakecloud-apigatewayv2` (17 passed)

Summary by cubic

Refactors API Gateway v2 action resolution by splitting resolve_action into helpers based on endpoint shape. Reduces duplication and string clones; behavior is unchanged.

  • Refactors
    • Compute api_id, resource_id, and collection once at the top.
    • Add resolve_collection_action for /v2/apis/{id}/{collection} (POST create, GET list).
    • Add resolve_resource_action for /v2/apis/{id}/{collection}/{resource-id} (GET, PATCH, DELETE).
    • Shrinks the main match from ~107 lines to ~30 and cuts per-branch clones from ~33 to 2 upfront bindings.
    • All existing tests pass.

Written for commit 750a872. Summary will update on new commits.

resolve_action was a single 107-line match that enumerated 33
(Method, path-length, collection-name) combinations, each arm
performing a segs[N].clone() for api_id and sometimes another
segs[4].clone() for resource_id.

Collapse by resolving api_id / resource_id / collection once at
the top of the function, and then dispatching to two smaller
helpers:

- resolve_collection_action handles the 4-segment
  /v2/apis/{id}/{collection} endpoints (POST creates, GET lists)
  for routes, integrations, stages, deployments, and authorizers.
- resolve_resource_action handles the 5-segment
  /v2/apis/{id}/{collection}/{resource-id} endpoints (GET, PATCH,
  DELETE) for the same five collections.

resolve_action itself is now a 30-line outer match that only
decides which sub-helper to consult and wraps the result with the
shared api_id / resource_id it already computed. The total number
of segs clones drops from ~33 to 2 (the upfront Option<String>
bindings). No behavior change.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@vieiralucas vieiralucas merged commit 77c0bc5 into main Apr 13, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup+apigatewayv2-splits branch April 13, 2026 02:23
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.

1 participant