@typespec/http-specs 0.1.0-alpha.27-dev.0 → 0.1.0-alpha.27-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,6 +69,42 @@ namespace Query {
69
69
  input: duration,
70
70
  ): NoContentResponse;
71
71
 
72
+ @route("/int32-milliseconds")
73
+ @scenario
74
+ @scenarioDoc("""
75
+ Test int32 milliseconds encode for a duration parameter.
76
+ Expected query parameter `input=36000`
77
+ """)
78
+ op int32Milliseconds(
79
+ @query
80
+ @encode(DurationKnownEncoding.milliseconds, int32)
81
+ input: duration,
82
+ ): NoContentResponse;
83
+
84
+ @route("/float-milliseconds")
85
+ @scenario
86
+ @scenarioDoc("""
87
+ Test float milliseconds encode for a duration parameter.
88
+ Expected query parameter `input=35625`
89
+ """)
90
+ op floatMilliseconds(
91
+ @query
92
+ @encode(DurationKnownEncoding.milliseconds, float)
93
+ input: duration,
94
+ ): NoContentResponse;
95
+
96
+ @route("/float64-milliseconds")
97
+ @scenario
98
+ @scenarioDoc("""
99
+ Test float64 milliseconds encode for a duration parameter.
100
+ Expected query parameter `input=35625`
101
+ """)
102
+ op float64Milliseconds(
103
+ @query
104
+ @encode(DurationKnownEncoding.milliseconds, float64)
105
+ input: duration,
106
+ ): NoContentResponse;
107
+
72
108
  @encode(DurationKnownEncoding.seconds, int32)
73
109
  scalar Int32Duration extends duration;
74
110
 
@@ -82,6 +118,20 @@ namespace Query {
82
118
  @query
83
119
  input: Int32Duration[],
84
120
  ): NoContentResponse;
121
+
122
+ @encode(DurationKnownEncoding.milliseconds, int32)
123
+ scalar Int32MillisecondsDuration extends duration;
124
+
125
+ @route("/int32-milliseconds-array")
126
+ @scenario
127
+ @scenarioDoc("""
128
+ Test int32 milliseconds encode for a duration array parameter.
129
+ Expected query parameter `input=36000,47000`
130
+ """)
131
+ op int32MillisecondsArray(
132
+ @query
133
+ input: Int32MillisecondsDuration[],
134
+ ): NoContentResponse;
85
135
  }
86
136
 
87
137
  @route("/property")
@@ -110,6 +160,21 @@ namespace Property {
110
160
  value: duration;
111
161
  }
112
162
 
163
+ model Int32MillisecondsDurationProperty {
164
+ @encode(DurationKnownEncoding.milliseconds, int32)
165
+ value: duration;
166
+ }
167
+
168
+ model FloatMillisecondsDurationProperty {
169
+ @encode(DurationKnownEncoding.milliseconds, float)
170
+ value: duration;
171
+ }
172
+
173
+ model Float64MillisecondsDurationProperty {
174
+ @encode(DurationKnownEncoding.milliseconds, float64)
175
+ value: duration;
176
+ }
177
+
113
178
  @encode(DurationKnownEncoding.seconds, float32)
114
179
  scalar Float32Duration extends duration;
115
180
 
@@ -117,6 +182,13 @@ namespace Property {
117
182
  value: Float32Duration[];
118
183
  }
119
184
 
185
+ @encode(DurationKnownEncoding.milliseconds, float32)
186
+ scalar Float32MillisecondsDuration extends duration;
187
+
188
+ model FloatMillisecondsDurationArrayProperty {
189
+ value: Float32MillisecondsDuration[];
190
+ }
191
+
120
192
  @route("/default")
121
193
  @scenario
122
194
  @scenarioDoc("""
@@ -214,6 +286,69 @@ namespace Property {
214
286
  """)
215
287
  op float64Seconds(@body body: Float64SecondsDurationProperty): Float64SecondsDurationProperty;
