-
Notifications
You must be signed in to change notification settings - Fork 215
/
http-query.smithy
708 lines (649 loc) · 19.3 KB
/
http-query.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
// This file defines test cases that test HTTP query string bindings.
// See: https://smithy.io/2.0/spec/http-bindings.html#httpquery-trait and
// https://smithy.io/2.0/spec/http-bindings.html#httpqueryparams-trait
$version: "2.0"
namespace aws.protocoltests.restjson
use aws.protocols#restJson1
use aws.protocoltests.shared#BooleanList
use aws.protocoltests.shared#DoubleList
use aws.protocoltests.shared#FooEnum
use aws.protocoltests.shared#FooEnumList
use aws.protocoltests.shared#IntegerEnum
use aws.protocoltests.shared#IntegerEnumList
use aws.protocoltests.shared#IntegerList
use aws.protocoltests.shared#IntegerSet
use aws.protocoltests.shared#StringList
use aws.protocoltests.shared#StringListMap
use aws.protocoltests.shared#StringMap
use aws.protocoltests.shared#StringSet
use aws.protocoltests.shared#TimestampList
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
/// This example uses all query string types.
@readonly
@http(uri: "/AllQueryStringTypesInput", method: "GET")
operation AllQueryStringTypes {
input: AllQueryStringTypesInput
}
apply AllQueryStringTypes @httpRequestTests([
{
id: "RestJsonAllQueryStringTypes",
documentation: "Serializes query string parameters with all supported types",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"String=Hello%20there",
"StringList=a",
"StringList=b",
"StringList=c",
"StringSet=a",
"StringSet=b",
"StringSet=c",
"Byte=1",
"Short=2",
"Integer=3",
"IntegerList=1",
"IntegerList=2",
"IntegerList=3",
"IntegerSet=1",
"IntegerSet=2",
"IntegerSet=3",
"Long=4",
"Float=1.1",
"Double=1.1",
"DoubleList=1.1",
"DoubleList=2.1",
"DoubleList=3.1",
"Boolean=true",
"BooleanList=true",
"BooleanList=false",
"BooleanList=true",
"Timestamp=1970-01-01T00%3A00%3A01Z",
"TimestampList=1970-01-01T00%3A00%3A01Z",
"TimestampList=1970-01-01T00%3A00%3A02Z",
"TimestampList=1970-01-01T00%3A00%3A03Z",
"Enum=Foo",
"EnumList=Foo",
"EnumList=Baz",
"EnumList=Bar",
"IntegerEnum=1",
"IntegerEnumList=1",
"IntegerEnumList=2",
"IntegerEnumList=3",
],
params: {
queryString: "Hello there",
queryStringList: ["a", "b", "c"],
queryStringSet: ["a", "b", "c"],
queryByte: 1,
queryShort: 2,
queryInteger: 3,
queryIntegerList: [1, 2, 3],
queryIntegerSet: [1, 2, 3],
queryLong: 4,
queryFloat: 1.1,
queryDouble: 1.1,
queryDoubleList: [1.1, 2.1, 3.1],
queryBoolean: true,
queryBooleanList: [true, false, true],
queryTimestamp: 1,
queryTimestampList: [1, 2, 3],
queryEnum: "Foo",
queryEnumList: ["Foo", "Baz", "Bar"],
queryIntegerEnum: 1,
queryIntegerEnumList: [1, 2, 3],
queryParamsMapOfStringList: {
"String": ["Hello there"],
"StringList": ["a", "b", "c"],
"StringSet": ["a", "b", "c"],
"Byte": ["1"],
"Short": ["2"],
"Integer": ["3"],
"IntegerList": ["1", "2", "3"],
"IntegerSet": ["1", "2", "3"],
"Long": ["4"],
"Float": ["1.1"],
"Double": ["1.1"],
"DoubleList": ["1.1", "2.1", "3.1"],
"Boolean": ["true"],
"BooleanList": ["true", "false", "true"],
"Timestamp": ["1970-01-01T00:00:01Z"],
"TimestampList": ["1970-01-01T00:00:01Z", "1970-01-01T00:00:02Z", "1970-01-01T00:00:03Z"],
"Enum": ["Foo"],
"EnumList": ["Foo", "Baz", "Bar"],
"IntegerEnum": ["1"],
"IntegerEnumList": ["1", "2", "3"]
},
}
},
{
id: "RestJsonQueryStringMap",
documentation: "Handles query string maps",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"QueryParamsStringKeyA=Foo",
"QueryParamsStringKeyB=Bar",
],
params: {
queryParamsMapOfStringList: {
"QueryParamsStringKeyA": ["Foo"],
"QueryParamsStringKeyB": ["Bar"],
},
}
},
{
id: "RestJsonQueryStringEscaping",
documentation: "Handles escaping all required characters in the query string.",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"String=%20%25%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%F0%9F%98%B9",
],
params: {
queryString: " %:/?#[]@!$&'()*+,;=😹",
queryParamsMapOfStringList: {
"String": [" %:/?#[]@!$&'()*+,;=😹"]
}
}
},
{
id: "RestJsonSupportsNaNFloatQueryValues",
documentation: "Supports handling NaN float query values.",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"Float=NaN",
"Double=NaN",
],
params: {
queryFloat: "NaN",
queryDouble: "NaN",
queryParamsMapOfStringList: {
"Float": ["NaN"],
"Double": ["NaN"],
}
}
},
{
id: "RestJsonSupportsInfinityFloatQueryValues",
documentation: "Supports handling Infinity float query values.",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"Float=Infinity",
"Double=Infinity",
],
params: {
queryFloat: "Infinity",
queryDouble: "Infinity",
queryParamsMapOfStringList: {
"Float": ["Infinity"],
"Double": ["Infinity"],
}
}
},
{
id: "RestJsonSupportsNegativeInfinityFloatQueryValues",
documentation: "Supports handling -Infinity float query values.",
protocol: restJson1,
method: "GET",
uri: "/AllQueryStringTypesInput",
body: "",
queryParams: [
"Float=-Infinity",
"Double=-Infinity",
],
params: {
queryFloat: "-Infinity",
queryDouble: "-Infinity",
queryParamsMapOfStringList: {
"Float": ["-Infinity"],
"Double": ["-Infinity"],
}
}
},
{
id: "RestJsonZeroAndFalseQueryValues"
documentation: "Query values of 0 and false are serialized"
protocol: restJson1
method: "GET"
uri: "/AllQueryStringTypesInput"
body: ""
queryParams: [
"Integer=0"
"Boolean=false"
]
params: {
queryInteger: 0
queryBoolean: false
}
}
])
@suppress(["HttpQueryParamsTrait"])
structure AllQueryStringTypesInput {
@httpQuery("String")
queryString: String,
@httpQuery("StringList")
queryStringList: StringList,
@httpQuery("StringSet")
queryStringSet: StringSet,
@httpQuery("Byte")
queryByte: Byte,
@httpQuery("Short")
queryShort: Short,
@httpQuery("Integer")
queryInteger: Integer,
@httpQuery("IntegerList")
queryIntegerList: IntegerList,
@httpQuery("IntegerSet")
queryIntegerSet: IntegerSet,
@httpQuery("Long")
queryLong: Long,
@httpQuery("Float")
queryFloat: Float,
@httpQuery("Double")
queryDouble: Double,
@httpQuery("DoubleList")
queryDoubleList: DoubleList,
@httpQuery("Boolean")
queryBoolean: Boolean,
@httpQuery("BooleanList")
queryBooleanList: BooleanList,
@httpQuery("Timestamp")
queryTimestamp: Timestamp,
@httpQuery("TimestampList")
queryTimestampList: TimestampList,
@httpQuery("Enum")
queryEnum: FooEnum,
@httpQuery("EnumList")
queryEnumList: FooEnumList,
@httpQuery("IntegerEnum")
queryIntegerEnum: IntegerEnum,
@httpQuery("IntegerEnumList")
queryIntegerEnumList: IntegerEnumList,
@httpQueryParams
queryParamsMapOfStringList: StringListMap,
}
/// This example uses a constant query string parameters and a label.
/// This simply tests that labels and query string parameters are
/// compatible. The fixed query string parameter named "hello" should
/// in no way conflict with the label, `{hello}`.
@readonly
@http(uri: "/ConstantQueryString/{hello}?foo=bar&hello", method: "GET")
@httpRequestTests([
{
id: "RestJsonConstantQueryString",
documentation: "Includes constant query string parameters",
protocol: restJson1,
method: "GET",
uri: "/ConstantQueryString/hi",
queryParams: [
"foo=bar",
"hello",
],
body: "",
params: {
hello: "hi"
}
},
])
operation ConstantQueryString {
input: ConstantQueryStringInput
}
structure ConstantQueryStringInput {
@httpLabel
@required
hello: String,
}
/// This example uses fixed query string params and variable query string params.
/// The fixed query string parameters and variable parameters must both be
/// serialized (implementations may need to merge them together).
@readonly
@http(uri: "/ConstantAndVariableQueryString?foo=bar", method: "GET")
operation ConstantAndVariableQueryString {
input: ConstantAndVariableQueryStringInput
}
apply ConstantAndVariableQueryString @httpRequestTests([
{
id: "RestJsonConstantAndVariableQueryStringMissingOneValue",
documentation: "Mixes constant and variable query string parameters",
protocol: restJson1,
method: "GET",
uri: "/ConstantAndVariableQueryString",
queryParams: [
"foo=bar",
"baz=bam",
],
forbidQueryParams: ["maybeSet"],
body: "",
params: {
baz: "bam"
}
},
{
id: "RestJsonConstantAndVariableQueryStringAllValues",
documentation: "Mixes constant and variable query string parameters",
protocol: restJson1,
method: "GET",
uri: "/ConstantAndVariableQueryString",
queryParams: [
"foo=bar",
"baz=bam",
"maybeSet=yes"
],
body: "",
params: {
baz: "bam",
maybeSet: "yes"
}
},
])
structure ConstantAndVariableQueryStringInput {
@httpQuery("baz")
baz: String,
@httpQuery("maybeSet")
maybeSet: String,
}
/// This example ensures that query string bound request parameters are
/// serialized in the body of responses if the structure is used in both
/// the request and response.
@readonly
@http(uri: "/IgnoreQueryParamsInResponse", method: "GET")
operation IgnoreQueryParamsInResponse {
output: IgnoreQueryParamsInResponseOutput
}
apply IgnoreQueryParamsInResponse @httpResponseTests([
{
id: "RestJsonIgnoreQueryParamsInResponse",
documentation: """
Query parameters must be ignored when serializing the output
of an operation. 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",
params: {}
},
{
id: "RestJsonIgnoreQueryParamsInResponseNoPayload",
documentation: """
This test is similar to RestJsonIgnoreQueryParamsInResponse,
but it ensures that clients gracefully handle responses from
the server that do not serialize an empty JSON object.""",
protocol: restJson1,
code: 200,
body: "",
params: {},
appliesTo: "client",
},
])
structure IgnoreQueryParamsInResponseOutput {
@httpQuery("baz")
@suppress(["HttpBindingTraitIgnored"])
baz: String
}
/// Omits null, but serializes empty string value.
@readonly
@http(uri: "/OmitsNullSerializesEmptyString", method: "GET")
operation OmitsNullSerializesEmptyString {
input: OmitsNullSerializesEmptyStringInput
}
apply OmitsNullSerializesEmptyString @httpRequestTests([
{
id: "RestJsonOmitsNullQuery",
documentation: "Omits null query values",
protocol: restJson1,
method: "GET",
uri: "/OmitsNullSerializesEmptyString",
body: "",
params: {
nullValue: null
},
"appliesTo": "client",
},
{
id: "RestJsonSerializesEmptyQueryValue",
documentation: "Serializes empty query strings",
protocol: restJson1,
method: "GET",
uri: "/OmitsNullSerializesEmptyString",
body: "",
queryParams: [
"Empty=",
],
params: {
emptyString: "",
},
},
{
id: "RestJsonServersAcceptStaticQueryParamAsEmptyString",
documentation: "Servers accept static query params as empty strings.",
protocol: restJson1,
method: "GET",
uri: "/OmitsNullSerializesEmptyString",
body: "",
queryParams: [
"Empty",
],
params: {
emptyString: "",
},
appliesTo: "server"
},
])
structure OmitsNullSerializesEmptyStringInput {
@httpQuery("Null")
nullValue: String,
@httpQuery("Empty")
emptyString: String,
}
/// Omits serializing empty lists. Because empty strings are serilized as
/// `Foo=`, empty lists cannot also be serialized as `Foo=` and instead
/// must be omitted.
@http(uri: "/OmitsSerializingEmptyLists", method: "POST")
@tags(["client-only"])
operation OmitsSerializingEmptyLists {
input: OmitsSerializingEmptyListsInput
}
apply OmitsSerializingEmptyLists @httpRequestTests([
{
id: "RestJsonOmitsEmptyListQueryValues",
documentation: "Supports omitting empty lists.",
protocol: restJson1,
method: "POST",
uri: "/OmitsSerializingEmptyLists",
body: "",
queryParams: [],
params: {
queryStringList: [],
queryIntegerList: [],
queryDoubleList: [],
queryBooleanList: [],
queryTimestampList: [],
queryEnumList: [],
queryIntegerEnumList: [],
}
}
])
structure OmitsSerializingEmptyListsInput {
@httpQuery("StringList")
queryStringList: StringList,
@httpQuery("IntegerList")
queryIntegerList: IntegerList,
@httpQuery("DoubleList")
queryDoubleList: DoubleList,
@httpQuery("BooleanList")
queryBooleanList: BooleanList,
@httpQuery("TimestampList")
queryTimestampList: TimestampList,
@httpQuery("EnumList")
queryEnumList: FooEnumList,
@httpQuery("IntegerEnumList")
queryIntegerEnumList: IntegerEnumList,
}
/// Automatically adds idempotency tokens.
@http(uri: "/QueryIdempotencyTokenAutoFill", method: "POST")
@tags(["client-only"])
operation QueryIdempotencyTokenAutoFill {
input: QueryIdempotencyTokenAutoFillInput
}
apply QueryIdempotencyTokenAutoFill @httpRequestTests([
{
id: "RestJsonQueryIdempotencyTokenAutoFill",
documentation: "Automatically adds idempotency token when not set",
protocol: restJson1,
method: "POST",
uri: "/QueryIdempotencyTokenAutoFill",
body: "",
queryParams: [
"token=00000000-0000-4000-8000-000000000000",
],
appliesTo: "client",
},
{
id: "RestJsonQueryIdempotencyTokenAutoFillIsSet",
documentation: "Uses the given idempotency token as-is",
protocol: restJson1,
method: "POST",
uri: "/QueryIdempotencyTokenAutoFill",
body: "",
queryParams: [
"token=00000000-0000-4000-8000-000000000000",
],
params: {
token: "00000000-0000-4000-8000-000000000000"
},
appliesTo: "client",
}
])
structure QueryIdempotencyTokenAutoFillInput {
@httpQuery("token")
@idempotencyToken
token: String,
}
// Clients must make named query members take precedence over unnamed members
// and servers must use all query params in the unnamed map.
@http(uri: "/Precedence", method: "POST")
operation QueryPrecedence {
input: QueryPrecedenceInput
}
apply QueryPrecedence @httpRequestTests([
{
id: "RestJsonQueryPrecedence",
documentation: "Prefer named query parameters when serializing",
protocol: restJson1,
method: "POST",
uri: "/Precedence",
body: "",
queryParams: [
"bar=named",
"qux=alsoFromMap"
],
params: {
foo: "named",
baz: {
bar: "fromMap",
qux: "alsoFromMap"
}
},
appliesTo: "client",
},
{
id: "RestJsonServersPutAllQueryParamsInMap",
documentation: "Servers put all query params in map",
protocol: restJson1,
method: "POST",
uri: "/Precedence",
body: "",
queryParams: [
"bar=named",
"qux=fromMap"
],
params: {
foo: "named",
baz: {
bar: "named",
qux: "fromMap"
}
},
appliesTo: "server",
}
])
@suppress(["HttpQueryParamsTrait"])
structure QueryPrecedenceInput {
@httpQuery("bar")
foo: String,
@httpQueryParams
baz: StringMap
}
// httpQueryParams as Map of ListStrings
@http(uri: "/StringListMap", method: "POST")
operation QueryParamsAsStringListMap {
input: QueryParamsAsStringListMapInput
}
apply QueryParamsAsStringListMap @httpRequestTests([
{
id: "RestJsonQueryParamsStringListMap",
documentation: "Serialize query params from map of list strings",
protocol: restJson1,
method: "POST",
uri: "/StringListMap",
body: "",
queryParams: [
"corge=named",
"baz=bar",
"baz=qux"
],
params: {
qux: "named",
foo: {
"baz": ["bar", "qux"]
}
},
appliesTo: "client"
},
{
id: "RestJsonServersQueryParamsStringListMap",
documentation: "Servers put all query params in map",
protocol: restJson1,
method: "POST",
uri: "/StringListMap",
body: "",
queryParams: [
"corge=named",
"baz=bar",
"baz=qux"
],
params: {
qux: "named",
foo: {
"corge": ["named"],
"baz": ["bar", "qux"]
}
},
appliesTo: "server"
}
])
@suppress(["HttpQueryParamsTrait"])
structure QueryParamsAsStringListMapInput {
@httpQuery("corge")
qux: String,
@httpQueryParams
foo: StringListMap
}