Skip to content

fix(ssdk): route on path and method only, not required query params#1917

Open
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
TrevorBurnham:fix/ssdk-required-httpquery-routing
Open

fix(ssdk): route on path and method only, not required query params#1917
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
TrevorBurnham:fix/ssdk-required-httpquery-routing

Conversation

@TrevorBurnham
Copy link
Copy Markdown
Contributor

Fixes #1840

Description of changes:

When a Smithy operation has a @required @httpQuery parameter, the generated SSDK throws UnknownOperationException instead of ValidationException when the parameter is missing from the request.

Root cause

The codegen emits required @httpQuery members as { type: 'query' } segments in the UriSpec passed to HttpBindingMux. During routing, UriSpec.match() requires all query segments (including these) to be present in the request. When a required query param is missing, the mux fails to match any operation and the handler throws UnknownOperationException.

Meanwhile, the SSDK already generates proper RequiredValidator checks for these members, but that validation runs after routing, so it never executes when the query param is absent.

Fix

Two complementary changes ensure required query params are validated, not routed on:

@aws-smithy/server-common (runtime)

UriSpec.match() now filters query segments to only enforce query_literal types (URI query literals like ?action=Foo) during routing. query type segments (from @required @httpQuery members) are skipped — they don't participate in operation matching. The rank calculation was updated accordingly to only count query_literal segments for routing priority.

This also makes the runtime backward-compatible with already-generated code: existing SSDKs that include query segments in their mux will now simply ignore them during routing instead of using them to reject requests.

smithy-typescript-codegen (codegen)

HttpBindingProtocolGenerator.generateUriSpec() no longer emits required @httpQuery members as query segments. Only URI query literals (from httpTrait.getUri().getQueryLiterals()) are included. This means newly generated code won't include the unnecessary segments at all.

Before

GET /resource  →  UnknownOperationException

After

GET /resource  →  ValidationException (1 validation error: Missing value at '/id')

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Required @httpquery parameters were included in UriSpec query segments,
causing HttpBindingMux to reject requests missing those params with
UnknownOperationException instead of letting validation produce
ValidationException.

- UriSpec.match() now skips 'query' type segments during routing,
  only enforcing 'query_literal' segments for operation disambiguation
- UriSpec.rank only counts query_literal segments
- Codegen no longer emits required @httpquery members as query segments

Fixes smithy-lang#1840
@TrevorBurnham TrevorBurnham requested a review from a team as a code owner March 10, 2026 22:17
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.

SSDK returns UnknownOperationException when query parameter marked with @required and @httpQuery is not provided

1 participant