Unverified Commit 78203c02 authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

RestJson with body expects application/json content type (#2330)

parent bf678fd7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -772,8 +772,6 @@ class ServerProtocolTestGenerator(
            FailingTest(RestJson, "RestJsonEndpointTrait", TestType.Request),
            FailingTest(RestJson, "RestJsonEndpointTraitWithHostLabel", TestType.Request),

            FailingTest(RestJson, "RestJsonWithBodyExpectsApplicationJsonContentType", TestType.MalformedRequest),

            // Tests involving `@range` on floats.
            // Pending resolution from the Smithy team, see https://github.com/awslabs/smithy-rs/issues/2007.
            FailingTest(RestJsonValidation, "RestJsonMalformedRangeFloat_case0", TestType.MalformedRequest),
+15 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.mapRustType
import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor
import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtocolPayloadGenerator
import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation
import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson
import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait
import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors
@@ -628,6 +629,19 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
                """
                let bytes = #{Hyper}::body::to_bytes(body).await?;
                if !bytes.is_empty() {
                """,
                *codegenScope,
            )
            if (protocol is RestJson) {
                rustTemplate(
                    """
                    #{SmithyHttpServer}::protocols::content_type_header_classifier(&parts.headers, Some("application/json"))?;
                    """,
                    *codegenScope,
                )
            }
            rustTemplate(
                """
                input = #{parser}(bytes.as_ref(), input)?;
                }
                """,