Unverified Commit b79cb265 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Remove unneeded doc parser (#1123)

* Remove unneeded doc parser

* Maintain identical behavior for empty documents

* Changelog
parent a183f124
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -11,6 +11,12 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[smithy-rs]]
message = "Refactor `Document` shape parser generation"
references = ["smithy-rs#1123"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = """
Moved the following re-exports into a `types` module for all services:
+1 −4
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@

package software.amazon.smithy.rust.codegen.server.smithy.generators.http


import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
@@ -29,14 +28,12 @@ class ServerRequestBindingGenerator(
        operationShape: OperationShape,
        binding: HttpBindingDescriptor,
        errorT: RuntimeType,
        structuredHandler: RustWriter.(String) -> Unit,
        docHandler: RustWriter.(String) -> Unit
        structuredHandler: RustWriter.(String) -> Unit
    ): RuntimeType = httpBindingGenerator.generateDeserializePayloadFn(
        operationShape,
        binding,
        errorT,
        structuredHandler,
        docHandler,
        HttpMessageType.REQUEST
    )
}
+0 −7
Original line number Diff line number Diff line
@@ -608,12 +608,6 @@ private class ServerHttpProtocolImplGenerator(
        return when (binding.location) {
            HttpLocation.HEADER -> writable { serverRenderHeaderParser(this, binding, operationShape) }
            HttpLocation.PAYLOAD -> {
                val docShapeHandler: RustWriter.(String) -> Unit = { body ->
                    rust(
                        "#T($body)",
                        structuredDataParser.documentParser(operationShape),
                    )
                }
                val structureShapeHandler: RustWriter.(String) -> Unit = { body ->
                    rust("#T($body)", structuredDataParser.payloadParser(binding.member))
                }
@@ -621,7 +615,6 @@ private class ServerHttpProtocolImplGenerator(
                    operationShape,
                    binding,
                    errorSymbol,
                    docHandler = docShapeHandler,
                    structuredHandler = structureShapeHandler
                )
                return if (binding.member.isStreaming(model)) {
+4 −9
Original line number Diff line number Diff line
@@ -174,10 +174,8 @@ class HttpBindingGenerator(
        operationShape: OperationShape,
        binding: HttpBindingDescriptor,
        errorT: RuntimeType,
        // Deserialize a single structure or union member marked as a payload
        structuredHandler: RustWriter.(String) -> Unit,
        // Deserialize a document type marked as a payload
        docHandler: RustWriter.(String) -> Unit,
        // Deserialize a single structure, union or document member marked as a payload
        payloadParser: RustWriter.(String) -> Unit,
        httpMessageType: HttpMessageType = HttpMessageType.RESPONSE
    ): RuntimeType {
        check(binding.location == HttpBinding.Location.PAYLOAD)
@@ -204,8 +202,7 @@ class HttpBindingGenerator(
                    deserializePayloadBody(
                        binding,
                        errorT,
                        structuredHandler = structuredHandler,
                        docShapeHandler = docHandler,
                        structuredHandler = payloadParser,
                        httpMessageType
                    )
                }
@@ -253,7 +250,6 @@ class HttpBindingGenerator(
        binding: HttpBindingDescriptor,
        errorSymbol: RuntimeType,
        structuredHandler: RustWriter.(String) -> Unit,
        docShapeHandler: RustWriter.(String) -> Unit,
        httpMessageType: HttpMessageType = HttpMessageType.RESPONSE
    ) {
        val member = binding.member
@@ -262,7 +258,7 @@ class HttpBindingGenerator(
        // of an empty instance of the response type.
        withBlock("(!body.is_empty()).then(||{", "}).transpose()") {
            when (targetShape) {
                is StructureShape, is UnionShape -> this.structuredHandler("body")
                is StructureShape, is UnionShape, is DocumentShape -> this.structuredHandler("body")
                is StringShape -> {
                    when (httpMessageType) {
                        HttpMessageType.RESPONSE -> {
@@ -288,7 +284,6 @@ class HttpBindingGenerator(
                    "Ok(#T::new(body))",
                    RuntimeType.Blob(runtimeConfig)
                )
                is DocumentShape -> this.docShapeHandler("body")
                // `httpPayload` can be applied to set/map/list shapes.
                // However, none of the AWS protocols support it.
                // Smithy CLI will refuse to build the model if you apply the trait to these shapes, so this branch
+2 −4
Original line number Diff line number Diff line
@@ -29,13 +29,11 @@ class ResponseBindingGenerator(
        operationShape: OperationShape,
        binding: HttpBindingDescriptor,
        errorT: RuntimeType,
        structuredHandler: RustWriter.(String) -> Unit,
        docHandler: RustWriter.(String) -> Unit
        payloadParser: RustWriter.(String) -> Unit
    ): RuntimeType = httpBindingGenerator.generateDeserializePayloadFn(
        operationShape,
        binding,
        errorT,
        structuredHandler,
        docHandler
        payloadParser
    )
}
Loading