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

Add test cases for required+default+httpPayload #175

Merged
merged 1 commit into from
Jul 1, 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
Expand Up @@ -54,3 +54,52 @@ apply HttpPayloadWithDefault @httpResponseTests([{
body: "default value"
}
}])

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

apply HttpPayloadRequiredWithDefault @httpResponseTests([{
id: "SimpleRestJsonSomeRequiredHttpPayloadWithDefault"
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: "SimpleRestJsonNoneRequiredHttpPayloadWithDefault"
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 @@ -4,12 +4,11 @@ namespace alloy.test

use alloy#simpleRestJson


@simpleRestJson
service PizzaAdminService {
version: "1.0.0",
errors: [GenericServerError, GenericClientError],
operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault]
operations: [AddMenuItem, GetMenu, Version, Health, HeaderEndpoint, RoundTrip, GetEnum, GetIntEnum, CustomCode, HttpPayloadWithDefault, HttpPayloadRequiredWithDefault]
}

@http(method: "POST", uri: "/restaurant/{restaurant}/menu/item", code: 201)
Expand Down Expand Up @@ -316,3 +315,17 @@ structure HttpPayloadWithDefaultInputOutput {
@default("default value")
body: String,
}

@idempotent
@http(uri: "/httpPayloadRequiredWithDefault", method: "PUT")
operation HttpPayloadRequiredWithDefault {
input: HttpPayloadRequiredWithDefaultInputOutput
output: HttpPayloadRequiredWithDefaultInputOutput
}

structure HttpPayloadRequiredWithDefaultInputOutput {
@httpPayload
@default("default value")
@required
body: String
}
Loading