Skip to content

Commit

Permalink
Try to pass @pattern string shapes to service visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jjant committed Nov 30, 2022
1 parent b5f1341 commit 83f3203
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.rust.codegen.server.smithy

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
Expand All @@ -31,6 +32,7 @@ data class ServerCodegenContext(
val constrainedShapeSymbolProvider: RustSymbolProvider,
val constraintViolationSymbolProvider: ConstraintViolationSymbolProvider,
val pubCrateConstrainedShapeSymbolProvider: PubCrateConstrainedShapeSymbolProvider,
val typesToInit: MutableSet<Symbol> = setOf<Symbol>().toMutableSet(),
) : CodegenContext(
model, symbolProvider, serviceShape, protocol, settings, CodegenTarget.SERVER,
)
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class ConstrainedStringGenerator(
if (constrainedTypeVisibility == Visibility.PUBCRATE) {
Attribute.AllowUnused.render(writer)
}
codegenContext.typesToInit.add(symbol)

writer.rust(
"""
impl $name {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolTestGenerator
Expand All @@ -31,7 +31,7 @@ open class ServerServiceGenerator(
private val protocolGenerator: ServerProtocolGenerator,
private val protocolSupport: ProtocolSupport,
val protocol: ServerProtocol,
private val codegenContext: CodegenContext,
private val codegenContext: ServerCodegenContext,
) {
private val index = TopDownIndex.of(codegenContext.model)
protected val operations = index.getContainedOperations(codegenContext.serviceShape).sortedBy { it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import software.amazon.smithy.rust.codegen.core.rustlang.join
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.util.toPascalCase
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol

class ServerServiceGeneratorV2(
private val codegenContext: CodegenContext,
private val codegenContext: ServerCodegenContext,
private val protocol: ServerProtocol,
) {
private val runtimeConfig = codegenContext.runtimeConfig
Expand All @@ -39,8 +39,11 @@ class ServerServiceGeneratorV2(
)
private val model = codegenContext.model
private val symbolProvider = codegenContext.symbolProvider
val crateName = codegenContext.settings.moduleName.toSnakeCase()
private val crateName = codegenContext.settings.moduleName.toSnakeCase()

private val typeInitializations = codegenContext.typesToInit

This comment has been minimized.

Copy link
@jjant

jjant Nov 30, 2022

Author Contributor

ServerServiceGeneratorV2 runs first, so typesToInit is empty here :(.

.map { typeSymbol -> writable { rust("$typeSymbol::compile_regex();") } }
.join("\n")
private val service = codegenContext.serviceShape
private val serviceName = service.id.name.toPascalCase()
private val builderName = "${serviceName}Builder"
Expand Down Expand Up @@ -203,6 +206,7 @@ class ServerServiceGeneratorV2(
/// unspecified route requested.
pub fn build(self) -> Result<$serviceName<#{SmithyHttpServer}::routing::Route<$builderBodyGenericTypeName>>, MissingOperationsError>
{
#{TypeInitializations:W}
let router = {
use #{SmithyHttpServer}::operation::OperationShape;
let mut $missingOperationsVariableName = std::collections::HashMap::new();
Expand All @@ -221,6 +225,7 @@ class ServerServiceGeneratorV2(
}
""",
"Router" to protocol.routerType(),
"TypeInitializations" to typeInitializations,
"NullabilityChecks" to nullabilityChecks,
"RoutesArrayElements" to routesArrayElements,
"SmithyHttpServer" to smithyHttpServer,
Expand Down

0 comments on commit 83f3203

Please sign in to comment.