Loading codegen-server-test/build.gradle.kts +6 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ val CodegenTests = listOf( CodegenTest("com.amazonaws.ebs#Ebs", "ebs") ) /** * The fluent client is generated to prevent warnings in RustDoc since the client is * referenced by multiple documentations. * TODO: review client generation in the future. */ fun generateSmithyBuild(tests: List<CodegenTest>): String { val projections = tests.joinToString(",\n") { Loading @@ -35,7 +40,7 @@ fun generateSmithyBuild(tests: List<CodegenTest>): String { "plugins": { "rust-server-codegen": { "codegen": { "includeFluentClient": false "includeFluentClient": true }, "runtimeConfig": { "relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime" Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/RestJson1.kt +26 −38 Original line number Diff line number Diff line Loading @@ -102,9 +102,6 @@ class RestJson1HttpSerializerGenerator( return } val serializerSymbol = jsonSerializerGenerator.serverOutputSerializer(operationShape) if (serializerSymbol == null) { return } val outputSymbol = symbolProvider.toSymbol(outputShape) writer.write("") writer.rustBlockTemplate( Loading Loading @@ -169,7 +166,6 @@ class RestJson1HttpSerializerGenerator( val variantSymbol = symbolProvider.toSymbol(variantShape) val data = safeName("var") val serializerSymbol = jsonSerializerGenerator.serverErrorSerializer(it) if (serializerSymbol != null) { rustBlock("#TKind::${variantSymbol.name}($data) =>", errorSymbol) { rust( """ Loading Loading @@ -203,11 +199,6 @@ class RestJson1HttpSerializerGenerator( ?: errorTrait.defaultHttpStatusCode rust("response = response.status($status);") } } else { logger.warning( "[rust-server-codegen] $variantShape: response error serialization does not contain any member" ) } } rust( """ Loading Loading @@ -369,9 +360,6 @@ class RestJson1HttpDeserializerGenerator( return } val deserializerSymbol = jsonParserGenerator.serverInputParser(operationShape) if (deserializerSymbol == null) { return } val inputSymbol = symbolProvider.toSymbol(inputShape) writer.write("") writer.rustBlockTemplate( Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/JsonParserGenerator.kt +12 −6 Original line number Diff line number Diff line Loading @@ -83,14 +83,14 @@ class JsonParserGenerator( /** * Reusable structure parser implementation that can be used to generate parsing code for * operation, error and structure shapes. * We still generate the parser symbol even if there are no included members because the server * generation requires parsers for all input structures. */ private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType? { if (includedMembers.isEmpty()) { return null } private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType { val unusedMut = if (includedMembers.isEmpty()) "##[allow(unused_mut)] " else "" return RuntimeType.forInlineFun(fnName, jsonDeserModule) { it.rustBlockTemplate( "pub fn $fnName(value: &[u8], mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>", "pub fn $fnName(value: &[u8], ${unusedMut}mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>", "Builder" to structureShape.builderSymbol(symbolProvider), *codegenScope ) { Loading Loading @@ -138,12 +138,18 @@ class JsonParserGenerator( override fun operationParser(operationShape: OperationShape): RuntimeType? { // Don't generate an operation JSON deserializer if there is no JSON body val httpDocumentMembers = httpBindingResolver.responseMembers(operationShape, HttpLocation.DOCUMENT) if (httpDocumentMembers.isEmpty()) { return null } val outputShape = operationShape.outputShape(model) val fnName = symbolProvider.deserializeFunctionName(operationShape) return structureParser(fnName, outputShape, httpDocumentMembers) } override fun errorParser(errorShape: StructureShape): RuntimeType? { if (errorShape.members().isEmpty()) { return null } val fnName = symbolProvider.deserializeFunctionName(errorShape) + "_json_err" return structureParser(fnName, errorShape, errorShape.members().toList()) } Loading Loading @@ -184,7 +190,7 @@ class JsonParserGenerator( ) } override fun serverInputParser(operationShape: OperationShape): RuntimeType? { override fun serverInputParser(operationShape: OperationShape): RuntimeType { val inputShape = operationShape.inputShape(model) val includedMembers = httpBindingResolver.requestMembers(operationShape, HttpLocation.DOCUMENT) val fnName = symbolProvider.deserializeFunctionName(inputShape) Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/StructuredDataParserGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -66,5 +66,5 @@ interface StructuredDataParserGenerator { * } * ``` */ fun serverInputParser(operationShape: OperationShape): RuntimeType? fun serverInputParser(operationShape: OperationShape): RuntimeType } codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -241,7 +241,7 @@ class XmlBindingTraitParserGenerator( TODO("Document shapes are not supported by rest XML") } override fun serverInputParser(operationShape: OperationShape): RuntimeType? { override fun serverInputParser(operationShape: OperationShape): RuntimeType { TODO("Not yet implemented") } Loading Loading
codegen-server-test/build.gradle.kts +6 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ val CodegenTests = listOf( CodegenTest("com.amazonaws.ebs#Ebs", "ebs") ) /** * The fluent client is generated to prevent warnings in RustDoc since the client is * referenced by multiple documentations. * TODO: review client generation in the future. */ fun generateSmithyBuild(tests: List<CodegenTest>): String { val projections = tests.joinToString(",\n") { Loading @@ -35,7 +40,7 @@ fun generateSmithyBuild(tests: List<CodegenTest>): String { "plugins": { "rust-server-codegen": { "codegen": { "includeFluentClient": false "includeFluentClient": true }, "runtimeConfig": { "relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime" Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/RestJson1.kt +26 −38 Original line number Diff line number Diff line Loading @@ -102,9 +102,6 @@ class RestJson1HttpSerializerGenerator( return } val serializerSymbol = jsonSerializerGenerator.serverOutputSerializer(operationShape) if (serializerSymbol == null) { return } val outputSymbol = symbolProvider.toSymbol(outputShape) writer.write("") writer.rustBlockTemplate( Loading Loading @@ -169,7 +166,6 @@ class RestJson1HttpSerializerGenerator( val variantSymbol = symbolProvider.toSymbol(variantShape) val data = safeName("var") val serializerSymbol = jsonSerializerGenerator.serverErrorSerializer(it) if (serializerSymbol != null) { rustBlock("#TKind::${variantSymbol.name}($data) =>", errorSymbol) { rust( """ Loading Loading @@ -203,11 +199,6 @@ class RestJson1HttpSerializerGenerator( ?: errorTrait.defaultHttpStatusCode rust("response = response.status($status);") } } else { logger.warning( "[rust-server-codegen] $variantShape: response error serialization does not contain any member" ) } } rust( """ Loading Loading @@ -369,9 +360,6 @@ class RestJson1HttpDeserializerGenerator( return } val deserializerSymbol = jsonParserGenerator.serverInputParser(operationShape) if (deserializerSymbol == null) { return } val inputSymbol = symbolProvider.toSymbol(inputShape) writer.write("") writer.rustBlockTemplate( Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/JsonParserGenerator.kt +12 −6 Original line number Diff line number Diff line Loading @@ -83,14 +83,14 @@ class JsonParserGenerator( /** * Reusable structure parser implementation that can be used to generate parsing code for * operation, error and structure shapes. * We still generate the parser symbol even if there are no included members because the server * generation requires parsers for all input structures. */ private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType? { if (includedMembers.isEmpty()) { return null } private fun structureParser(fnName: String, structureShape: StructureShape, includedMembers: List<MemberShape>): RuntimeType { val unusedMut = if (includedMembers.isEmpty()) "##[allow(unused_mut)] " else "" return RuntimeType.forInlineFun(fnName, jsonDeserModule) { it.rustBlockTemplate( "pub fn $fnName(value: &[u8], mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>", "pub fn $fnName(value: &[u8], ${unusedMut}mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>", "Builder" to structureShape.builderSymbol(symbolProvider), *codegenScope ) { Loading Loading @@ -138,12 +138,18 @@ class JsonParserGenerator( override fun operationParser(operationShape: OperationShape): RuntimeType? { // Don't generate an operation JSON deserializer if there is no JSON body val httpDocumentMembers = httpBindingResolver.responseMembers(operationShape, HttpLocation.DOCUMENT) if (httpDocumentMembers.isEmpty()) { return null } val outputShape = operationShape.outputShape(model) val fnName = symbolProvider.deserializeFunctionName(operationShape) return structureParser(fnName, outputShape, httpDocumentMembers) } override fun errorParser(errorShape: StructureShape): RuntimeType? { if (errorShape.members().isEmpty()) { return null } val fnName = symbolProvider.deserializeFunctionName(errorShape) + "_json_err" return structureParser(fnName, errorShape, errorShape.members().toList()) } Loading Loading @@ -184,7 +190,7 @@ class JsonParserGenerator( ) } override fun serverInputParser(operationShape: OperationShape): RuntimeType? { override fun serverInputParser(operationShape: OperationShape): RuntimeType { val inputShape = operationShape.inputShape(model) val includedMembers = httpBindingResolver.requestMembers(operationShape, HttpLocation.DOCUMENT) val fnName = symbolProvider.deserializeFunctionName(inputShape) Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/StructuredDataParserGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -66,5 +66,5 @@ interface StructuredDataParserGenerator { * } * ``` */ fun serverInputParser(operationShape: OperationShape): RuntimeType? fun serverInputParser(operationShape: OperationShape): RuntimeType }
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -241,7 +241,7 @@ class XmlBindingTraitParserGenerator( TODO("Document shapes are not supported by rest XML") } override fun serverInputParser(operationShape: OperationShape): RuntimeType? { override fun serverInputParser(operationShape: OperationShape): RuntimeType { TODO("Not yet implemented") } Loading