Unverified Commit 2dc9da06 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add "S3 preview" service + codegen updates (#398)

This diff adds the S3 model & fixes compilation / clippy related codegen issues. I altered the SDK ID to be "S3 Preview". This means that all the generated code includes
"preview" because until a number of other fixes land, requests to S3 won't actually work.
parent d0eafbcf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ plugins {
val smithyVersion: String by project

val sdkOutputDir = buildDir.resolve("aws-sdk")
val runtimeModules = listOf("smithy-types", "smithy-http", "smithy-http-tower", "protocol-test-helpers")
val runtimeModules = listOf("smithy-types", "smithy-xml", "smithy-http", "smithy-http-tower", "protocol-test-helpers")
val awsModules = listOf("aws-auth", "aws-endpoint", "aws-types", "aws-hyper", "aws-sig-auth", "aws-http")

buildscript {
+13309 −0

File added.

Preview size limit exceeded, changes collapsed.

+21 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import software.amazon.smithy.model.shapes.UnionShape
import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.model.traits.XmlFlattenedTrait
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.RustType
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
@@ -161,6 +162,7 @@ class XmlBindingTraitParserGenerator(protocolConfig: ProtocolConfig, private val
            return null
        }
        return RuntimeType.forInlineFun(fnName, "xml_deser") {
            Attribute.AllowUnusedMut.render(it)
            it.rustBlock(
                "pub fn $fnName(inp: &[u8], mut builder: #1T) -> Result<#1T, #2T>",
                outputShape.builderSymbol(symbolProvider),
@@ -188,22 +190,28 @@ class XmlBindingTraitParserGenerator(protocolConfig: ProtocolConfig, private val
    override fun errorParser(errorShape: StructureShape): RuntimeType {
        val fnName = errorShape.id.name.toString().toSnakeCase()
        return RuntimeType.forInlineFun(fnName, "xml_deser") {
            Attribute.AllowUnusedMut.render(it)
            it.rustBlock(
                "pub fn $fnName(inp: &[u8], mut builder: #1T) -> Result<#1T, #2T>",
                errorShape.builderSymbol(symbolProvider),
                xmlError
            ) {
                val members = errorShape.errorXmlMembers()
                if (members.isNotEmpty()) {
                    rustTemplate(
                        """
                    use std::convert::TryFrom;
                    let mut document = #{Document}::try_from(inp)?;
                    ##[allow(unused_mut)]
                    let mut error_decoder = #{xml_errors}::error_scope(&mut document)?;
                    """,
                        *codegenScope,
                        "xml_errors" to xmlErrors
                    )
                val members = errorShape.errorXmlMembers()
                    parseStructureInner(members, builder = "builder", Ctx(tag = "error_decoder", accum = null))
                } else {
                    rust("let _ = inp;")
                }
                rust("Ok(builder)")
            }
        }
@@ -373,6 +381,7 @@ class XmlBindingTraitParserGenerator(protocolConfig: ProtocolConfig, private val
                "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Shape}, #{XmlError}>",
                *codegenScope, "Shape" to symbol
            ) {
                Attribute.AllowUnusedMut.render(this)
                rustTemplate(
                    """
                    let mut builder = #{Shape}::builder();
@@ -380,7 +389,11 @@ class XmlBindingTraitParserGenerator(protocolConfig: ProtocolConfig, private val
                    *codegenScope, "Shape" to symbol
                )
                val members = shape.xmlMembers()
                if (members.isNotEmpty()) {
                    parseStructureInner(members, "builder", Ctx(tag = "decoder", accum = null))
                } else {
                    rust("let _ = decoder;")
                }
                withBlock("Ok(builder.build()", ")") {
                    if (StructureGenerator.fallibleBuilder(shape, symbolProvider)) {
                        rustTemplate(""".map_err(|_|{XmlError}::custom("missing field"))?""", *codegenScope)
+16 −1
Original line number Diff line number Diff line
@@ -192,6 +192,17 @@ class XmlBindingTraitSerializerGenerator(protocolConfig: ProtocolConfig) : Struc
        rust("scope.finish();")
    }

    /**
     * Dereference [input]
     *
     * Clippy is upset about `*&`, so if [input] is already referenced, simply strip the leading '&'
     */
    private fun autoDeref(input: String) = if (input.startsWith("&")) {
        input.removePrefix("&")
    } else {
        "*$input"
    }

    private fun RustWriter.serializeRawMember(member: MemberShape, input: String) {
        when (val shape = model.expectShape(member.target)) {
            is StringShape -> if (shape.hasTrait<EnumTrait>()) {
@@ -200,7 +211,7 @@ class XmlBindingTraitSerializerGenerator(protocolConfig: ProtocolConfig) : Struc
                rust("$input.as_ref()")
            }
            is NumberShape -> rust("$input.to_string().as_ref()")
            is BooleanShape -> rust("""if *$input { "true" } else { "false" }""")
            is BooleanShape -> rust("""if ${autoDeref(input)} { "true" } else { "false" }""")
            is BlobShape -> rust("#T($input.as_ref()).as_ref()", RuntimeType.Base64Encode(runtimeConfig))
            is TimestampShape -> {
                val timestampFormat =
@@ -271,6 +282,10 @@ class XmlBindingTraitSerializerGenerator(protocolConfig: ProtocolConfig) : Struc
                "Shape" to structureSymbol,
                *codegenScope
            ) {
                if (!members.isNotEmpty()) {
                    // removed unused warning if there are no fields we're going to read
                    rust("let _ = input;")
                }
                structureInner(members, Ctx.Element("writer", "&input"))
            }
        }