Skip to content

Commit

Permalink
RestJson with body expects application/json content type (#2330)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
  • Loading branch information
82marbag authored and LukeMathWalker committed Feb 13, 2023
1 parent 729cd96 commit 53b4092
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -628,7 +629,20 @@ private class ServerHttpBoundProtocolTraitImplGenerator(
"""
let bytes = #{Hyper}::body::to_bytes(body).await?;
if !bytes.is_empty() {
input = #{parser}(bytes.as_ref(), input)?;
""",
*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)?;
}
""",
*codegenScope,
Expand Down

0 comments on commit 53b4092

Please sign in to comment.