diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt index 4956624491d56a6dc0a6d815354c3b2ad13c7965..da31f42c765796eba7d92e7707b0bb7270020bae 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt @@ -451,12 +451,12 @@ private class ServerHttpProtocolImplGenerator( bindings: List, ) { val structuredDataSerializer = protocol.structuredDataSerializer(operationShape) - structuredDataSerializer.serverOutputSerializer(operationShape).also { serializer -> + structuredDataSerializer.serverOutputSerializer(operationShape)?.let { serializer -> rust( "let payload = #T(output)?;", serializer ) - } + } ?: rust("""let payload = "";""") // avoid non-usage warnings for response Attribute.AllowUnusedMut.render(this) rustTemplate("let mut response = #{http}::Response::builder();", *codegenScope) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/XmlNameIndex.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/XmlNameIndex.kt index d837d9a59a28608952d77d9f2dfa6ec9e8299b72..767daab42221aa799ec87ab0617de3934c9f7fb4 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/XmlNameIndex.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/XmlNameIndex.kt @@ -63,5 +63,6 @@ data class XmlMemberIndex(val dataMembers: List, val attributeMembe } } - fun isNotEmpty() = dataMembers.isNotEmpty() || attributeMembers.isNotEmpty() + fun isEmpty() = dataMembers.isEmpty() && attributeMembers.isEmpty() + fun isNotEmpty() = !isEmpty() } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt index 6f8cf6fccb86215a0fb72e7736fb23187fc9d9e3..75385d3e3be61a8935c8265762b415887d72f2b4 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt @@ -22,7 +22,7 @@ class AwsQuerySerializerGenerator(codegenContext: CodegenContext) : QuerySeriali override fun MemberShape.isFlattened(): Boolean = getTrait() != null - override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType { + override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType? { TODO("Not yet implemented") } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt index cfcd4fde4f19bb28ea4514f8c393bc864c93a1ba..3a1e3af79106354e7d4ae7438299db2bc3686402 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt @@ -25,7 +25,7 @@ class Ec2QuerySerializerGenerator(codegenContext: CodegenContext) : QuerySeriali override fun MemberShape.isFlattened(): Boolean = true - override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType { + override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType? { TODO("Not yet implemented") } diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt index 57466d2fc5d1e80704c88f05fe02bd7dc094a250..f97144802384556acbd0fe20b9e2e086f46c6837 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -242,7 +242,7 @@ class JsonSerializerGenerator( } } - override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType { + override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType? { val outputShape = operationShape.outputShape(model) val includedMembers = httpBindingResolver.responseMembers(operationShape, HttpLocation.DOCUMENT) val fnName = symbolProvider.serializeFunctionName(outputShape) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt index 0a4d1d0ee355c9460bcf9cc99c1f44658786f7a4..117a950b558ba5de7de7b913d275d5ca46b13e77 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt @@ -55,7 +55,7 @@ interface StructuredDataSerializerGenerator { * } * ``` */ - fun serverOutputSerializer(operationShape: OperationShape): RuntimeType + fun serverOutputSerializer(operationShape: OperationShape): RuntimeType? /** * Generate a serializer for a server operation error structure diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 6ac9ea9ea602cccd096501e964bec7f9c06bdfd6..66b697c9ebb9eb4eb2df5a9c1ffd90d730c994b0 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -106,8 +106,8 @@ class XmlBindingTraitSerializerGenerator( override fun operationSerializer(operationShape: OperationShape): RuntimeType? { val fnName = symbolProvider.serializeFunctionName(operationShape) val inputShape = operationShape.inputShape(model) - val xmlMembers = operationShape.operationXmlMembers() - if (!xmlMembers.isNotEmpty()) { + val xmlMembers = operationShape.requestBodyMembers() + if (xmlMembers.isEmpty()) { return null } val operationXmlName = xmlIndex.operationInputShapeName(operationShape) @@ -191,10 +191,13 @@ class XmlBindingTraitSerializerGenerator( } } - override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType { + override fun serverOutputSerializer(operationShape: OperationShape): RuntimeType? { val fnName = symbolProvider.serializeFunctionName(operationShape) val outputShape = operationShape.outputShape(model) - val xmlMembers = operationShape.operationXmlMembers() + val xmlMembers = operationShape.responseBodyMembers() + if (xmlMembers.isEmpty()) { + return null + } val operationXmlName = xmlIndex.operationOutputShapeName(operationShape) ?: throw CodegenException("operation must have a name if it has members") return RuntimeType.forInlineFun(fnName, operationSerModule) { @@ -466,9 +469,12 @@ class XmlBindingTraitSerializerGenerator( } } - private fun OperationShape.operationXmlMembers(): XmlMemberIndex = + private fun OperationShape.requestBodyMembers(): XmlMemberIndex = XmlMemberIndex.fromMembers(httpBindingResolver.requestMembers(this, HttpLocation.DOCUMENT)) + private fun OperationShape.responseBodyMembers(): XmlMemberIndex = + XmlMemberIndex.fromMembers(httpBindingResolver.responseMembers(this, HttpLocation.DOCUMENT)) + private fun Shape.xmlNamespace(root: Boolean): XmlNamespaceTrait? { return this.getTrait().letIf(root) { it ?: rootNamespace } }