Unverified Commit 555021e3 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Expand protocol tests for RestJson1.1 and AwsRestJson (#38)

* Add document types & other bug fixes to support AwsJson11

* Expand protocol tests for RestJson1.1 and AwsRestJson

This diff adds RestJson1 and AwsJson1.1 to the integration test suite. It uncovered a number of bugs, some of which I fixed inline and some I filed issues for and disabled the tests.

* Add another disabled test & cleaup

* Fix tests broken by changing URL encoding to encode ':'

* Copy-paste Aarons comment

* Fixup Rustfmt
parent a3dbb5e3
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ plugins {

val smithyVersion: String by project


dependencies {
    implementation(project(":codegen"))
    implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
@@ -26,7 +27,15 @@ data class CodegenTest(val service: String, val module: String)
val CodgenTests = listOf(
    CodegenTest("com.amazonaws.dynamodb#DynamoDB_20120810", "dynamo"),
    CodegenTest("com.amazonaws.ebs#Ebs", "ebs"),
    CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10")
    CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10"),
    CodegenTest(
        "aws.protocoltests.json#JsonProtocol",
        "json_rpc11"
    ),
    CodegenTest(
        "aws.protocoltests.restjson#RestJson",
        "rest_json"
    )
)

fun generateSmithyBuild(tests: List<CodegenTest>): String {
+14 −3
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@ package software.amazon.smithy.rust.codegen.lang

import software.amazon.smithy.rust.codegen.smithy.RuntimeType

interface Container {
    val value: RustType
}

/**
 * A hierarchy of types handled by Smithy codegen
 */
@@ -47,15 +51,15 @@ sealed class RustType {
        override val name: kotlin.String = "HashSet"
    }

    data class Reference(val lifetime: kotlin.String?, val value: RustType) : RustType() {
    data class Reference(val lifetime: kotlin.String?, override val value: RustType) : RustType(), Container {
        override val name: kotlin.String = value.name
    }

    data class Option(val value: RustType) : RustType() {
    data class Option(override val value: RustType) : RustType(), Container {
        override val name: kotlin.String = "Option"
    }

    data class Box(val value: RustType) : RustType() {
    data class Box(override val value: RustType) : RustType(), Container {
        override val name: kotlin.String = "Box"
    }

@@ -76,6 +80,13 @@ fun RustType.render(): String = when (this) {
    is RustType.Opaque -> this.name
}

inline fun <reified T : Container> RustType.stripOuter(): RustType {
    return when (this) {
        is T -> this.value
        else -> this
    }
}

/**
 * Meta information about a Rust construction (field, struct, or enum)
 */
+3 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.codegen.core.writer.CodegenWriter
import software.amazon.smithy.codegen.core.writer.CodegenWriterFactory
import software.amazon.smithy.model.shapes.CollectionShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.EnumTrait
@@ -123,10 +124,10 @@ class RustWriter private constructor(private val filename: String, val namespace
    }

    fun ListForEach(target: Shape, outerField: String, block: CodeWriter.(field: String, target: ShapeId) -> Unit) {
        if (target.isListShape) {
        if (target is CollectionShape) {
            val derefName = safeName("inner")
            rustBlock("for $derefName in $outerField") {
                block(derefName, target.asListShape().get().member.target)
                block(derefName, target.member.target)
            }
        } else {
            this.block(outerField, target.toShapeId())
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ data class RuntimeType(val name: String, val dependency: RustDependency?, val na
        fun Blob(runtimeConfig: RuntimeConfig) =
            RuntimeType("Blob", RustDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.cratePrefix}_types")

        fun Document(runtimeConfig: RuntimeConfig): RuntimeType =
            RuntimeType("Document", RustDependency.SmithyTypes(runtimeConfig), "${runtimeConfig.cratePrefix}_types")

        fun LabelFormat(runtimeConfig: RuntimeConfig, func: String) =
            RuntimeType(func, RustDependency.SmithyHttp(runtimeConfig), "${runtimeConfig.cratePrefix}_http::label")

@@ -88,6 +91,7 @@ data class RuntimeType(val name: String, val dependency: RustDependency?, val na
            )

        fun Http(path: String): RuntimeType = RuntimeType(name = path, dependency = RustDependency.Http, namespace = "http")

        val HttpRequestBuilder = Http("request::Builder")
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ class SymbolVisitor(
    }

    override fun documentShape(shape: DocumentShape?): Symbol {
        TODO("Not yet implemented")
        return RuntimeType.Document(config.runtimeConfig).toSymbol()
    }

    override fun bigIntegerShape(shape: BigIntegerShape?): Symbol {
Loading