Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate the operation registry when there are no operations #1369

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -33,6 +33,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
10 changes: 10 additions & 0 deletions codegen-server-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 @@ -50,6 +50,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,6 +29,7 @@ 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`
Expand All @@ -52,13 +54,17 @@ class ServerServiceGenerator(
}
}
}
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 ->
ServerOperationRegistryGenerator(context, httpBindingResolver, operations)
.render(writer)
if (operations.isNotEmpty()) {
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 ->
ServerOperationRegistryGenerator(context, httpBindingResolver, operations)
.render(writer)
}
} else {
logger.warning("[rust-server-codegen] There are no operations in the service closure")
}
}
}