Skip to content

Commit

Permalink
Overrode renderContentTypeHeader in rest json 1
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Oct 12, 2023
1 parent a8d8206 commit b1cf170
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
val requestBindings = resolver.requestBindings(op)
val httpPayload = requestBindings.firstOrNull { it.location == HttpBinding.Location.PAYLOAD }
if (httpPayload != null) {
// TODO: this is replacing `renderExplicitHttpPayloadSerializer`
// explicit payload member as the sole payload
val memberName = httpPayload.member.defaultName()
val target = ctx.model.expectShape(httpPayload.member.target)
Expand All @@ -59,11 +60,21 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
}
// 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))
renderContentTypeHeader(ctx, op, writer, resolver)
}
}
}

override fun renderContentTypeHeader(
ctx: ProtocolGenerator.GenerationContext,
op: OperationShape,
writer: KotlinWriter,
resolver: HttpBindingResolver,
) {
val contentType = resolver.determineRequestContentType(op)
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
}

override fun structuredDataParser(ctx: ProtocolGenerator.GenerationContext): StructuredDataParserGenerator =
AwsJsonProtocolParserGenerator(this, supportsJsonNameTrait)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ open class RestXml : AwsHttpBindingProtocolGenerator() {
ctx: ProtocolGenerator.GenerationContext,
op: OperationShape,
writer: KotlinWriter,
resolver: HttpBindingResolver,
) {
val resolver = getProtocolHttpBindingResolver(ctx.model, ctx.service)
val contentType = resolver.determineRequestContentType(op)

if (!op.isBlobShape) {
contentType.let {
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
}
contentType.let {
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
}
}

Expand Down

0 comments on commit b1cf170

Please sign in to comment.