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

simpleRestJson: add protocol tests for default body behavior #163

Merged
merged 7 commits into from
May 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$version: "2"

namespace alloy.test

use alloy#simpleRestJson
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

apply HttpPayloadWithDefault @httpRequestTests([{
id: "SimpleRestJsonSomeHttpPayloadWithDefault"
documentation: "Pass JSON string value as is if payload provided"
protocol: simpleRestJson
method: "PUT"
uri: "/httpPayloadWithDefault"
body: "\"custom value\""
headers: {
"Content-Type": "application/json"
}
requireHeaders: ["Content-Length"]
params: {
body: "custom value"
}
bodyMediaType: "application/json"
}, {
id: "SimpleRestJsonNoneHttpPayloadWithDefault"
documentation: "Use default value when there is no payload"
protocol: simpleRestJson
method: "PUT"
uri: "/httpPayloadWithDefault"
params: {
body: "default value"
}
}])

apply HttpPayloadWithDefault @httpResponseTests([{
id: "SimpleRestJsonSomeHttpPayloadWithDefault"
documentation: "Pass JSON string value as is if payload provided"
protocol: simpleRestJson
code: 200
body: "\"custom value\""
bodyMediaType: "application/json"
headers: {
"Content-Type": "application/json"
}
params: {
body: "custom value"
}
}, {
id: "SimpleRestJsonNoneHttpPayloadWithDefault"
documentation: "Use default value when there is no payload"
protocol: simpleRestJson
code: 200
params: {
body: "default value"
}
}])
17 changes: 15 additions & 2 deletions modules/protocol-tests/resources/META-INF/smithy/Pizza.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloy#simpleRestJson
service PizzaAdminService {
version: "1.0.0",
errors: [GenericServerError, GenericClientError],
operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode]
operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault]
}

@http(method: "POST", uri: "/restaurant/{restaurant}/menu/item", code: 201)
Expand Down Expand Up @@ -302,4 +302,17 @@ structure CustomCodeInput {
structure CustomCodeOutput {
@httpResponseCode
code: Integer
}
}

@idempotent
@http(uri: "/httpPayloadWithDefault", method: "PUT")
operation HttpPayloadWithDefault {
input: HttpPayloadWithDefaultInputOutput,
output: HttpPayloadWithDefaultInputOutput
}

structure HttpPayloadWithDefaultInputOutput {
@httpPayload
@default("default value")
body: String,
}
3 changes: 2 additions & 1 deletion modules/protocol-tests/resources/META-INF/smithy/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Health.smithy
Pizza.smithy
RoundTrip.smithy
Version.smithy
test-config.json
HttpPayloadWithDefault.smithy
test-config.json
Loading