Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestJson with body expects application/json content type #2330

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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