Commit e0d52582 authored by Russell Cohen's avatar Russell Cohen
Browse files

Upgrade Smithy to 1.42

parent eff5a574
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.BlobShape
import software.amazon.smithy.model.shapes.CollectionShape
import software.amazon.smithy.model.shapes.IntEnumShape
import software.amazon.smithy.model.shapes.ListShape
import software.amazon.smithy.model.shapes.MapShape
import software.amazon.smithy.model.shapes.MemberShape
@@ -105,6 +106,7 @@ class BaseSymbolMetadataProvider(
            // This covers strings with the enum trait for now, and can be removed once we're fully on EnumShape
            // TODO(https://github.com/smithy-lang/smithy-rs/issues/1700): Remove this `is StringShape` match arm
            is StringShape -> RustMetadata(visibility = Visibility.PUBLIC)
            is IntEnumShape -> RustMetadata(visibility = Visibility.PUBLIC)

            else -> TODO("Unrecognized container type: $container")
        }
+11 −5
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ import software.amazon.smithy.model.shapes.BlobShape
import software.amazon.smithy.model.shapes.BooleanShape
import software.amazon.smithy.model.shapes.CollectionShape
import software.amazon.smithy.model.shapes.DocumentShape
import software.amazon.smithy.model.shapes.DoubleShape
import software.amazon.smithy.model.shapes.EnumShape
import software.amazon.smithy.model.shapes.FloatShape
import software.amazon.smithy.model.shapes.ListShape
import software.amazon.smithy.model.shapes.MapShape
import software.amazon.smithy.model.shapes.MemberShape
@@ -479,7 +481,11 @@ class PrimitiveInstantiator(private val runtimeConfig: RuntimeConfig, private va
                        )
                    }

                    is NumberNode -> write(data.value)
                    is NumberNode -> when (shape) {
                        is FloatShape -> rust("${data.value}_f32")
                        is DoubleShape -> rust("${data.value}_f64")
                        else -> rust(data.value.toString())
                    }
                }

                is BooleanShape -> rust(data.asBooleanNode().get().toString())