216
288
 
289
+ @route("/int32-milliseconds")
290
+ @scenario
291
+ @scenarioDoc("""
292
+ Test operation with request and response model contains a duration property with int32 milliseconds encode.
293
+ Expected request body:
294
+ ```json
295
+ {
296
+ "value": 36000
297
+ }
298
+ ```
299
+ Expected response body:
300
+ ```json
301
+ {
302
+ "value": 36000
303
+ }
304
+ ```
305
+ """)
306
+ op int32Milliseconds(
307
+ @body body: Int32MillisecondsDurationProperty,
308
+ ): Int32MillisecondsDurationProperty;
309
+
310
+ @route("/float-milliseconds")
311
+ @scenario
312
+ @scenarioDoc("""
313
+ Test operation with request and response model contains a duration property with float milliseconds encode.
314
+ Expected request body:
315
+ ```json
316
+ {
317
+ "value": 35625
318
+ }
319
+ ```
320
+ Expected response body:
321
+ ```json
322
+ {
323
+ "value": 35625
324
+ }
325
+ ```
326
+ """)
327
+ op floatMilliseconds(
328
+ @body body: FloatMillisecondsDurationProperty,
329
+ ): FloatMillisecondsDurationProperty;
330
+
331
+ @route("/float64-milliseconds")
332
+ @scenario
333
+ @scenarioDoc("""
334
+ Test operation with request and response model contains a duration property with float64 milliseconds encode.
335
+ Expected request body:
336
+ ```json
337
+ {
338
+ "value": 35625
339
+ }
340
+ ```
341
+ Expected response body:
342
+ ```json
343
+ {
344
+ "value": 35625
345
+ }
346
+ ```
347
+ """)
348
+ op float64Milliseconds(
349
+ @body body: Float64MillisecondsDurationProperty,
350
+ ): Float64MillisecondsDurationProperty;
351
+
217
352
  @route("/float-seconds-array")
218
353
  @scenario
