Skip to content

Commit

Permalink
Add test cases for required+default+httpPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Jun 25, 2024
1 parent 8eb295c commit 4ce6c2e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
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
}

0 comments on commit 4ce6c2e

Please sign in to comment.