mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
* fix(apigateway): only emit the greedy path parameter for greedy resources
REST (V1) proxy events carried a "proxy" key in pathParameters on every
request, not just for greedy resources. The value came from the controller's
own JAX-RS binding - the class is mounted at @Path("/{proxy: .*}"), so
`proxy` is non-empty for every request regardless of which API Gateway
resource matched.
AWS emits pathParameters.proxy only when the matched resource itself declares
a greedy parameter. For /datasets/{datasetId} it sends {"datasetId": "..."}
and nothing else. Integrations that validate the event against a strict
schema (JSON Schema additionalProperties: false) therefore rejected every
request to a parameterised resource, which made every findOne/updateOne/
deleteOne style route unusable behind such an integration.
The two meanings of "proxy" coincide only for a root-level /{proxy+}
resource, which is why this went unnoticed: that is the shape the code was
originally written for. extractPathParams already skips greedy params
deliberately, and the V2 builder derives them from the route key, so V1 was
the odd one out.
Replace the unconditional put with putGreedyPathParam, which:
- adds the parameter only when the matched resource declares a greedy
segment;
- takes the value from the remainder after the literal prefix, so
/files/{proxy+} matching /files/a/b/c yields "a/b/c" rather than the
whole request path; and
- reads the parameter name from the template, since {proxy+} is only the
conventional spelling and AWS permits any name.
The now-unused JAX-RS capture is dropped from the buildProxyEvent signature
so it cannot leak into the event again.
* fix(apigateway): route greedy resources named other than {proxy+}
AWS does not reserve the greedy path parameter name - "you can use any
string for the greedy path parameter name" - and /parent/{name+} matches
every descendant below that parent.
buildProxyEvent already reads the name from the template, but the REST
router still keyed on the literal {proxy+} in three places: the exclusion
in the template-match arm, the guard in the greedy-match arm, and the
parent-prefix extraction used by both that arm and its specificity sort.
A resource such as /assets/{rest+} therefore only half routed. It fell to
the template arm, where pathMatchesTemplate compares segment counts and
treats {rest+} as an ordinary single-segment wildcard, so /assets/foo
matched while /assets/img/logo.png - the whole point of a greedy resource
- matched nothing at all. A quick manual check passes, which is why the
unit test added with the previous commit stayed green: it calls
buildProxyEvent directly and never exercises routing.
Recognise a greedy segment by its trailing "+" rather than by name, via
greedyParentPrefix, and route on that. Only a terminal greedy segment
counts, matching AWS, where a greedy parameter is allowed solely as the
last segment of a resource path. Specificity is unchanged: exact beats
template beats greedy, and greedy resources still sort by longest parent
prefix.
extractPathParams already generalised on the trailing "+", so it needed no
change. putGreedyPathParam becomes greedyPathParam, returning a map like
its extractPathParams companion and sharing the same terminal-segment
detection instead of scanning for the first greedy part.
Tested through the real request path, per AGENTS.md: the new
ApiGatewayGreedyPathParameterIntegrationTest stands up /assets/{rest+}
with a MOCK integration and drives it over HTTP. Without this change its
multi-segment and deeply-nested cases fail while the single-segment case
passes, reproducing the half-routing exactly. ApiGatewayProxyMatchTest
adds five routing assertions for non-proxy greedy names, four of which
fail without it.
* fix(apigateway): emit the greedy path parameter to mapping templates too
The same rule the previous two commits applied to the Lambda proxy event
was wrong in the two mapping-template paths, in opposite directions.
invokeAwsIntegration built its pathParameters from the JAX-RS capture,
exactly as buildProxyEvent used to, so $input.params('proxy') and a
method.request.path.proxy mapping resolved on every request rather than
only for a greedy resource, and carried the whole request path instead of
the remainder after the prefix.
invokeMock had the opposite gap: it used extractPathParams alone, which
deliberately skips greedy parameters, so $input.params('proxy') was empty
for a greedy resource where AWS supplies the captured remainder.
Both now compose extractPathParams with greedyPathParam, matching
buildProxyEvent, so the three paths agree on what a matched resource
declares. AGENTS.md asks for compatibility to be checked across alternate
protocol paths; these are the alternates for this behaviour.
As with buildProxyEvent, the JAX-RS capture was invokeAwsIntegration's only
use of the proxy argument, so it is dropped from the signature rather than
left available to leak back in.
ApiGatewayGreedyPathParameterIntegrationTest now asserts the captured value
over HTTP and not merely the route: its MOCK response template echoes
$input.params('rest'), so the greedy value must arrive under the name the
template declares. All three assertions fail without this change.