Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codegen-server-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
}

val allCodegenTests = listOf(
CodegenTest("com.aws.example#EmptyService", "empty"),
CodegenTest("com.amazonaws.simple#SimpleService", "simple"),
CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"),
CodegenTest("aws.protocoltests.restjson.validation#RestJsonValidation", "rest_json_validation"),
Expand Down
1 change: 1 addition & 0 deletions codegen-server-test/model/empty.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ServerOperationHandlerGenerator(
)

fun render(writer: RustWriter) {
check(operations.isNotEmpty())

renderHandlerImplementations(writer, false)
renderHandlerImplementations(writer, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ServerOperationRegistryGenerator(
private val operationRegistryBuilderNameWithArguments = "$operationRegistryBuilderName<$genericArguments>"

fun render(writer: RustWriter) {
check(operations.isNotEmpty())

renderOperationRegistryStruct(writer)
renderOperationRegistryBuilderStruct(writer)
renderOperationRegistryBuilderError(writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import software.amazon.smithy.rust.codegen.smithy.RustCrate
import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBindingResolver
import java.util.logging.Logger

/**
* ServerServiceGenerator
Expand All @@ -28,13 +29,20 @@ class ServerServiceGenerator(
private val context: CodegenContext,
) {
private val index = TopDownIndex.of(context.model)
private val logger = Logger.getLogger(javaClass.name)

/**
* Render Service Specific code. Code will end up in different files via [useShapeWriter]. See `SymbolVisitor.kt`
* which assigns a symbol location to each shape.
*/
fun render() {
val operations = index.getContainedOperations(context.serviceShape).sortedBy { it.id }

if (operations.isEmpty()) {
logger.warning("[rust-server-codegen] There are no operations in the service closure")
return
}

for (operation in operations) {
rustCrate.useShapeWriter(operation) { operationWriter ->
protocolGenerator.serverRenderOperation(
Expand All @@ -52,11 +60,21 @@ class ServerServiceGenerator(
}
}
}
rustCrate.withModule(RustModule.public("operation_handler", "Operation handlers definition and implementation.")) { writer ->
rustCrate.withModule(
RustModule.public(
"operation_handler",
"Operation handlers definition and implementation."
)
) { writer ->
ServerOperationHandlerGenerator(context, operations)
.render(writer)
}
rustCrate.withModule(RustModule.public("operation_registry", "A registry of your service's operations.")) { writer ->
rustCrate.withModule(
RustModule.public(
"operation_registry",
"A registry of your service's operations."
)
) { writer ->
ServerOperationRegistryGenerator(context, httpBindingResolver, operations)
.render(writer)
}
Expand Down
1 change: 1 addition & 0 deletions codegen-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
}

val allCodegenTests = listOf(
CodegenTest("com.aws.example#EmptyService", "empty"),
CodegenTest("com.amazonaws.simple#SimpleService", "simple"),
CodegenTest("com.amazonaws.dynamodb#DynamoDB_20120810", "dynamo"),
CodegenTest("com.amazonaws.ebs#Ebs", "ebs"),
Expand Down
10 changes: 10 additions & 0 deletions codegen-test/model/empty.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$version: "1.0"

namespace com.aws.example

use aws.protocols#restJson1

@restJson1
service EmptyService {
version: "2022-05-06",
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class ServiceGenerator(
*/
fun render() {
val operations = index.getContainedOperations(config.serviceShape).sortedBy { it.id }
operations.map { operation ->

for (operation in operations) {
rustCrate.useShapeWriter(operation) { operationWriter ->
rustCrate.useShapeWriter(operation.inputShape(config.model)) { inputWriter ->
// Render the operation shape & serializers input `input.rs`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class FluentClientGenerator(
"""
##[derive(Debug)]
pub(crate) struct Handle#{generics_decl:W} {
pub(crate) client: #{client}::Client#{smithy_inst:W},
##[allow(dead_code)] pub(crate) client: #{client}::Client#{smithy_inst:W},
pub(crate) conf: crate::Config,
}

Expand Down