Unverified Commit 85c413f7 authored by Matteo Bigoi's avatar Matteo Bigoi Committed by GitHub
Browse files

Fix #793. Generate all input/output/error serde helpers in server codegen (#794)

parent f2c1b15e
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ val CodegenTests = listOf(
    CodegenTest("com.amazonaws.ebs#Ebs", "ebs")
)

/**
 * The fluent client is generated to prevent warnings in RustDoc since the client is
 * referenced by multiple documentations.
 * TODO: review client generation in the future.
 */
fun generateSmithyBuild(tests: List<CodegenTest>): String {
    val projections =
        tests.joinToString(",\n") {
@@ -35,7 +40,7 @@ fun generateSmithyBuild(tests: List<CodegenTest>): String {
                "plugins": {
                    "rust-server-codegen": {
                      "codegen": {
                        "includeFluentClient": false
                        "includeFluentClient": true
                      },
                      "runtimeConfig": {
                        "relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime"
+26 −38
Original line number Diff line number Diff line
@@ -102,9 +102,6 @@ class RestJson1HttpSerializerGenerator(
            return
        }
        val serializerSymbol = jsonSerializerGenerator.serverOutputSerializer(operationShape)
        if (serializerSymbol == null) {
            return
        }
        val outputSymbol = symbolProvider.toSymbol(outputShape)
        writer.write("")
        writer.rustBlockTemplate(
@@ -169,7 +166,6 @@ class RestJson1HttpSerializerGenerator(
                    val variantSymbol = symbolProvider.toSymbol(variantShape)
                    val data = safeName("var")
                    val serializerSymbol = jsonSerializerGenerator.serverErrorSerializer(it)
                    if (serializerSymbol != null) {
                    rustBlock("#TKind::${variantSymbol.name}($data) =>", errorSymbol) {
                        rust(
                            """
@@ -203,11 +199,6 @@ class RestJson1HttpSerializerGenerator(
                                ?: errorTrait.defaultHttpStatusCode
                        rust("response = response.status($status);")
                    }
                    } else {
                        logger.warning(
                            "[rust-server-codegen] $variantShape: response error serialization does not contain any member"
                        )
                    }
                }
                rust(
                    """
@@ -369,9 +360,6 @@ class RestJson1HttpDeserializerGenerator(
            return
        }
        val deserializerSymbol = jsonParserGenerator.serverInputParser(operationShape)
        if (deserializerSymbol == null) {
            return
        }
        val inputSymbol = symbolProvider.toSymbol(inputShape)
        writer.write("")
        writer.rustBlockTemplate(
+12 −6
Original line number Diff line number Diff line
@@ -83,14 +83,14 @@ class JsonParserGenerator(
    /**
     * Reusable structure parser implementation that can be used to generate parsing code for
     * operation, error and structure shapes.
     * We still generate the parser symbol even if there are no included members because the server
     * generation requires parsers for all input structures.
     */
    private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType? {
        if (includedMembers.isEmpty()) {
            return null
        }
    private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType {
        val unusedMut = if (includedMembers.isEmpty()) "##[allow(unused_mut)] " else ""
        return RuntimeType.forInlineFun(fnName, jsonDeserModule) {
            it.rustBlockTemplate(
                "pub fn $fnName(value: &[u8], mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>",
                "pub fn $fnName(value: &[u8], ${unusedMut}mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>",
                "Builder" to structureShape.builderSymbol(symbolProvider),
                *codegenScope
            ) {
@@ -138,12 +138,18 @@ class JsonParserGenerator(
    override fun operationParser(operationShape: OperationShape): RuntimeType? {
        // Don't generate an operation JSON deserializer if there is no JSON body
        val httpDocumentMembers = httpBindingResolver.responseMembers(operationShape, HttpLocation.DOCUMENT)
        if (httpDocumentMembers.isEmpty()) {
            return null
        }
        val outputShape = operationShape.outputShape(model)
        val fnName = symbolProvider.deserializeFunctionName(operationShape)
        return structureParser(fnName, outputShape, httpDocumentMembers)
    }

    override fun errorParser(errorShape: StructureShape): RuntimeType? {
        if (errorShape.members().isEmpty()) {
            return null
        }
        val fnName = symbolProvider.deserializeFunctionName(errorShape) + "_json_err"
        return structureParser(fnName, errorShape, errorShape.members().toList())
    }
@@ -184,7 +190,7 @@ class JsonParserGenerator(
        )
    }

    override fun serverInputParser(operationShape: OperationShape): RuntimeType? {
    override fun serverInputParser(operationShape: OperationShape): RuntimeType {
        val inputShape = operationShape.inputShape(model)
        val includedMembers = httpBindingResolver.requestMembers(operationShape, HttpLocation.DOCUMENT)
        val fnName = symbolProvider.deserializeFunctionName(inputShape)
+1 −1
Original line number Diff line number Diff line
@@ -66,5 +66,5 @@ interface StructuredDataParserGenerator {
     * }
     * ```
     */
    fun serverInputParser(operationShape: OperationShape): RuntimeType?
    fun serverInputParser(operationShape: OperationShape): RuntimeType
}
+1 −1
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ class XmlBindingTraitParserGenerator(
        TODO("Document shapes are not supported by rest XML")
    }

    override fun serverInputParser(operationShape: OperationShape): RuntimeType? {
    override fun serverInputParser(operationShape: OperationShape): RuntimeType {
        TODO("Not yet implemented")
    }

Loading