219
354
  @scenarioDoc("""
@@ -234,6 +369,27 @@ namespace Property {
234
369
  op floatSecondsArray(
235
370
  @body body: FloatSecondsDurationArrayProperty,
236
371
  ): FloatSecondsDurationArrayProperty;
372
+
373
+ @route("/float-milliseconds-array")
374
+ @scenario
375
+ @scenarioDoc("""
376
+ Test operation with request and response model contains an array property which elements are duration with float milliseconds encode.
377
+ Expected request body:
378
+ ```json
379
+ {
380
+ "value": [35625, 46750]
381
+ }
382
+ ```
383
+ Expected response body:
384
+ ```json
385
+ {
386
+ "value": [35625, 46750]
387
+ }
388
+ ```
389
+ """)
390
+ op floatMillisecondsArray(
391
+ @body body: FloatMillisecondsDurationArrayProperty,
392
+ ): FloatMillisecondsDurationArrayProperty;
237
393
  }
238
394
 
239
395
  @route("/header")
@@ -310,4 +466,54 @@ namespace Header {
310
466
  @encode(DurationKnownEncoding.seconds, float64)
311
467
  duration: duration,
312
468
  ): NoContentResponse;
469
+
470
+ @route("/int32-milliseconds")
471
+ @scenario
472
+ @scenarioDoc("""
473
+ Test int32 milliseconds encode for a duration header.
474
+ Expected header `duration: 36000`
475
+ """)
476
+ op int32Milliseconds(
477
+ @header
478
+ @encode(DurationKnownEncoding.milliseconds, int32)
479
+ duration: duration,
480
+ ): NoContentResponse;
481
+
482
+ @route("/float-milliseconds")
483
+ @scenario
484
+ @scenarioDoc("""
485
+ Test float milliseconds encode for a duration header.
486
+ Expected header `duration: 35625`
487
+ """)
488
+ op floatMilliseconds(
489
+ @header
490
+ @encode(DurationKnownEncoding.milliseconds, float)
491
+ duration: duration,
492
+ ): NoContentResponse;
493
+
494
+ @route("/float64-milliseconds")
495
+ @scenario
496
+ @scenarioDoc("""
497
+ Test float64 milliseconds encode for a duration header.
498
+ Expected header `duration: 35625`
499
+ """)
500
+ op float64Milliseconds(
501
+ @header
502
+ @encode(DurationKnownEncoding.milliseconds, float64)
503
+ duration: duration,
504
+ ): NoContentResponse;
505
+
506
+ @encode(DurationKnownEncoding.milliseconds, int32)
507
+ scalar Int32MillisecondsDuration extends duration;
508
+
509
+ @route("/int32-milliseconds-array")
510
+ @scenario
511
+ @scenarioDoc("""
512
+ Test int32 milliseconds encode for a duration array header.
513
+ Expected header `duration: [36000,47000]`
514
+ """)
515
+ op int32MillisecondsArray(
516
+ @header
517
+ duration: Int32MillisecondsDuration[],
518
+ ): NoContentResponse;
313
519
  }
@@ -65,6 +65,35 @@ Scenarios.Encode_Duration_Property_floatSecondsArray = createBodyServerTests(
65
65
  [35.625, 46.75],
66
66
  );
67
67
 
68
+ Scenarios.Encode_Duration_Property_int32Milliseconds = createBodyServerTests(
69
+ "/encode/duration/property/int32-milliseconds",
70
+ {
71
+ value: 36000,
72
+ },
73
+ 36000,
74
+ );
75
+ Scenarios.Encode_Duration_Property_floatMilliseconds = createBodyServerTests(
76
+ "/encode/duration/property/float-milliseconds",
77
+ {
78
+ value: 35625,
79
+ },
80
+ 35625,
81
+ );
82
+ Scenarios.Encode_Duration_Property_float64Milliseconds = createBodyServerTests(
83
+ "/encode/duration/property/float64-milliseconds",
84
+ {
85
+ value: 35625,
86
+ },
87
+ 35625,
88
+ );
89
+ Scenarios.Encode_Duration_Property_floatMillisecondsArray = createBodyServerTests(
90
+ "/encode/duration/property/float-milliseconds-array",
91
+ {
92
+ value: [35625, 46750],
93
+ },
94
+ [35625, 46750],
95
+ );
96
+
68
97
  function createQueryServerTests(
69
98
  uri: string,
70
99
  paramData: any,
@@ -133,6 +162,36 @@ Scenarios.Encode_Duration_Query_float64Seconds = createQueryServerTests(
133
162
  "35.625",
134
163
  );
135
164
 
165
+ Scenarios.Encode_Duration_Query_int32Milliseconds = createQueryServerTests(
166
+ "/encode/duration/query/int32-milliseconds",
167
+ {
168
+ input: 36000,
169
+ },
170
+ "36000",
171
+ );
172
+ Scenarios.Encode_Duration_Query_floatMilliseconds = createQueryServerTests(
173
+ "/encode/duration/query/float-milliseconds",
174
+ {
175
+ input: 35625,
176
+ },
177
+ "35625",
178
+ );
179
+ Scenarios.Encode_Duration_Query_float64Milliseconds = createQueryServerTests(
180
+ "/encode/duration/query/float64-milliseconds",
181
+ {
182
+ input: 35625,
183
+ },
184
+ "35625",
185
+ );
186
+ Scenarios.Encode_Duration_Query_int32MillisecondsArray = createQueryServerTests(
187
+ "/encode/duration/query/int32-milliseconds-array",
188
+ {
189
+ input: [36000, 47000].join(","),
190
+ },
191
+ ["36000", "47000"],
192
+ "csv",
193
+ );
194
+
136
195
  function createHeaderServerTests(uri: string, headersData: any, value: any) {
137
196
  return passOnSuccess({
138
197
  uri,
@@ -189,3 +248,32 @@ Scenarios.Encode_Duration_Header_iso8601Array = createHeaderServerTests(
189
248
  },
190
249
  "P40D,P50D",
191
250
  );
251
+
252
+ Scenarios.Encode_Duration_Header_int32Milliseconds = createHeaderServerTests(
253
+ "/encode/duration/header/int32-milliseconds",
254
+ {
255
+ duration: "36000",
256
+ },
257
+ "36000",
258
+ );
259
+ Scenarios.Encode_Duration_Header_floatMilliseconds = createHeaderServerTests(
260
+ "/encode/duration/header/float-milliseconds",
261
+ {
262
+ duration: "35625",
263
+ },
264
+ "35625",
265
+ );
266
+ Scenarios.Encode_Duration_Header_float64Milliseconds = createHeaderServerTests(
267
+ "/encode/duration/header/float64-milliseconds",
268
+ {
269
+ duration: "35625",
270
+ },
271
+ "35625",
272
+ );
273
+ Scenarios.Encode_Duration_Header_int32MillisecondsArray = createHeaderServerTests(
274
+ "/encode/duration/header/int32-milliseconds-array",
275
+ {
276
+ duration: ["36000", "47000"].join(","),
277
+ },
278
+ "36000,47000",
279
+ );
@@ -449,27 +449,68 @@ namespace ServerDrivenPagination {
449
449
  }
450
450
  }
451
451
 
452
- @scenario
453
- @scenarioDoc("""
454
- Test case for simple pagination without nextlink or continuationToken.
455
-
456
- Single request:
457
- Expected route: /payload/pageable/simple
458
-
459
- Expected response body:
460
- ```json
461
- { "pets": [
462
- { "id": "1", "name": "dog" },
463
- { "id": "2", "name": "cat" },
464
- { "id": "3", "name": "bird" },
465
- { "id": "4", "name": "fish" }
466
- ]
467
- }
468
- ```
469
- """)
470
- @route("/simple")
471
- @list
472
- op listWithoutContinuation(): {
473
- @pageItems
474
- pets: Pet[];
475
- };
452
+ @route("/pagesize")
453
+ namespace PageSize {
454
+ @scenario
455
+ @scenarioDoc("""
456
+ Test case for simple pagination without nextlink or continuationToken.
457
+
458
+ Single request:
459
+ Expected route: /payload/pageable/pagesize/without-continuation
460
+
461
+ Expected response body:
462
+ ```json
463
+ { "pets": [
464
+ { "id": "1", "name": "dog" },
465
+ { "id": "2", "name": "cat" },
466
+ { "id": "3", "name": "bird" },
467
+ { "id": "4", "name": "fish" }
468
+ ]
469
+ }
470
+ ```
471
+ """)
472
+ @route("/without-continuation")
473
+ @list
474
+ op listWithoutContinuation(): {
475
+ @pageItems
476
+ pets: Pet[];
477
+ };
478
+
479
+ @scenario
480
+ @scenarioDoc("""
481
+ Test case for pagination with a regular @pageSize parameter.
482
+
483
+ Two requests need to be tested:
484
+ 1. Request with pageSize=2:
485
+ Expected route: /payload/pageable/pagesize/list?pageSize=2
486
+
487
+ Expected response body:
488
+ ```json
489
+ { "pets": [
490
+ { "id": "1", "name": "dog" },
491
+ { "id": "2", "name": "cat" }
492
+ ]
493
+ }
494
+ ```
495
+
496
+ 2. Request with pageSize=4:
497
+ Expected route: /payload/pageable/pagesize/list?pageSize=4
498
+
499
+ Expected response body:
500
+ ```json
501
+ { "pets": [
502
+ { "id": "1", "name": "dog" },
503
+ { "id": "2", "name": "cat" },
504
+ { "id": "3", "name": "bird" },
505
+ { "id": "4", "name": "fish" }
506
+ ]
507
+ }
508
+ ```
509
+ """)
510
+ @route("/list")
511
+ @list
512
+ op listWithPageSize(@pageSize @query pageSize?: int32): {
513
+ @pageItems
514
+ pets: Pet[];
515
+ };
516
+ }
@@ -187,9 +187,9 @@ Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQuery
187
187
  Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestHeaderResponseHeader =
188
188
  createTests("header", "header");
189
189
 
190
- Scenarios.Payload_Pageable_listWithoutContinuation = passOnSuccess([
190
+ Scenarios.Payload_Pageable_PageSize_listWithoutContinuation = passOnSuccess([
191
191
  {
192
- uri: "/payload/pageable/simple",
192
+ uri: "/payload/pageable/pagesize/without-continuation",
193
193
  method: "get",
194
194
  request: {},
195
195
  response: {
@@ -207,6 +207,101 @@ Scenarios.Payload_Pageable_listWithoutContinuation = passOnSuccess([
207
207
  },
208
208
  ]);
209
209
 
210
+ Scenarios.Payload_Pageable_PageSize_listWithPageSize = passOnSuccess([
211
+ {
212
+ uri: "/payload/pageable/pagesize/list",
213
+ method: "get",
214
+ request: { query: { pageSize: "2" } },
215
+ response: {
216
+ status: 200,
217
+ body: json({
218
+ pets: [
219
+ { id: "1", name: "dog" },
220
+ { id: "2", name: "cat" },
221
+ ],
222
+ }),
223
+ },
224
+ handler: (req: MockRequest) => {
225
+ const pageSize = req.query?.pageSize;
226
+
227
+ switch (pageSize) {
228
+ case "2":
229
+ return {
230
+ status: 200,
231
+ body: json({
232
+ pets: [
233
+ { id: "1", name: "dog" },
234
+ { id: "2", name: "cat" },
235
+ ],
236
+ }),
237
+ };
238
+ case "4":
239
+ return {
240
+ status: 200,
241
+ body: json({
242
+ pets: [
243
+ { id: "1", name: "dog" },
244
+ { id: "2", name: "cat" },
245
+ { id: "3", name: "bird" },
246
+ { id: "4", name: "fish" },
247
+ ],
248
+ }),
249
+ };
250
+ default:
251
+ throw new ValidationError("Unsupported page size", `"2" | "4"`, pageSize);
252
+ }
253
+ },
254
+ kind: "MockApiDefinition",
255
+ },
256
+ {
257
+ uri: "/payload/pageable/pagesize/list",
258
+ method: "get",
259
+ request: { query: { pageSize: "4" } },
260
+ response: {
261
+ status: 200,
262
+ body: json({
263
+ pets: [
264
+ { id: "1", name: "dog" },
265
+ { id: "2", name: "cat" },
266
+ { id: "3", name: "bird" },
267
+ { id: "4", name: "fish" },
268
+ ],
269
+ }),
270
+ },
271
+ handler: (req: MockRequest) => {
272
+ const pageSize = req.query?.pageSize;
273
+
274
+ switch (pageSize) {
275
+ case "2":
276
+ return {
277
+ status: 200,
278
+ body: json({
279
+ pets: [
280
+ { id: "1", name: "dog" },
281
+ { id: "2", name: "cat" },
282
+ ],
283
+ }),
284
+ };
285
+ case "4":
286
+ return {
287
+ status: 200,
288
+ body: json({
289
+ pets: [
290
+ { id: "1", name: "dog" },
291
+ { id: "2", name: "cat" },
292
+ { id: "3", name: "bird" },
293
+ { id: "4", name: "fish" },
294
+ ],
295
+ }),
296
+ };
297
+ default:
298
+ throw new ValidationError("Unsupported page size", `"2" | "4"`, pageSize);
299
+ }
300
+ },
301
+ kind: "MockApiDefinition",
302
+ },
303
+ ]);
304
+
210
305
  Scenarios.Payload_Pageable_ServerDrivenPagination_ContinuationToken_requestQueryNestedResponseBody =
211
306
  passOnSuccess([
212
307
  {