Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.rust.codegen.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.rustlang.CratesIo /** * Object used *exclusively* in the runtime of the server, for separation concerns. * Analogous to the companion object in [CargoDependency]; see its documentation for details. * For a dependency that is used in the client, or in both the client and the server, use [CargoDependency] directly. */ object ServerCargoDependency { val Axum: CargoDependency = CargoDependency("axum", CratesIo("0.3")) // TODO Remove this dependency https://github.com/awslabs/smithy-rs/issues/864 val DeriveBuilder = CargoDependency("derive_builder", CratesIo("0.10")) } codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeTypes.kt 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.rust.codegen.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.smithy.RuntimeType /** * Object used *exclusively* in the runtime of the server, for separation concerns. * Analogous to the companion object in [RuntimeType]; see its documentation for details. * For a runtime type that is used in the client, or in both the client and the server, use [RuntimeType] directly. */ object ServerRuntimeType { val DeriveBuilder = RuntimeType("Builder", dependency = ServerCargoDependency.DeriveBuilder, namespace = "derive_builder") fun Router(runtimeConfig: RuntimeConfig) = RuntimeType("Router", CargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") fun RequestSpecModule(runtimeConfig: RuntimeConfig) = RuntimeType("request_spec", CargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") } codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/OperationRegistryGenerator.kt +4 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.rustlang.* import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpProtocolGenerator import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.RuntimeType.Companion.RequestSpecModule import software.amazon.smithy.rust.codegen.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBindingResolver import software.amazon.smithy.rust.codegen.smithy.protocols.HttpTraitHttpBindingResolver Loading @@ -33,13 +33,13 @@ class OperationRegistryGenerator( private val operationNames = operations.map { symbolProvider.toSymbol(it).name.toSnakeCase() } private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Router" to RuntimeType.Router(runtimeConfig), "Router" to ServerRuntimeType.Router(runtimeConfig), ) private val httpBindingResolver: HttpBindingResolver = HttpTraitHttpBindingResolver(codegenContext.model, ProtocolContentTypes.consistent("application/json")) fun render(writer: RustWriter) { Attribute.Derives(setOf(RuntimeType.Debug, RuntimeType.DeriveBuilder)).render(writer) Attribute.Derives(setOf(RuntimeType.Debug, ServerRuntimeType.DeriveBuilder)).render(writer) Attribute.Custom("builder(pattern = \"owned\")").render(writer) // Generic arguments of the `OperationRegistryBuilder<Fun0, Fut0, ..., FunN, FutN>`. val operationsGenericArguments = operations.mapIndexed { i, _ -> "Fun$i, Fut$i"}.joinToString() Loading Loading @@ -98,7 +98,7 @@ class OperationRegistryGenerator( private fun OperationShape.requestSpec(): String { val httpTrait = httpBindingResolver.httpTrait(this) val namespace = RequestSpecModule(runtimeConfig).fullyQualifiedName() val namespace = ServerRuntimeType.RequestSpecModule(runtimeConfig).fullyQualifiedName() // TODO Support the `endpoint` trait: https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#endpoint-trait Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import software.amazon.smithy.rust.codegen.rustlang.rust import software.amazon.smithy.rust.codegen.rustlang.rustBlock import software.amazon.smithy.rust.codegen.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.rustlang.withBlock import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpProtocolGenerator import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeType Loading Loading @@ -65,7 +66,7 @@ class ServerProtocolTestGenerator( "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), "Hyper" to CargoDependency.Hyper.asType(), "Axum" to CargoDependency.Axum.asType(), "Axum" to ServerCargoDependency.Axum.asType(), "SmithyHttpServer" to CargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), ) Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import software.amazon.smithy.rust.codegen.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.rustlang.withBlock import software.amazon.smithy.rust.codegen.rustlang.writable import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.smithy.RuntimeType Loading Loading @@ -86,7 +87,7 @@ private class ServerHttpProtocolImplGenerator( private val operationSerModule = RustModule.private("operation_ser") private val codegenScope = arrayOf( "Axum" to CargoDependency.Axum.asType(), "Axum" to ServerCargoDependency.Axum.asType(), "DateTime" to RuntimeType.DateTime(runtimeConfig), "HttpBody" to CargoDependency.HttpBody.asType(), "Hyper" to CargoDependency.Hyper.asType(), Loading Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.rust.codegen.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.rustlang.CratesIo /** * Object used *exclusively* in the runtime of the server, for separation concerns. * Analogous to the companion object in [CargoDependency]; see its documentation for details. * For a dependency that is used in the client, or in both the client and the server, use [CargoDependency] directly. */ object ServerCargoDependency { val Axum: CargoDependency = CargoDependency("axum", CratesIo("0.3")) // TODO Remove this dependency https://github.com/awslabs/smithy-rs/issues/864 val DeriveBuilder = CargoDependency("derive_builder", CratesIo("0.10")) }
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeTypes.kt 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.rust.codegen.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.smithy.RuntimeType /** * Object used *exclusively* in the runtime of the server, for separation concerns. * Analogous to the companion object in [RuntimeType]; see its documentation for details. * For a runtime type that is used in the client, or in both the client and the server, use [RuntimeType] directly. */ object ServerRuntimeType { val DeriveBuilder = RuntimeType("Builder", dependency = ServerCargoDependency.DeriveBuilder, namespace = "derive_builder") fun Router(runtimeConfig: RuntimeConfig) = RuntimeType("Router", CargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") fun RequestSpecModule(runtimeConfig: RuntimeConfig) = RuntimeType("request_spec", CargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::routing") }
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/OperationRegistryGenerator.kt +4 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.rust.codegen.rustlang.* import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpProtocolGenerator import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeType import software.amazon.smithy.rust.codegen.smithy.RuntimeType.Companion.RequestSpecModule import software.amazon.smithy.rust.codegen.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBindingResolver import software.amazon.smithy.rust.codegen.smithy.protocols.HttpTraitHttpBindingResolver Loading @@ -33,13 +33,13 @@ class OperationRegistryGenerator( private val operationNames = operations.map { symbolProvider.toSymbol(it).name.toSnakeCase() } private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Router" to RuntimeType.Router(runtimeConfig), "Router" to ServerRuntimeType.Router(runtimeConfig), ) private val httpBindingResolver: HttpBindingResolver = HttpTraitHttpBindingResolver(codegenContext.model, ProtocolContentTypes.consistent("application/json")) fun render(writer: RustWriter) { Attribute.Derives(setOf(RuntimeType.Debug, RuntimeType.DeriveBuilder)).render(writer) Attribute.Derives(setOf(RuntimeType.Debug, ServerRuntimeType.DeriveBuilder)).render(writer) Attribute.Custom("builder(pattern = \"owned\")").render(writer) // Generic arguments of the `OperationRegistryBuilder<Fun0, Fut0, ..., FunN, FutN>`. val operationsGenericArguments = operations.mapIndexed { i, _ -> "Fun$i, Fut$i"}.joinToString() Loading Loading @@ -98,7 +98,7 @@ class OperationRegistryGenerator( private fun OperationShape.requestSpec(): String { val httpTrait = httpBindingResolver.httpTrait(this) val namespace = RequestSpecModule(runtimeConfig).fullyQualifiedName() val namespace = ServerRuntimeType.RequestSpecModule(runtimeConfig).fullyQualifiedName() // TODO Support the `endpoint` trait: https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#endpoint-trait Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import software.amazon.smithy.rust.codegen.rustlang.rust import software.amazon.smithy.rust.codegen.rustlang.rustBlock import software.amazon.smithy.rust.codegen.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.rustlang.withBlock import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpProtocolGenerator import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeType Loading Loading @@ -65,7 +66,7 @@ class ServerProtocolTestGenerator( "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), "Hyper" to CargoDependency.Hyper.asType(), "Axum" to CargoDependency.Axum.asType(), "Axum" to ServerCargoDependency.Axum.asType(), "SmithyHttpServer" to CargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), ) Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt +2 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import software.amazon.smithy.rust.codegen.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.rustlang.withBlock import software.amazon.smithy.rust.codegen.rustlang.writable import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.smithy.CodegenContext import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.smithy.RuntimeType Loading Loading @@ -86,7 +87,7 @@ private class ServerHttpProtocolImplGenerator( private val operationSerModule = RustModule.private("operation_ser") private val codegenScope = arrayOf( "Axum" to CargoDependency.Axum.asType(), "Axum" to ServerCargoDependency.Axum.asType(), "DateTime" to RuntimeType.DateTime(runtimeConfig), "HttpBody" to CargoDependency.HttpBody.asType(), "Hyper" to CargoDependency.Hyper.asType(), Loading