+20 −35
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import software.amazon.smithy.model.shapes.DocumentShape
import software.amazon.smithy.model.shapes.DoubleShape
import software.amazon.smithy.model.shapes.EnumShape
import software.amazon.smithy.model.shapes.FloatShape
import software.amazon.smithy.model.shapes.IntEnumShape
import software.amazon.smithy.model.shapes.IntegerShape
import software.amazon.smithy.model.shapes.ListShape
import software.amazon.smithy.model.shapes.LongShape
@@ -32,15 +31,13 @@ import software.amazon.smithy.model.shapes.ShortShape
import software.amazon.smithy.model.shapes.StringShape
import software.amazon.smithy.model.shapes.TimestampShape
import software.amazon.smithy.model.traits.DefaultTrait
import software.amazon.smithy.model.traits.EnumDefinition
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumMemberModel
import software.amazon.smithy.rust.codegen.core.util.UNREACHABLE
import software.amazon.smithy.rust.codegen.core.smithy.generators.PrimitiveInstantiator
import software.amazon.smithy.rust.codegen.core.util.dq
import software.amazon.smithy.rust.codegen.core.util.expectTrait
import software.amazon.smithy.rust.codegen.core.util.isStreaming
@@ -127,32 +124,7 @@ fun defaultValue(
    val unsupportedDefaultValueException =
        CodegenException("Default value $node for member shape ${member.id} is unsupported or cannot exist; please file a bug report under https://github.com/smithy-lang/smithy-rs/issues")
    when (val target = model.expectShape(member.target)) {
        is EnumShape, is IntEnumShape -> {
            val value = when (target) {
                is IntEnumShape -> node.expectNumberNode().value
                is EnumShape -> node.expectStringNode().value
                else -> throw CodegenException("Default value for shape ${target.id} must be of EnumShape or IntEnumShape")
            }
            val enumValues = when (target) {
                is IntEnumShape -> target.enumValues
                is EnumShape -> target.enumValues
                else -> UNREACHABLE(
                    "Target shape ${target.id} must be an `EnumShape` or an `IntEnumShape` at this point, otherwise it would have failed above",
                )
            }
            val variant = enumValues
                .entries
                .filter { entry -> entry.value == value }
                .map { entry ->
                    EnumMemberModel.toEnumVariantName(
                        symbolProvider,
                        target,
                        EnumDefinition.builder().name(entry.key).value(entry.value.toString()).build(),
                    )!!
                }
                .first()
            rust("#T::${variant.name}", symbolProvider.toSymbol(target))
        }
        is EnumShape -> PrimitiveInstantiator(runtimeConfig, symbolProvider).instantiate(target, node)(this)

        is ByteShape -> rust(node.expectNumberNode().value.toString() + "i8")
        is ShortShape -> rust(node.expectNumberNode().value.toString() + "i16")
@@ -163,7 +135,7 @@ fun defaultValue(
        is BooleanShape -> rust(node.expectBooleanNode().value.toString())
        is StringShape -> rust("String::from(${node.expectStringNode().value.dq()})")
        is TimestampShape -> when (node) {
            is NumberNode -> rust(node.expectNumberNode().value.toString())
            is NumberNode -> PrimitiveInstantiator(runtimeConfig, symbolProvider).instantiate(target, node)(this)
            is StringNode -> {
                val value = node.expectStringNode().value
                rustTemplate(
@@ -180,10 +152,12 @@ fun defaultValue(
            check(node is ArrayNode && node.isEmpty)
            rust("Vec::new()")
        }

        is MapShape -> {
            check(node is ObjectNode && node.isEmpty)
            rust("std::collections::HashMap::new()")
        }

        is DocumentShape -> {
            when (node) {
                is NullNode -> rustTemplate(
@@ -191,8 +165,16 @@ fun defaultValue(
                    "SmithyTypes" to types,
                )

                is BooleanNode -> rustTemplate("""#{SmithyTypes}::Document::Bool(${node.value})""", "SmithyTypes" to types)
                is StringNode -> rustTemplate("#{SmithyTypes}::Document::String(String::from(${node.value.dq()}))", "SmithyTypes" to types)
                is BooleanNode -> rustTemplate(
                    """#{SmithyTypes}::Document::Bool(${node.value})""",
                    "SmithyTypes" to types,
                )

                is StringNode -> rustTemplate(
                    "#{SmithyTypes}::Document::String(String::from(${node.value.dq()}))",
                    "SmithyTypes" to types,
                )

                is NumberNode -> {
                    val value = node.value.toString()
                    val variant = when (node.value) {
@@ -212,14 +194,17 @@ fun defaultValue(

                is ObjectNode -> {
                    check(node.isEmpty)
                    rustTemplate("#{SmithyTypes}::Document::Object(std::collections::HashMap::new())", "SmithyTypes" to types)
                    rustTemplate(
                        "#{SmithyTypes}::Document::Object(std::collections::HashMap::new())",
                        "SmithyTypes" to types,
                    )
                }

                else -> throw unsupportedDefaultValueException
            }
        }

        is BlobShape -> rust("Default::default()")
        is BlobShape -> PrimitiveInstantiator(runtimeConfig, symbolProvider).instantiate(target, node)(this)

        else -> throw unsupportedDefaultValueException
    }
+1 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ class ServerInstantiator(codegenContext: CodegenContext, customWritable: CustomW
        ServerBuilderKindBehavior(codegenContext),
        defaultsForRequiredFields = true,
        customizations = listOf(ServerAfterInstantiatingValueConstrainItIfNecessary(codegenContext)),
        // Construct with direct pattern to more closely replicate actual server customer usage
        constructPattern = InstantiatorConstructPattern.DIRECT,
        customWritable = customWritable,
    )
+11 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ class ServerProtocolTestGenerator(
                    TestCase.MalformedRequestTest(fixed)
                }
            }

            else -> it
        }
    }
@@ -741,6 +742,7 @@ class ServerProtocolTestGenerator(
        // it makes sense to do the simplest thing for now.
        // The test will _fail_ if these pass, so we will discover & remove if we fix them by accident
        private const val AwsJson11 = "aws.protocoltests.json#JsonProtocol"
        private const val AwsJson10 = "aws.protocoltests.json10#JsonRpc10"
        private const val RestJson = "aws.protocoltests.restjson#RestJson"
        private const val RestJsonValidation = "aws.protocoltests.restjson.validation#RestJsonValidation"
        private val ExpectFail: Set<FailingTest> = setOf(
@@ -825,6 +827,14 @@ class ServerProtocolTestGenerator(
            // TODO(https://github.com/awslabs/smithy/issues/1737): Specs on @internal, @tags, and enum values need to be clarified
            FailingTest(RestJsonValidation, "RestJsonMalformedEnumTraitString_case0", TestType.MalformedRequest),
            FailingTest(RestJsonValidation, "RestJsonMalformedEnumTraitString_case1", TestType.MalformedRequest),

            // These tests are broken because they are missing a target header
            FailingTest(AwsJson10, "AwsJson10ServerPopulatesNestedDefaultsWhenMissingInRequestBody", TestType.Request),
            FailingTest(AwsJson10, "AwsJson10ServerPopulatesDefaultsWhenMissingInRequestBody", TestType.Request),

            // Response defaults are not set when builders are not used https://github.com/smithy-lang/smithy-rs/issues/3339
            FailingTest(AwsJson10, "AwsJson10ServerPopulatesDefaultsInResponseWhenMissingInParams", TestType.Response),
            FailingTest(AwsJson10, "AwsJson10ServerPopulatesNestedDefaultValuesWhenMissingInInResponseParams", TestType.Response),
        )
        private val RunOnly: Set<String>? = null

@@ -848,6 +858,7 @@ class ServerProtocolTestGenerator(
            // RestXml S3 tests that fail to compile
            "S3EscapeObjectKeyInUriLabel",
            "S3EscapePathObjectKeyInUriLabel",

        )

        private fun fixRestJsonAllQueryStringTypes(
Loading