Skip to content

Fix codegen to ignore httpLabel on non-input shapes per Smithy spec#6789

Open
RanVaknin wants to merge 14 commits intomasterfrom
rvaknin/fix-codegen-locationUri
Open

Fix codegen to ignore httpLabel on non-input shapes per Smithy spec#6789
RanVaknin wants to merge 14 commits intomasterfrom
rvaknin/fix-codegen-locationUri

Conversation

@RanVaknin
Copy link
Copy Markdown
Contributor

@RanVaknin RanVaknin commented Mar 12, 2026

Context

Per the Smithy spec, httpLabel on non-input shapes "has no meaning and is simply ignored." However, AddShapes.findRequestUri() was throwing a ModelInvalidException when it found a shape with a URI bound member that wasn't a direct operation input.

When the shape isn't a direct operation input, it now returns empty instead of throwing (results in codegen ignoring this member). The existing validation for operations with a missing requestUri is unchanged.

Test coverage matrix

The following table shows whether a combination of location / shape has meaning in codegen or is ignored (member gets serialized in PAYLOAD):

Location On Input On Output On Error On Nested
URI pre-existing, honored added, ignored added, ignored added, ignored
QUERY_STRING pre-existing, honored added, ignored added, ignore added, ignored
HEADER pre-existing, honored added, honored added, honored added, ignored
HEADERS same path as HEADER same path as HEADER same path as HEADER added, ignored
STATUS_CODE added, ignored added, honored added, ignored added, ignored

@RanVaknin RanVaknin requested a review from a team as a code owner March 12, 2026 21:36
@RanVaknin RanVaknin added changelog-not-required Indicate changelog entry is not required for a specific PR no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required labels Mar 13, 2026
@RanVaknin RanVaknin force-pushed the rvaknin/fix-codegen-locationUri branch from dd6a8b4 to cbb38f4 Compare March 13, 2026 19:49
@RanVaknin RanVaknin changed the title Include shape name in REQUEST_URI_NOT_FOUND validation error message Fix codegen to ignore httpLabel on non-input shapes per Smithy spec Mar 13, 2026
MemberModel requiredMemberModel = requestShapeModel.findMemberModelByC2jName(queryParamName);

assertThat(requestShapeModel.getRequired()).contains(queryParamName);
assertThat(requiredMemberModel.getHttp().getLocation()).isEqualTo(Location.QUERY_STRING);
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.

why are we removing this assertion ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because it was asserting the buggy behavior. NestedQueryParameterOperation is not a direct operation input/output/errors.
I should have added an assert null instead (null would result in the default behavior of it being serialized to the payload instead)

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.

Thanks Ran

.getter(getter(NestedQueryParameterOperation::queryParamOne))
.setter(setter(Builder::queryParamOne))
.traits(LocationTrait.builder().location(MarshallLocation.QUERY_PARAM).locationName("QueryParamOne").build(),
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("QueryParamOne").build(),
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.

I see here the MarshallLocation of existing test case is getting changed , any reason on why the existing shape is getting changed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason as above, "location":"querystring" on a nested member that is not an input/output/errors should go in the payload.

.anyMatch(o -> allC2jShapes.get(o.getOutput().getShape()).equals(shape));
}

private boolean isDirectOperationShape(Shape shape, Map<String, Shape> allC2jShapes) {
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.

Nit: Can we rename this to isDirectInputOutputOrErrorShape

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.

Or maybe just isTopLevelShape?

@RanVaknin RanVaknin added this pull request to the merge queue Mar 26, 2026
@RanVaknin RanVaknin removed this pull request from the merge queue due to a manual request Mar 26, 2026
Copy link
Copy Markdown
Contributor

@joviegas joviegas left a comment

Choose a reason for hiding this comment

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

For the changes you discussed offline

.anyMatch(o -> allC2jShapes.get(o.getOutput().getShape()).equals(shape));
}

private boolean isDirectOperationShape(Shape shape, Map<String, Shape> allC2jShapes) {
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.

Or maybe just isTopLevelShape?

private boolean isDirectInputShape(Shape shape, Map<String, Shape> allC2jShapes) {
return builder.getService().getOperations().values().stream()
.filter(o -> o.getInput() != null)
.anyMatch(o -> allC2jShapes.get(o.getInput().getShape()).equals(shape));
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.

This probably isnt a big deal (but I ran into it in the Smithy POC...) - the equals method in shape is just a reference check. That is probably actually what we want here so its fine. But would be an issue if the shape itself was duplicated or something.

@RanVaknin RanVaknin force-pushed the rvaknin/fix-codegen-locationUri branch from d7b62c3 to 67931ac Compare March 26, 2026 22:01
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-not-required Indicate changelog entry is not required for a specific PR no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants