Unverified Commit fd94858d authored by Harry Barber's avatar Harry Barber Committed by GitHub
Browse files

Add new service builder codegen (#1693)

* Add `ServerProtocol` interface to allow for server side protocol specific methods.

* Make public the structs merged in https://github.com/awslabs/smithy-rs/pull/1679.

* Add `ServerOperationGenerator`, which generates a ZST and implements `OperationShape` on it.

* Add `ServerServiceGeneratorV2`, which generates the service newtype around a router and a service builder.

* Add `hidden` argument to `RustModule` which allows modules to be marked with `#[doc(hidden)]`.

* Add `BuildModifier` trait to provide a common interface for extending service builders.

* Add `Upgradable` trait to simplifying bounds when upgrading from an `Operation` to a HTTP service.

* Add `FromRequest`, `FromParts`, and `IntoResponse` implementations.

* Make `RoutingService` accept general body types `B` for the inner services `http::Response<B>`.

* Use new service builder in protocol tests.
parent 56f4be32
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -26,6 +26,13 @@ fun Writable.isEmpty(): Boolean {
    return writer.toString() == RustWriter.root().toString()
}

operator fun Writable.plus(other: Writable): Writable {
    val first = this
    return writable {
        rustTemplate("#{First:W}#{Second:W}", "First" to first, "Second" to other)
    }
}

/**
 * Helper allowing a `Iterable<Writable>` to be joined together using a `String` separator.
 */
+3 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ class AwsJsonSerializerGenerator(
}

open class AwsJson(
    private val coreCodegenContext: CoreCodegenContext,
    val coreCodegenContext: CoreCodegenContext,
    private val awsJsonVersion: AwsJsonVersion,
) : Protocol {
    private val runtimeConfig = coreCodegenContext.runtimeConfig
@@ -143,6 +143,8 @@ open class AwsJson(
    )
    private val jsonDeserModule = RustModule.private("json_deser")

    val version: AwsJsonVersion get() = awsJsonVersion

    override val httpBindingResolver: HttpBindingResolver =
        AwsJsonHttpBindingResolver(coreCodegenContext.model, awsJsonVersion)

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ class RestJsonHttpBindingResolver(
    }
}

class RestJson(private val coreCodegenContext: CoreCodegenContext) : Protocol {
open class RestJson(val coreCodegenContext: CoreCodegenContext) : Protocol {
    private val runtimeConfig = coreCodegenContext.runtimeConfig
    private val errorScope = arrayOf(
        "Bytes" to RuntimeType.Bytes,
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class RestXmlFactory(
    }
}

open class RestXml(private val coreCodegenContext: CoreCodegenContext) : Protocol {
open class RestXml(val coreCodegenContext: CoreCodegenContext) : Protocol {
    private val restXml = coreCodegenContext.serviceShape.expectTrait<RestXmlTrait>()
    private val runtimeConfig = coreCodegenContext.runtimeConfig
    private val errorScope = arrayOf(
+4 −2
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ object ServerRuntimeType {
    fun ResponseRejection(runtimeConfig: RuntimeConfig) =
        RuntimeType("ResponseRejection", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::rejection")

    fun Protocol(runtimeConfig: RuntimeConfig) =
        RuntimeType("Protocol", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::protocols")
    fun Protocol(name: String, runtimeConfig: RuntimeConfig) =
        RuntimeType(name, ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::protocols")

    fun Protocol(runtimeConfig: RuntimeConfig) = Protocol("Protocol", runtimeConfig)
}
Loading