Skip to content

Commit

Permalink
Move serverContentTypeCheckNoModeledInput to server protocols
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ahmed <[email protected]>
  • Loading branch information
82marbag authored and Daniele Ahmed committed Sep 13, 2022
1 parent 71869d6 commit 20974d3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,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
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersio
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson
import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml
import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator
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.protocols.ServerAwsJsonSerializerGenerator

private fun allOperations(coreCodegenContext: CoreCodegenContext): List<OperationShape> {
val index = TopDownIndex.of(coreCodegenContext.model)
Expand Down Expand Up @@ -87,6 +89,9 @@ class ServerAwsJsonProtocol(
private val symbolProvider = coreCodegenContext.symbolProvider
private val service = coreCodegenContext.serviceShape

override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator =
ServerAwsJsonSerializerGenerator(coreCodegenContext, httpBindingResolver, awsJsonVersion)

companion object {
fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol = ServerAwsJsonProtocol(awsJson.coreCodegenContext, awsJson.version)
}
Expand Down Expand Up @@ -221,6 +226,8 @@ class ServerRestJsonProtocol(
): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape)

override fun serverRouterRuntimeConstructor() = "new_rest_json_router"

override fun serverContentTypeCheckNoModeledInput() = true
}

class ServerRestXmlProtocol(
Expand Down Expand Up @@ -248,4 +255,6 @@ class ServerRestXmlProtocol(
): Writable = RestRequestSpecGenerator(httpBindingResolver, requestSpecModule).generate(operationShape)

override fun serverRouterRuntimeConstructor() = "new_rest_xml_router"

override fun serverContentTypeCheckNoModeledInput() = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.traits.ErrorTrait
import software.amazon.smithy.rust.codegen.client.rustlang.Writable
import software.amazon.smithy.rust.codegen.client.rustlang.escape
Expand All @@ -14,25 +13,25 @@ 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.ServerCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJson
import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion
import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory
import software.amazon.smithy.rust.codegen.client.smithy.protocols.awsJsonFieldName
import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonCustomization
import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSection
import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSerializerGenerator
import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator
import software.amazon.smithy.rust.codegen.client.util.hasTrait
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerAwsJsonProtocol
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol

/**
* AwsJson 1.0 and 1.1 server-side protocol factory. This factory creates the [ServerHttpBoundProtocolGenerator]
* with AwsJson specific configurations.
*/
class ServerAwsJsonFactory(private val version: AwsJsonVersion) :
ProtocolGeneratorFactory<ServerHttpBoundProtocolGenerator, ServerCodegenContext> {
override fun protocol(codegenContext: ServerCodegenContext): Protocol = ServerAwsJson(codegenContext, version)
override fun protocol(codegenContext: ServerCodegenContext): ServerProtocol = ServerAwsJsonProtocol(codegenContext, version)

override fun buildProtocolGenerator(codegenContext: ServerCodegenContext): ServerHttpBoundProtocolGenerator =
ServerHttpBoundProtocolGenerator(codegenContext, protocol(codegenContext))
Expand Down Expand Up @@ -93,11 +92,3 @@ class ServerAwsJsonSerializerGenerator(
customizations = listOf(ServerAwsJsonError(awsJsonVersion)),
),
) : StructuredDataSerializerGenerator by jsonSerializerGenerator

class ServerAwsJson(
coreCodegenContext: CoreCodegenContext,
private val awsJsonVersion: AwsJsonVersion,
) : AwsJson(coreCodegenContext, awsJsonVersion) {
override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator =
ServerAwsJsonSerializerGenerator(coreCodegenContext, httpBindingResolver, awsJsonVersion)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.isOptional
import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingDescriptor
import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolPayloadGenerator
import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator
import software.amazon.smithy.rust.codegen.client.smithy.toOptional
import software.amazon.smithy.rust.codegen.client.smithy.traits.SyntheticInputTrait
Expand Down Expand Up @@ -89,7 +88,7 @@ import java.util.logging.Logger
*/
class ServerHttpBoundProtocolGenerator(
codegenContext: ServerCodegenContext,
protocol: Protocol,
protocol: ServerProtocol,
) : ProtocolGenerator(
codegenContext,
protocol,
Expand All @@ -115,7 +114,7 @@ class ServerHttpBoundProtocolGenerator(
*/
private class ServerHttpBoundProtocolTraitImplGenerator(
private val codegenContext: ServerCodegenContext,
private val protocol: Protocol,
private val protocol: ServerProtocol,
) : ProtocolTraitImplGenerator {
private val logger = Logger.getLogger(javaClass.name)
private val symbolProvider = codegenContext.symbolProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Pro
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory
import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestJsonProtocol

/**
* RestJson1 server-side protocol factory. This factory creates the [ServerHttpProtocolGenerator]
Expand All @@ -19,7 +20,7 @@ class ServerRestJsonFactory : ProtocolGeneratorFactory<ServerHttpBoundProtocolGe
override fun protocol(codegenContext: ServerCodegenContext): Protocol = RestJson(codegenContext)

override fun buildProtocolGenerator(codegenContext: ServerCodegenContext): ServerHttpBoundProtocolGenerator =
ServerHttpBoundProtocolGenerator(codegenContext, RestJson(codegenContext))
ServerHttpBoundProtocolGenerator(codegenContext, ServerRestJsonProtocol(codegenContext))

override fun support(): ProtocolSupport {
return ProtocolSupport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Pro
import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory
import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestXmlProtocol

/*
* RestXml server-side protocol factory. This factory creates the [ServerHttpProtocolGenerator]
Expand All @@ -19,7 +20,7 @@ class ServerRestXmlFactory : ProtocolGeneratorFactory<ServerHttpBoundProtocolGen
override fun protocol(codegenContext: ServerCodegenContext): Protocol = RestXml(codegenContext)

override fun buildProtocolGenerator(codegenContext: ServerCodegenContext): ServerHttpBoundProtocolGenerator =
ServerHttpBoundProtocolGenerator(codegenContext, RestXml(codegenContext))
ServerHttpBoundProtocolGenerator(codegenContext, ServerRestXmlProtocol(codegenContext))

override fun support(): ProtocolSupport {
return ProtocolSupport(
Expand Down

0 comments on commit 20974d3

Please sign in to comment.