Skip to content

Commit 6a0857b

Browse files
authored
fix: add content type header to empty body union rest xml payloads (#1073)
1 parent 72fbc22 commit 6a0857b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestXml.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator
99
import aws.sdk.kotlin.codegen.protocols.xml.RestXmlSerdeDescriptorGenerator
1010
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
1111
import software.amazon.smithy.codegen.core.Symbol
12-
import software.amazon.smithy.kotlin.codegen.core.*
12+
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
13+
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
14+
import software.amazon.smithy.kotlin.codegen.core.withBlock
1315
import software.amazon.smithy.kotlin.codegen.model.*
1416
import software.amazon.smithy.kotlin.codegen.rendering.protocol.*
1517
import software.amazon.smithy.kotlin.codegen.rendering.serde.*
1618
import software.amazon.smithy.model.Model
1719
import software.amazon.smithy.model.shapes.*
18-
import software.amazon.smithy.model.traits.*
20+
import software.amazon.smithy.model.traits.TimestampFormatTrait
21+
import software.amazon.smithy.model.traits.XmlNameTrait
1922
import kotlin.contracts.ExperimentalContracts
2023
import kotlin.contracts.contract
2124

@@ -34,6 +37,20 @@ open class RestXml : AwsHttpBindingProtocolGenerator() {
3437
override fun getProtocolHttpBindingResolver(model: Model, serviceShape: ServiceShape): HttpBindingResolver =
3538
HttpTraitResolver(model, serviceShape, ProtocolContentTypes.consistent("application/xml"))
3639

40+
// See: https://github.com/awslabs/aws-sdk-kotlin/issues/1050
41+
override fun renderContentTypeHeader(
42+
ctx: ProtocolGenerator.GenerationContext,
43+
op: OperationShape,
44+
writer: KotlinWriter,
45+
resolver: HttpBindingResolver,
46+
) {
47+
if (op.payloadIsUnionShape(ctx.model)) {
48+
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", resolver.determineRequestContentType(op))
49+
} else {
50+
super.renderContentTypeHeader(ctx, op, writer, resolver)
51+
}
52+
}
53+
3754
override fun structuredDataParser(ctx: ProtocolGenerator.GenerationContext): StructuredDataParserGenerator =
3855
RestXmlParserGenerator(this, defaultTimestampFormat)
3956

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGenerator.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ abstract class AwsHttpBindingProtocolGenerator : HttpBindingProtocolGenerator()
6767
"SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1",
6868
"SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery",
6969
"SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query",
70-
71-
// FIXME - missing Content-Type on restXml empty payloads, see https://github.com/awslabs/aws-sdk-kotlin/issues/1050
72-
"RestXmlHttpPayloadWithUnsetUnion",
7370
),
7471
)
7572

0 commit comments

Comments
 (0)