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

commonMain.aws.sdk.kotlin.services.resiliencehub.serde.CreateRecommendationTemplateOperationSerializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.resiliencehub.serde

import aws.sdk.kotlin.services.resiliencehub.model.CreateRecommendationTemplateRequest
import aws.sdk.kotlin.services.resiliencehub.model.RenderRecommendationType
import aws.sdk.kotlin.services.resiliencehub.model.TemplateFormat
import aws.smithy.kotlin.runtime.client.idempotencyTokenProvider
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.url
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
import aws.smithy.kotlin.runtime.serde.json.JsonSerialName
import aws.smithy.kotlin.runtime.serde.json.JsonSerializer
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct


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

        builder.url {
            path.encoded = "/create-recommendation-template"
        }

        val payload = serializeCreateRecommendationTemplateOperationBody(context, input)
        builder.body = HttpBody.fromBytes(payload)
        if (builder.body !is HttpBody.Empty) {
            builder.headers.setMissing("Content-Type", "application/json")
        }
        return builder
    }
}

private fun serializeCreateRecommendationTemplateOperationBody(context: ExecutionContext, input: CreateRecommendationTemplateRequest): ByteArray {
    val serializer = JsonSerializer()
    val ASSESSMENTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("assessmentArn"))
    val BUCKETNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("bucketName"))
    val CLIENTTOKEN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("clientToken"))
    val FORMAT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("format"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
    val RECOMMENDATIONIDS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("recommendationIds"))
    val RECOMMENDATIONTYPES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("recommendationTypes"))
    val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("tags"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ASSESSMENTARN_DESCRIPTOR)
        field(BUCKETNAME_DESCRIPTOR)
        field(CLIENTTOKEN_DESCRIPTOR)
        field(FORMAT_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(RECOMMENDATIONIDS_DESCRIPTOR)
        field(RECOMMENDATIONTYPES_DESCRIPTOR)
        field(TAGS_DESCRIPTOR)
    }

    serializer.serializeStruct(OBJ_DESCRIPTOR) {
        field(ASSESSMENTARN_DESCRIPTOR, input.assessmentArn)
        input.bucketName?.let { field(BUCKETNAME_DESCRIPTOR, it) }
        input.clientToken?.let { field(CLIENTTOKEN_DESCRIPTOR, it) } ?: field(CLIENTTOKEN_DESCRIPTOR, context.idempotencyTokenProvider.generateToken())
        input.format?.let { field(FORMAT_DESCRIPTOR, it.value) }
        field(NAME_DESCRIPTOR, input.name)
        if (input.recommendationIds != null) {
            listField(RECOMMENDATIONIDS_DESCRIPTOR) {
                for (el0 in input.recommendationIds) {
                    serializeString(el0)
                }
            }
        }
        if (input.recommendationTypes != null) {
            listField(RECOMMENDATIONTYPES_DESCRIPTOR) {
                for (el0 in input.recommendationTypes) {
                    serializeString(el0.value)
                }
            }
        }
        if (input.tags != null) {
            mapField(TAGS_DESCRIPTOR) {
                input.tags.forEach { (key, value) -> entry(key, value) }
            }
        }
    }
    return serializer.toByteArray()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy