Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: xml content type header renderer to be overridable #977

Merged
merged 3 commits into from
Nov 14, 2023
Merged
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
@@ -21,7 +21,6 @@ import software.amazon.smithy.rulesengine.language.EndpointRuleSet
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait
import software.amazon.smithy.rulesengine.traits.EndpointTestCase
import software.amazon.smithy.rulesengine.traits.EndpointTestsTrait
import kotlin.streams.toList

/**
* Get all shapes of a particular type from the model.
@@ -193,6 +192,15 @@ val Shape.isSparse: Boolean
val Shape.isStreaming: Boolean
get() = hasTrait<StreamingTrait>()

/**
* Returns boolean indicating if operations explicitly set HTTP payload is a union
*/
fun OperationShape.payloadIsUnionShape(model: Model): Boolean {
val requestShape = model.expectShape<StructureShape>(input.get())
val payload = requestShape.findMemberWithTrait<HttpPayloadTrait>(model)?.targetOrSelf(model)
return payload is UnionShape
}

/**
* Test if a member targets an event stream
*/
Original file line number Diff line number Diff line change
@@ -12,7 +12,10 @@ import software.amazon.smithy.kotlin.codegen.core.*
import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes
import software.amazon.smithy.kotlin.codegen.lang.toEscapedLiteral
import software.amazon.smithy.kotlin.codegen.model.*
import software.amazon.smithy.kotlin.codegen.rendering.serde.*
import software.amazon.smithy.kotlin.codegen.rendering.serde.deserializerName
import software.amazon.smithy.kotlin.codegen.rendering.serde.formatInstant
import software.amazon.smithy.kotlin.codegen.rendering.serde.parseInstant
import software.amazon.smithy.kotlin.codegen.rendering.serde.serializerName
import software.amazon.smithy.kotlin.codegen.utils.getOrNull
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.knowledge.HttpBinding
@@ -267,7 +270,15 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
writer.write("val payload = #T(context, input)", opBodySerializerFn)
writer.write("builder.body = #T.fromBytes(payload)", RuntimeTypes.Http.HttpBody)
}
renderContentTypeHeader(ctx, op, writer, resolver)
}

protected open fun renderContentTypeHeader(
ctx: ProtocolGenerator.GenerationContext,
op: OperationShape,
writer: KotlinWriter,
resolver: HttpBindingResolver = getProtocolHttpBindingResolver(ctx.model, ctx.service),
) {
resolver.determineRequestContentType(op)?.let { contentType ->
writer.withBlock("if (builder.body !is HttpBody.Empty) {", "}") {
write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
Loading