-
Notifications
You must be signed in to change notification settings - Fork 218
/
empty-input-output.smithy
246 lines (228 loc) · 7.57 KB
/
empty-input-output.smithy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// This file defines test cases that test the basics of empty input and
// output shape serialization.
//
// TODO: does an operation with no input always send {}? What about no output?
$version: "2.0"
namespace aws.protocoltests.restjson
use aws.protocols#restJson1
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
/// The example tests how requests and responses are serialized when there's
/// no request or response payload because the operation has no input or output.
/// While this should be rare, code generators must support this.
@http(uri: "/NoInputAndNoOutput", method: "POST")
operation NoInputAndNoOutput {}
apply NoInputAndNoOutput @httpRequestTests([
{
id: "RestJsonNoInputAndNoOutput",
documentation: """
No input serializes no payload. When clients do not need to
serialize any data in the payload, they should omit a payload
altogether.""",
protocol: restJson1,
method: "POST",
uri: "/NoInputAndNoOutput",
body: ""
},
{
id: "RestJsonNoInputAllowsAccept",
documentation: """
Servers should allow the accept header to be set to the
default content-type.""",
protocol: restJson1,
method: "POST",
uri: "/NoInputAndNoOutput",
body: "",
headers: {
"Accept": "application/json"
},
appliesTo: "server",
}
])
apply NoInputAndNoOutput @httpResponseTests([
{
id: "RestJsonNoInputAndNoOutput",
documentation: """
When an operation does not define output, the service will respond
with an empty payload, and may optionally include the content-type
header.""",
protocol: restJson1,
code: 200,
body: ""
}
])
/// This test is similar to NoInputAndNoOutput, but uses explicit Unit types.
@http(uri: "/UnitInputAndOutput", method: "POST")
operation UnitInputAndOutput {
input: Unit,
output: Unit
}
apply UnitInputAndOutput @httpRequestTests([
{
id: "RestJsonUnitInputAndOutput",
documentation: """
A unit type input serializes no payload. When clients do not
need to serialize any data in the payload, they should omit
a payload altogether.""",
protocol: restJson1,
method: "POST",
uri: "/UnitInputAndOutput",
body: ""
},
{
id: "RestJsonUnitInputAllowsAccept",
documentation: """
Servers should allow the accept header to be set to the
default content-type.""",
protocol: restJson1,
method: "POST",
uri: "/UnitInputAndOutput",
body: "",
headers: {
"Accept": "application/json"
},
appliesTo: "server",
}
])
apply UnitInputAndOutput @httpResponseTests([
{
id: "RestJsonUnitInputAndOutputNoOutput",
documentation: """
When an operation defines Unit output, the service will respond
with an empty payload, and may optionally include the content-type
header.""",
protocol: restJson1,
code: 200,
body: ""
}
])
/// The example tests how requests and responses are serialized when there's
/// no request or response payload because the operation has no input and the
/// output is empty. While this should be rare, code generators must support
/// this.
@http(uri: "/NoInputAndOutputOutput", method: "POST")
operation NoInputAndOutput {
output: NoInputAndOutputOutput
}
apply NoInputAndOutput @httpRequestTests([
{
id: "RestJsonNoInputAndOutput",
documentation: """
No input serializes no payload. When clients do not need to
serialize any data in the payload, they should omit a payload
altogether.""",
protocol: restJson1,
method: "POST",
uri: "/NoInputAndOutputOutput",
body: "",
},
{
id: "RestJsonNoInputAndOutputAllowsAccept",
documentation: """
Servers should allow the accept header to be set to the
default content-type.""",
protocol: restJson1,
method: "POST",
uri: "/NoInputAndOutputOutput",
body: "",
headers: {
"Accept": "application/json"
},
appliesTo: "server"
}
])
apply NoInputAndOutput @httpResponseTests([
{
id: "RestJsonNoInputAndOutputWithJson",
documentation: """
Operations that define output and do not bind anything to
the payload return a JSON object in the response.""",
protocol: restJson1,
code: 200,
body: "{}",
bodyMediaType: "application/json",
headers: {
"Content-Type": "application/json"
},
},
{
id: "RestJsonNoInputAndOutputNoPayload",
documentation: """
This test is similar to RestJsonNoInputAndOutputWithJson, but
it ensures that clients can gracefully handle responses that
omit a JSON payload.""",
protocol: restJson1,
code: 200,
body: "",
appliesTo: "client",
}
])
@output
structure NoInputAndOutputOutput {}
/// The example tests how requests and responses are serialized when there's
/// no request or response payload because the operation has an empty input
/// and empty output structure that reuses the same shape. While this should
/// be rare, code generators must support this.
@http(uri: "/EmptyInputAndEmptyOutput", method: "POST")
operation EmptyInputAndEmptyOutput {
input: EmptyInputAndEmptyOutputInput,
output: EmptyInputAndEmptyOutputOutput
}
apply EmptyInputAndEmptyOutput @httpRequestTests([
{
id: "RestJsonEmptyInputAndEmptyOutput",
documentation: """
Clients should not serialize a JSON payload when no parameters
are given that are sent in the body. A service will tolerate
clients that omit a payload or that send a JSON object.""",
protocol: restJson1,
method: "POST",
uri: "/EmptyInputAndEmptyOutput",
body: "",
},
{
id: "RestJsonEmptyInputAndEmptyOutputWithJson",
documentation: """
Similar to RestJsonEmptyInputAndEmptyOutput, but ensures that
services gracefully handles receiving a JSON object.""",
protocol: restJson1,
method: "POST",
uri: "/EmptyInputAndEmptyOutput",
headers: {
"Content-Type": "application/json",
},
body: "{}",
bodyMediaType: "application/json",
appliesTo: "server",
},
])
apply EmptyInputAndEmptyOutput @httpResponseTests([
{
id: "RestJsonEmptyInputAndEmptyOutput",
documentation: """
As of January 2021, server implementations are expected to
respond with a JSON object regardless of if the output
parameters are empty.""",
protocol: restJson1,
code: 200,
headers: {
"Content-Type": "application/json",
},
body: "{}",
bodyMediaType: "application/json",
},
{
id: "RestJsonEmptyInputAndEmptyOutputJsonObjectOutput",
documentation: """
This test ensures that clients can gracefully handle
situations where a service omits a JSON payload entirely.""",
protocol: restJson1,
code: 200,
body: "",
appliesTo: "client",
},
])
@input
structure EmptyInputAndEmptyOutputInput {}
@output
structure EmptyInputAndEmptyOutputOutput {}