5
5
6
6
package software.amazon.smithy.rust.codegen.server.smithy.protocols
7
7
8
- import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait
9
- import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait
10
- import software.amazon.smithy.aws.traits.protocols.RestJson1Trait
11
- import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
12
8
import software.amazon.smithy.codegen.core.Symbol
13
9
import software.amazon.smithy.model.knowledge.HttpBindingIndex
14
10
import software.amazon.smithy.model.node.ExpectationNotMetException
@@ -20,7 +16,6 @@ import software.amazon.smithy.model.shapes.MemberShape
20
16
import software.amazon.smithy.model.shapes.NumberShape
21
17
import software.amazon.smithy.model.shapes.OperationShape
22
18
import software.amazon.smithy.model.shapes.Shape
23
- import software.amazon.smithy.model.shapes.StringShape
24
19
import software.amazon.smithy.model.shapes.StructureShape
25
20
import software.amazon.smithy.model.traits.ErrorTrait
26
21
import software.amazon.smithy.model.traits.HttpErrorTrait
@@ -124,13 +119,7 @@ class ServerHttpBoundProtocolGenerator(
124
119
) : ServerProtocolGenerator(
125
120
protocol,
126
121
ServerHttpBoundProtocolTraitImplGenerator (codegenContext, protocol, customizations, additionalHttpBindingCustomizations),
127
- ) {
128
- // Define suffixes for operation input / output / error wrappers
129
- companion object {
130
- const val OPERATION_INPUT_WRAPPER_SUFFIX = " OperationInputWrapper"
131
- const val OPERATION_OUTPUT_WRAPPER_SUFFIX = " OperationOutputWrapper"
132
- }
133
- }
122
+ )
134
123
135
124
class ServerHttpBoundProtocolPayloadGenerator (
136
125
codegenContext : CodegenContext ,
@@ -697,8 +686,6 @@ class ServerHttpBoundProtocolTraitImplGenerator(
697
686
inputShape : StructureShape ,
698
687
bindings : List <HttpBindingDescriptor >,
699
688
) {
700
- val httpBindingGenerator =
701
- ServerRequestBindingGenerator (protocol, codegenContext, operationShape, additionalHttpBindingCustomizations)
702
689
val structuredDataParser = protocol.structuredDataParser()
703
690
Attribute .AllowUnusedMut .render(this )
704
691
rust(
@@ -740,7 +727,7 @@ class ServerHttpBoundProtocolTraitImplGenerator(
740
727
for (binding in bindings) {
741
728
val member = binding.member
742
729
val parsedValue =
743
- serverRenderBindingParser(binding, operationShape, httpBindingGenerator, structuredDataParser)
730
+ serverRenderBindingParser(binding, operationShape, httpBindingGenerator(operationShape) , structuredDataParser)
744
731
val valueToSet =
745
732
if (symbolProvider.toSymbol(binding.member).isOptional()) {
746
733
" Some(value)"
@@ -801,13 +788,8 @@ class ServerHttpBoundProtocolTraitImplGenerator(
801
788
val structureShapeHandler: RustWriter .(String ) -> Unit = { body ->
802
789
rust(" #T($body )" , structuredDataParser.payloadParser(binding.member))
803
790
}
804
- val errorSymbol = getDeserializePayloadErrorSymbol(binding)
805
791
val deserializer =
806
- httpBindingGenerator.generateDeserializePayloadFn(
807
- binding,
808
- errorSymbol,
809
- structuredHandler = structureShapeHandler,
810
- )
792
+ httpBindingGenerator.generateDeserializePayloadFn(binding, structuredHandler = structureShapeHandler)
811
793
return writable {
812
794
if (binding.member.isStreaming(model)) {
813
795
rustTemplate(
@@ -1196,9 +1178,7 @@ class ServerHttpBoundProtocolTraitImplGenerator(
1196
1178
binding : HttpBindingDescriptor ,
1197
1179
operationShape : OperationShape ,
1198
1180
) {
1199
- val httpBindingGenerator =
1200
- ServerRequestBindingGenerator (protocol, codegenContext, operationShape, additionalHttpBindingCustomizations)
1201
- val deserializer = httpBindingGenerator.generateDeserializeHeaderFn(binding)
1181
+ val deserializer = httpBindingGenerator(operationShape).generateDeserializeHeaderFn(binding)
1202
1182
writer.rustTemplate(
1203
1183
"""
1204
1184
#{deserializer}(&headers)?
@@ -1215,8 +1195,7 @@ class ServerHttpBoundProtocolTraitImplGenerator(
1215
1195
) {
1216
1196
check(binding.location == HttpLocation .PREFIX_HEADERS )
1217
1197
1218
- val httpBindingGenerator = ServerRequestBindingGenerator (protocol, codegenContext, operationShape)
1219
- val deserializer = httpBindingGenerator.generateDeserializePrefixHeadersFn(binding)
1198
+ val deserializer = httpBindingGenerator(operationShape).generateDeserializePrefixHeadersFn(binding)
1220
1199
writer.rustTemplate(
1221
1200
"""
1222
1201
#{deserializer}(&headers)?
@@ -1300,33 +1279,13 @@ class ServerHttpBoundProtocolTraitImplGenerator(
1300
1279
}
1301
1280
}
1302
1281
1303
- /* *
1304
- * Returns the error type of the function that deserializes a non-streaming HTTP payload (a byte slab) into the
1305
- * shape targeted by the `httpPayload` trait.
1306
- */
1307
- private fun getDeserializePayloadErrorSymbol (binding : HttpBindingDescriptor ): Symbol {
1308
- check(binding.location == HttpLocation .PAYLOAD )
1309
-
1310
- if (model.expectShape(binding.member.target) is StringShape ) {
1311
- return protocol.requestRejection(runtimeConfig).toSymbol()
1312
- }
1313
- return when (codegenContext.protocol) {
1314
- RestJson1Trait .ID , AwsJson1_0Trait .ID , AwsJson1_1Trait .ID -> {
1315
- RuntimeType .smithyJson(runtimeConfig).resolve(" deserialize::error::DeserializeError" ).toSymbol()
1316
- }
1317
- RestXmlTrait .ID -> {
1318
- RuntimeType .smithyXml(runtimeConfig).resolve(" decode::XmlDecodeError" ).toSymbol()
1319
- }
1320
- else -> {
1321
- TODO (" Protocol ${codegenContext.protocol} not supported yet" )
1322
- }
1323
- }
1324
- }
1325
-
1326
1282
private fun streamingBodyTraitBounds (operationShape : OperationShape ) =
1327
1283
if (operationShape.inputShape(model).hasStreamingMember(model)) {
1328
1284
" \n B: Into<#{SmithyTypes}::byte_stream::ByteStream>,"
1329
1285
} else {
1330
1286
" "
1331
1287
}
1288
+
1289
+ private fun httpBindingGenerator (operationShape : OperationShape ) =
1290
+ ServerRequestBindingGenerator (protocol, codegenContext, operationShape, additionalHttpBindingCustomizations)
1332
1291
}
0 commit comments