Unverified Commit f421c635 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Make server pass naming obstacle course protocol tests (#1333)

This commit fixes two bugs that were present in the server
implementation:

* We were incorrectly referring to the operation input shape name
  instead of using the symbol provider in
  `ServerOperationHandlerGenerator.kt` and
  `ServerOperationRegistryGenerator.kt`.
* We were not escaping Rust reserved keywords in operation names in
  `ServerOperationRegistryGenerator.kt`.

The second bug would have been caught had we been generating server
crates for the two naming obstacle course test suites
(`naming-obstacle-course-ops.smithy` and
`naming-obstacle-course-structs.smithy`) that the client is already
passing. This commit adds these suites to the `codegen-server-test`
subproject, and expands `naming-obstacle-course-ops.smithy` to exercise
the logic that was causing the first bug.
parent 86debc67
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ dependencies {
}

val allCodegenTests = listOf(
    CodegenTest("crate#Config", "naming_test_ops"),
    CodegenTest("naming_obs_structs#NamingObstacleCourseStructs", "naming_test_structs"),
    CodegenTest("com.amazonaws.simple#SimpleService", "simple"),
    CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"),
    CodegenTest("aws.protocoltests.restjson.validation#RestJsonValidation", "rest_json_validation"),
+1 −0
Original line number Diff line number Diff line
../../codegen-test/model/naming-obstacle-course-ops.smithy
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
../../codegen-test/model/naming-obstacle-course-structs.smithy
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ open class ServerOperationHandlerGenerator(
    private fun renderHandlerImplementations(writer: RustWriter, state: Boolean) {
        operations.map { operation ->
            val operationName = symbolProvider.toSymbol(operation).name
            val inputName = "crate::input::${operationName}Input"
            val inputName = symbolProvider.toSymbol(operation.inputShape(model)).fullName
            val inputWrapperName = "crate::operation::$operationName${ServerHttpBoundProtocolGenerator.OPERATION_INPUT_WRAPPER_SUFFIX}"
            val outputWrapperName = "crate::operation::$operationName${ServerHttpBoundProtocolGenerator.OPERATION_OUTPUT_WRAPPER_SUFFIX}"
            val fnSignature = if (state) {
+4 −3
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import software.amazon.smithy.model.traits.DocumentationTrait
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.rustlang.RustReservedWords
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.Writable
import software.amazon.smithy.rust.codegen.rustlang.asType
@@ -55,7 +56,7 @@ class ServerOperationRegistryGenerator(
    private val model = coreCodegenContext.model
    private val symbolProvider = coreCodegenContext.symbolProvider
    private val serviceName = coreCodegenContext.serviceShape.toShapeId().name
    private val operationNames = operations.map { symbolProvider.toSymbol(it).name.toSnakeCase() }
    private val operationNames = operations.map { RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(it).name.toSnakeCase()) }
    private val runtimeConfig = coreCodegenContext.runtimeConfig
    private val codegenScope = arrayOf(
        "Router" to ServerRuntimeType.Router(runtimeConfig),
@@ -287,7 +288,7 @@ ${operationImplementationStubs(operations)}
            operations.forEachIndexed { i, operation ->
                rustTemplate(
                    """
                    Op$i: #{ServerOperationHandler}::Handler<B, In$i, #{OperationInput}>,
                    Op$i: #{ServerOperationHandler}::Handler<B, In$i, ${symbolProvider.toSymbol(operation.inputShape(model)).fullName}>,
                    In$i: 'static + Send,
                    """,
                    *codegenScope,
@@ -385,7 +386,7 @@ ${operationImplementationStubs(operations)}
            "Result<$t, $e>"
        }

        val operationName = symbolProvider.toSymbol(this).name.toSnakeCase()
        val operationName = RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(this).name.toSnakeCase())
        return "async fn $operationName(input: $inputT) -> $outputT"
    }

Loading