Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
// explicit payload member as the sole payload
val memberName = httpPayload.member.defaultName()
val target = ctx.model.expectShape(httpPayload.member.target)
if (target is StructureShape) {
writer.withBlock("if (input.#L == null) {", "}", memberName) {
writer.withBlock("if (input.#L == null) {", "}", memberName) {
if (target is StructureShape) {
addImport(RuntimeTypes.Http.ByteArrayContent)
write("builder.body = #T(#S.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent, "{}")
}
// Content-Type still needs to be set for non-structured payloads
// https://github.com/awslabs/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
write("builder.headers.setMissing(\"Content-Type\", #S)", resolver.determineRequestContentType(op))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sdkVersion=0.14.3-SNAPSHOT
smithyVersion=1.17.0
smithyGradleVersion=0.5.3
# smithy-kotlin codegen and runtime are versioned together
smithyKotlinVersion=0.8.2
smithyKotlinVersion=0.8.3-SNAPSHOT

# kotlin
kotlinVersion=1.6.10
Expand Down
35 changes: 35 additions & 0 deletions services/s3/model/s3-tests.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,38 @@ apply PutObject @httpRequestTests([
}
}
])

apply CreateBucket @httpRequestTests([
{
id: "CreateBucketNoBody",
documentation: "Validates https://github.com/awslabs/aws-sdk-kotlin/issues/567 (empty body)",
protocol: "aws.protocols#restXml",
method: "PUT",
uri: "/mybucket",
host: "s3.us-west-2.amazonaws.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to be explicit or at least put a comment in here since we can't actually create this exact request in the real world (anything other than us-east-1 IIRC requires the location constraint which results in a body)

body: "",
forbidHeaders: ["Content-Type", "Content-Length"],
params: {
Bucket: "mybucket",
}
},
{
id: "CreateBucketWithBody",
documentation: "This test case validates https://github.com/awslabs/aws-sdk-kotlin/issues/567 (non-empty body)",
protocol: "aws.protocols#restXml",
method: "PUT",
uri: "/mybucket",
host: "s3.us-west-2.amazonaws.com",
body: "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LocationConstraint>us-east-2</LocationConstraint></CreateBucketConfiguration>",
headers: {
"Content-Type": "application/xml",
"Content-Length": "153"
},
params: {
Bucket: "mybucket",
CreateBucketConfiguration: {
LocationConstraint: "us-east-2"
}
}
}
])