Skip to content

Commit d7b62c3

Browse files
committed
Fix comments
1 parent cdc91d3 commit d7b62c3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/AddShapes.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,19 @@ private ParameterHttpMapping generateParameterHttpMapping(Shape parentShape,
311311

312312
ParameterHttpMapping mapping = new ParameterHttpMapping();
313313

314-
// Per the Smithy spec, HTTP binding traits are only honored on specific shape types.
315-
// When a trait is ignored, its locationName is also ignored so the member name is used as the wire name.
316-
// https://smithy.io/2.0/spec/http-bindings.html
317-
Location location = resolveLocation(parentShape, member, allC2jShapes);
318-
boolean locationIgnored = member.getLocation() != null && location == null;
314+
// Per the Smithy spec, HTTP binding traits are only honored on top-level shapes (direct operation
315+
// input/output/error). When a location trait is ignored, its locationName is also ignored so the member
316+
// name is used as the wire name. https://smithy.io/2.0/spec/http-bindings.html
317+
Location resolvedLocation = resolveLocation(parentShape, member, allC2jShapes);
318+
boolean locationIgnored = member.getLocation() != null && resolvedLocation == null;
319319

320320
Shape memberShape = allC2jShapes.get(member.getShape());
321321
String marshallLocationName = locationIgnored
322322
? memberName : deriveMarshallerLocationName(memberShape, memberName, member, protocol);
323323
String unmarshallLocationName = locationIgnored
324324
? memberName : deriveUnmarshallerLocationName(memberShape, memberName, member);
325325

326-
mapping.withLocation(location)
326+
mapping.withLocation(resolvedLocation)
327327
.withPayload(member.isPayload()).withStreaming(member.isStreaming())
328328
.withFlattened(isFlattened(member, memberShape))
329329
.withUnmarshallLocationName(unmarshallLocationName)
@@ -344,7 +344,7 @@ private Location resolveLocation(Shape parentShape, Member member, Map<String, S
344344
return isDirectInputShape(parentShape, allC2jShapes) ? location : null;
345345
case HEADER:
346346
case HEADERS:
347-
return isDirectOperationShape(parentShape, allC2jShapes) ? location : null;
347+
return isTopLevelShape(parentShape, allC2jShapes) ? location : null;
348348
case STATUS_CODE:
349349
return isDirectOutputShape(parentShape, allC2jShapes) ? location : null;
350350
default:
@@ -364,7 +364,7 @@ private boolean isDirectOutputShape(Shape shape, Map<String, Shape> allC2jShapes
364364
.anyMatch(o -> allC2jShapes.get(o.getOutput().getShape()).equals(shape));
365365
}
366366

367-
private boolean isDirectOperationShape(Shape shape, Map<String, Shape> allC2jShapes) {
367+
private boolean isTopLevelShape(Shape shape, Map<String, Shape> allC2jShapes) {
368368
return builder.getService().getOperations().values().stream()
369369
.anyMatch(o -> (o.getInput() != null && allC2jShapes.get(o.getInput().getShape()).equals(shape))
370370
|| (o.getOutput() != null && allC2jShapes.get(o.getOutput().getShape()).equals(shape))

codegen/src/test/java/software/amazon/awssdk/codegen/AddShapesTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,12 @@ void generateShapeModel_locationNameOnNestedShape_usesMemberNameForMarshalling()
109109
assertThat(inputShape.findMemberModelByC2jName("NestedHeaderMember").getHttp().getMarshallLocationName()).isEqualTo("NestedHeaderMember");
110110
}
111111

112+
@Test
113+
void generateShapeModel_locationNameOnTopLevelShape_honorsLocationName() {
114+
ShapeModel inputShape = intermediateModel.getShapes().get("QueryParameterOperationRequest");
115+
MemberModel member = inputShape.findMemberModelByC2jName("PayloadMemberWithCustomName");
116+
assertThat(member.getHttp().getLocation()).isNull();
117+
assertThat(member.getHttp().getMarshallLocationName()).isEqualTo("CustomWireName");
118+
}
119+
112120
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/model/service-2.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@
696696
"StatusCodeOnInput":{
697697
"shape":"Integer",
698698
"location":"statusCode"
699+
},
700+
"PayloadMemberWithCustomName":{
701+
"shape":"String",
702+
"locationName":"CustomWireName"
699703
}
700704
},
701705
"payload":"NestedQueryParameterOperation"

0 commit comments

Comments
 (0)