Repository navigation
fix(apigateway): return the v1 response shape an SDK parses (#529) - #565
Merged
Merged
Conversation
Every apigateway v1 response used PascalCase members under an "items" envelope. botocore matches a response key against the model's locationName case-sensitively, so nothing substrate returned parsed: `create-rest-api --query id` printed nothing and `get-rest-apis --query 'length(items)'` failed on a null, both at HTTP 200 with no error. Both halves were wrong. This corrects #529 as filed, which says the "items" envelope is already correct: every v1 collection member is named "items" but carries locationName "item", singular. Seven of the eight list handlers sent the plural and now send "item". GetStages is the exception — its model member is literally named "item", substrate already emitted it, and it is left unchanged, with a regression test, because a blanket rename would break the only v1 list an SDK could already read. Fixed as #528 fixed CloudWatch Logs: the eleven state types keep their PascalCase tags and are untouched, so state encoding is unchanged and recorded runs replay. Eleven response-only element types tagged from the model are projected from them, and none carries an AccountID, Region or APIId member at all, so the leak is closed structurally. The projection recurses, which needed a second fix to be observable: Resource declares a resourceMethods map and Method a methodIntegration, but methods and integrations were stored under separate state keys and never joined, so both members were permanently absent from every response. GetResource and GetMethod now report them at all three depths. From the model rather than the previous code: providerARNs keeps its capitalised acronym; UsagePlan reports no createdDate and BasePathMapping no domainName, neither being a member of its shape; unset optionals are omitted rather than sent as "" or null; no response invents a position token. GetStage's invokeUrl is substrate's own and no model declares it — kept, respelled from InvokeUrl, and harmless because botocore drops an undeclared key. Existing assertions in apigateway_plugin_test.go and apigateway_proxy_test.go are updated to the real wire keys. They were wrong today and passed anyway, because Go's json.Unmarshal matches case-insensitively; one carried a comment documenting the broken spelling as intended. Refs #529
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
scttfrdmn
added a commit
that referenced
this pull request
Aug 4, 2026
…567) Every apigatewayv2 response marshaled a PascalCase state struct onto the wire under an "Items" envelope. botocore matches a response key against the model's locationName case-sensitively, so nothing substrate returned parsed: `aws apigatewayv2 create-api --query ApiId` printed None and `get-apis --query 'length(Items)'` failed on a null. Substrate's own AccountID and Region went out on every response too. Same remedy as v1 (#565) and MSK: the state types keep their PascalCase tags and are untouched, so state encoding is unchanged and recorded runs replay. Nine response-only element types tagged from the botocore model are projected from them, and none declares an AccountID or Region member at all, so the leak cannot return through a field added later. The five list envelopes emit "items". Three members are now absent, from the model rather than the previous code: a route, integration, stage and API mapping declare no apiId (the API is a path parameter, not a member), a domain name reports the regional hostname where v2 puts it — domainNameConfigurations[].apiGatewayDomainName — rather than under v1's regionalDomainName spelling, and no response carries a nextToken. The CloudFormation v2 deploy handlers read these responses to set a resource's physical ID and now read the wire spellings; they worked before only because Go's json.Unmarshal is case-insensitive, which is also why ~10 existing assertions were wrong today and passed anyway. Those CloudFormation tests asserted only a resource count, so they now assert the physical ID itself. Verified through botocore's own parser against a live server: 28 checks that returned None or an empty parse now return values, and 0 leaked fields.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every API Gateway v1 response substrate sent was unparseable by an AWS SDK, and
nothing reported it.
aws apigateway create-rest-api --query idprinted an emptyline;
get-rest-apis --query 'length(items)'failed on a null. Both at HTTP 200with a well-formed body and no error.
The mechanism is #528's: the plugin marshaled its state struct onto the wire,
and botocore's rest-json parser matches a response key against the model's
locationName(falling back to the member name) case-sensitively. APascalCase key matches nothing, so the parse produces an empty result rather than
a failure. Feeding substrate's actual body to
create_parser('rest-json')turns{"Id":"a1","Name":"n1",…}into{}— not "some fields missing", nothing at all.It hid because Go's
json.Unmarshalmatches keys case-insensitively. Therequest side therefore works, every Go round-trip test passes, and a hand-written
assertion struct with the wrong tags stays green. Response-only fix.
Three corrections to #529 as filed
The
itemsenvelope was not already correct. The issue says it is. Every v1collection member is named
itemsbut carrieslocationName: "item", singular,so
{"items":[…]}parses to{}and{"item":[…]}parses. Seven of the eightlist handlers sent the plural; they now send
item.GetStagesis the exception and is deliberately unchanged. Its model member isliterally named
item, and substrate already emitteditem. A blanket renamewould have broken the only v1 list an SDK could already read. It keeps its key,
with a comment saying why and a regression test that goes red if someone
"corrects" it.
resourceMethodsandmethodIntegrationwere never populated at all. Not acasing problem — methods and integrations were stored under separate state keys and
never joined, so both members were structurally absent from every response no
matter how they were spelled. The recursive projection is only observable once that
join exists, so this PR adds it:
GetResource,GetResourcesandGetMethodnowreport all three depths.
The fix
The eleven state types in
apigateway_types.goare untouched. Their PascalCasetags are a persisted format that
MemoryStateManager.Snapshotround-trips andrecorded runs replay from — retagging them would silently change the format of
every recording. State encoding is unchanged, and a test asserts it by checking
the stored bytes still carry
Id/Name/RootResourceId/AccountID/Regionandthat the wire spellings do not appear there.
apigateway_wire.goadds eleven response-only element types tagged from thebotocore model, each with a
…Wire()projection, plus a genericapigwItemsOut[T]envelope. None of the wire types has an
AccountID,RegionorAPIIdmember atall — the leak is closed structurally, not by an
omitemptya future field couldstep around.
resourceWirerecurses intomethodWirewhich recurses intointegrationWire.MethodResponsesandIntegrationResponseshold whatever the caller PUT. They passthrough unchanged: those are the caller's own keys, not substrate's to rename.
Judgement calls, made from the model rather than the previous code
providerARNskeeps its capitalised acronym — that is what the model spells, anda mechanical lowerCamel transform would get it wrong.
UsagePlanreports nocreatedDateandBasePathMappingnodomainName.Neither is a member of its shape; substrate stores both, and a mapping's domain
is a path parameter of the request.
""ornull, following eachmodel member's optionality. A caller distinguishing absent from null is making a
real observation.
positiontoken. Substrate returns every element in onepage and honors no token; emitting one would invite a caller to page on nothing.
GetStage'sinvokeUrlis substrate's own member that no model declares. It iskept (a consumer reading the raw response uses it) and respelled from
InvokeUrl.It cannot break an SDK caller, because botocore drops a key the model does not
declare.
The updated existing assertions were wrong today and passed anyway
Ten sites in
apigateway_plugin_test.goand two inapigateway_proxy_test.goassert on PascalCase members and
itemsenvelopes. They passed because of thecase-insensitive
Unmarshalabove, not because the wire was right — one carried acomment documenting the broken spelling as intended ("RestAPIState uses json tag
Id(capital I)"). Updating them is part of the fix, not a weakening of thetests. The
GetRestApisdecode could not simply be retagged: it decoded into[]emulator.RestAPIState, which is the state type this PR is specifically keepingoff the wire, so it now decodes into a local struct with wire tags.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./....apigateway_wire_test.goadds 18 tests that decode intomap[string]anyand assertliteral wire keys — including one envelope test per list operation (a single
test over all eight would pass while seven were wrong), the
GetStagesregressiongate, the three-depth nested-projection test, byte-level negative assertions on
AccountID/Region/APIId, empty-list-is-a-list-not-null, and thestate-encoding-invariance test. Value assertions throughout, not key presence: a
Wire()that drops a member still emits its key holding Go's zero value.Mutation testing: 30 mutants, 30 CAUGHT. Including
getStages"fixed" toitems, two different list operations reverted independently, per-type tagreversions,
AccountIDandAPIIdadded back to a wire type, the nested projectionskipped at each of two levels, both joins removed, eight separate single-member
Wire()drops, twoomitemptydrops, the two non-model members added back, aninvented
position, and the state struct retagged. One survivor was found andfixed on the way: the API-key test compared
got["value"]againstcreated["value"], so dropping the member compared""with""— it now assertsnon-empty before comparing.
Live against
substrate server --address :4621, every call parsing a non-emptyresult where it returned empty before:
Raw body:
{"item":[{"id":"ojkaahjfpk","name":"prod-api","description":"a description","rootResourceId":"pnmjfhiipp","createdDate":"…"}]}.No other consumer of the v1 wire shape exists:
tagging_plugin.goreads statedirectly, and
cfn_resources_v19.goalready decodes lowerCamel and computes thestage invoke URL locally rather than reading it from the response.
Scope
v1 only. API Gateway v2 is the same defect and is the next PR —
aws apigatewayv2 create-api --query ApiIdstill returnsNonetoday. #529 covers v1, v2 and MSK, soit stays open until v2 lands; MSK was #564.
Refs #529