All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.dataexchange.serde.SendApiAssetOperationSerializer.kt Maven / Gradle / Ivy

There is a newer version: 1.3.32
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.dataexchange.serde

import aws.sdk.kotlin.services.dataexchange.model.SendApiAssetRequest
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.operation.HttpSerializer
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.headers
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.text.encoding.PercentEncoding
import kotlin.text.encodeToByteArray


internal class SendApiAssetOperationSerializer: HttpSerializer.NonStreaming {
    override fun serialize(context: ExecutionContext, input: SendApiAssetRequest): HttpRequestBuilder {
        val builder = HttpRequestBuilder()
        builder.method = HttpMethod.POST

        builder.url {
            path.encoded = "/v1"
            parameters.decodedParameters(PercentEncoding.SmithyLabel) {
                input.queryStringParameters
                    ?.filterNot{ contains(it.key) }
                    ?.forEach { (key, value) ->
                        add(key, value)
                    }
            }
        }

        builder.headers {
            if (input.assetId.isNotEmpty() == true) append("x-amzn-dataexchange-asset-id", input.assetId)
            if (input.dataSetId.isNotEmpty() == true) append("x-amzn-dataexchange-data-set-id", input.dataSetId)
            if (input.method?.isNotEmpty() == true) append("x-amzn-dataexchange-http-method", input.method)
            if (input.path?.isNotEmpty() == true) append("x-amzn-dataexchange-path", input.path)
            if (input.revisionId.isNotEmpty() == true) append("x-amzn-dataexchange-revision-id", input.revisionId)
            input.requestHeaders?.forEach { (key, value) ->
                append("x-amzn-dataexchange-header-$key", value)
            }
        }

        if (input.body != null) {
            builder.body = HttpBody.fromBytes(input.body.encodeToByteArray())
        }
        if (builder.body !is HttpBody.Empty) {
            builder.headers.setMissing("Content-Type", "text/plain")
        }
        if (input.body == null) {
            builder.headers.setMissing("Content-Type", "text/plain")
        }
        return builder
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy