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

Move server specific methods from Protocol to ServerProtocol #1731

Merged
merged 5 commits into from
Sep 13, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.rust
import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate
import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.client.rustlang.writable
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType
Expand Down Expand Up @@ -130,7 +129,7 @@ class AwsJsonSerializerGenerator(

open class AwsJson(
val coreCodegenContext: CoreCodegenContext,
private val awsJsonVersion: AwsJsonVersion,
val awsJsonVersion: AwsJsonVersion,
) : Protocol {
private val runtimeConfig = coreCodegenContext.runtimeConfig
private val errorScope = arrayOf(
Expand Down Expand Up @@ -183,23 +182,6 @@ open class AwsJson(
*errorScope,
)
}

/**
* Returns the operation name as required by the awsJson1.x protocols.
*/
override fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
) = writable {
rust("""String::from("$serviceName.$operationName")""")
}

override fun serverRouterRuntimeConstructor() = when (awsJsonVersion) {
AwsJsonVersion.Json10 -> "new_aws_json_10_router"
AwsJsonVersion.Json11 -> "new_aws_json_11_router"
}
}

fun awsJsonFieldName(member: MemberShape): String = member.memberName
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import software.amazon.smithy.model.traits.HttpTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.rust
import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate
Expand Down Expand Up @@ -105,17 +104,4 @@ class AwsQueryProtocol(private val coreCodegenContext: CoreCodegenContext) : Pro
rust("#T::parse_generic_error(payload.as_ref())", awsQueryErrors)
}
}

override fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
): Writable {
TODO("Not yet implemented")
}

override fun serverRouterRuntimeConstructor(): String {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import software.amazon.smithy.model.traits.HttpTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.rust
import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate
Expand Down Expand Up @@ -96,17 +95,4 @@ class Ec2QueryProtocol(private val coreCodegenContext: CoreCodegenContext) : Pro
rust("#T::parse_generic_error(payload.as_ref())", ec2QueryErrors)
}
}

override fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
): Writable {
TODO("Not yet implemented")
}

override fun serverRouterRuntimeConstructor(): String {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.model.traits.Trait
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator
Expand Down Expand Up @@ -74,29 +73,6 @@ interface Protocol {
* there are no response headers or statuses available to further inform the error parsing.
*/
fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType

/**
* Returns a writable for the `RequestSpec` for an operation.
*/
fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
): Writable

/**
* Returns the name of the constructor to be used on the `Router` type, to instantiate a `Router` using this
* protocol.
*/
fun serverRouterRuntimeConstructor(): String

/**
* In some protocols, such as restJson1,
* when there is no modeled body input, content type must not be set and the body must be empty.
* Returns a boolean indicating whether to perform this check.
*/
fun serverContentTypeCheckNoModeledInput(): Boolean = false
}

typealias ProtocolMap<C> = Map<ShapeId, ProtocolGeneratorFactory<ProtocolGenerator, C>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import software.amazon.smithy.model.traits.StreamingTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.client.smithy.generators.http.RestRequestSpecGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.JsonParserGenerator
import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator
Expand Down Expand Up @@ -141,17 +139,6 @@ open class RestJson(val coreCodegenContext: CoreCodegenContext) : Protocol {
*errorScope,
)
}

override fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape)

override fun serverRouterRuntimeConstructor() = "new_rest_json_router"

override fun serverContentTypeCheckNoModeledInput() = true
}

fun restJsonFieldName(member: MemberShape): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import software.amazon.smithy.model.traits.AnnotationTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.client.rustlang.RustModule
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.rustlang.asType
import software.amazon.smithy.rust.codegen.client.rustlang.rust
import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.client.smithy.generators.http.RestRequestSpecGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.RestXmlParserGenerator
import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator
Expand Down Expand Up @@ -103,17 +101,6 @@ open class RestXml(val coreCodegenContext: CoreCodegenContext) : Protocol {
rust("#T::parse_generic_error(payload.as_ref())", restXmlErrors)
}
}

override fun serverRouterRequestSpec(
operationShape: OperationShape,
operationName: String,
serviceName: String,
requestSpecModule: RuntimeType,
): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape)

override fun serverRouterRuntimeConstructor() = "new_rest_xml_router"

override fun serverContentTypeCheckNoModeledInput() = true
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import software.amazon.smithy.rust.codegen.server.python.smithy.generators.Pytho
import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerServiceGenerator
import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerStructureGenerator
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol
import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader

/**
Expand Down Expand Up @@ -136,7 +137,7 @@ class PythonServerCodegenVisitor(
rustCrate,
protocolGenerator,
protocolGeneratorFactory.support(),
protocolGeneratorFactory.protocol(codegenContext),
ServerProtocol.fromCoreProtocol(protocolGeneratorFactory.protocol(codegenContext)),
codegenContext,
)
.render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.RustCrate
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerServiceGenerator
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol

/**
* PythonServerServiceGenerator
Expand All @@ -25,7 +25,7 @@ class PythonServerServiceGenerator(
private val rustCrate: RustCrate,
protocolGenerator: ProtocolGenerator,
protocolSupport: ProtocolSupport,
protocol: Protocol,
protocol: ServerProtocol,
private val context: CoreCodegenContext,
) : ServerServiceGenerator(rustCrate, protocolGenerator, protocolSupport, protocol, context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import software.amazon.smithy.rust.codegen.client.util.getTrait
import software.amazon.smithy.rust.codegen.client.util.runCommand
import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerEnumGenerator
import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerServiceGenerator
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol
import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader
import java.util.logging.Logger

Expand Down Expand Up @@ -229,7 +230,7 @@ open class ServerCodegenVisitor(
rustCrate,
protocolGenerator,
protocolGeneratorFactory.support(),
protocolGeneratorFactory.protocol(codegenContext),
ServerProtocol.fromCoreProtocol(protocolGeneratorFactory.protocol(codegenContext)),
codegenContext,
)
.render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import software.amazon.smithy.rust.codegen.client.smithy.Outputs
import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget
import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.util.getTrait
import software.amazon.smithy.rust.codegen.client.util.inputShape
import software.amazon.smithy.rust.codegen.client.util.outputShape
import software.amazon.smithy.rust.codegen.client.util.toSnakeCase
import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency
import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol

/**
* [ServerOperationRegistryGenerator] renders the `OperationRegistry` struct, a place where users can register their
Expand All @@ -49,7 +49,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType
*/
class ServerOperationRegistryGenerator(
private val coreCodegenContext: CoreCodegenContext,
private val protocol: Protocol,
private val protocol: ServerProtocol,
private val operations: List<OperationShape>,
) {
private val crateName = coreCodegenContext.settings.moduleName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.DefaultPublicModules
import software.amazon.smithy.rust.codegen.client.smithy.RustCrate
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolTestGenerator

Expand All @@ -31,7 +30,7 @@ open class ServerServiceGenerator(
private val rustCrate: RustCrate,
private val protocolGenerator: ProtocolGenerator,
private val protocolSupport: ProtocolSupport,
private val protocol: Protocol,
private val protocol: ServerProtocol,
private val coreCodegenContext: CoreCodegenContext,
) {
private val index = TopDownIndex.of(coreCodegenContext.model)
Expand Down
Loading