@typespec/http-specs 0.37.2 → 0.38.0-dev.4
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.
- package/dist/specs/encode/duration/mockapi.js +6 -0
- package/dist/specs/encode/duration/mockapi.js.map +1 -1
- package/dist/specs/special-words/mockapi.js +1 -1
- package/dist/specs/special-words/mockapi.js.map +1 -1
- package/package.json +17 -16
- package/specs/authentication/api-key/main.tsp +2 -1
- package/specs/authentication/http/custom/main.tsp +1 -0
- package/specs/authentication/oauth2/main.tsp +2 -1
- package/specs/authentication/union/main.tsp +2 -1
- package/specs/encode/bytes/main.tsp +2 -8
- package/specs/encode/datetime/main.tsp +2 -7
- package/specs/encode/duration/main.tsp +2 -6
- package/specs/encode/duration/mockapi.ts +14 -0
- package/specs/encode/numeric/main.tsp +2 -4
- package/specs/parameters/basic/main.tsp +2 -5
- package/specs/parameters/body-optionality/main.tsp +2 -4
- package/specs/parameters/collection-format/main.tsp +2 -5
- package/specs/parameters/spread/main.tsp +2 -5
- package/specs/payload/json-merge-patch/main.tsp +2 -1
- package/specs/payload/media-type/main.tsp +2 -4
- package/specs/payload/multipart/main.tsp +2 -1
- package/specs/payload/xml/main.tsp +15 -25
- package/specs/routes/main.tsp +2 -1
- package/specs/serialization/encoded-name/json/main.tsp +2 -2
- package/specs/server/endpoint/not-defined/main.tsp +2 -1
- package/specs/server/path/multiple/main.tsp +2 -1
- package/specs/server/path/single/main.tsp +2 -1
- package/specs/server/versions/not-versioned/main.tsp +2 -1
- package/specs/server/versions/versioned/main.tsp +2 -3
- package/specs/special-headers/conditional-request/main.tsp +2 -2
- package/specs/special-headers/repeatability/main.tsp +2 -2
- package/specs/special-words/main.tsp +2 -6
- package/specs/special-words/mockapi.ts +1 -1
- package/specs/type/array/main.tsp +15 -39
- package/specs/type/dictionary/main.tsp +15 -36
- package/specs/type/enum/extensible/main.tsp +2 -1
- package/specs/type/enum/fixed/main.tsp +2 -2
- package/specs/type/model/empty/main.tsp +2 -1
- package/specs/type/model/inheritance/enum-discriminator/main.tsp +2 -2
- package/specs/type/model/inheritance/nested-discriminator/main.tsp +2 -1
- package/specs/type/model/inheritance/not-discriminated/main.tsp +2 -1
- package/specs/type/model/inheritance/recursive/main.tsp +2 -1
- package/specs/type/model/inheritance/single-discriminator/main.tsp +2 -1
- package/specs/type/model/templated/main.tsp +2 -2
- package/specs/type/model/usage/main.tsp +2 -1
- package/specs/type/model/visibility/main.tsp +2 -1
- package/specs/type/property/additional-properties/main.tsp +15 -57
- package/specs/type/property/nullable/main.tsp +31 -54
- package/specs/type/property/optionality/main.tsp +31 -63
- package/specs/type/property/value-types/main.tsp +15 -56
- package/specs/type/scalar/main.tsp +34 -62
- package/specs/type/union/main.tsp +5 -18
- package/specs/versioning/added/main.tsp +2 -1
- package/specs/versioning/madeOptional/main.tsp +2 -1
- package/specs/versioning/removed/main.tsp +2 -1
- package/specs/versioning/renamedFrom/main.tsp +2 -1
- package/specs/versioning/returnTypeChangedFrom/main.tsp +2 -1
- package/specs/versioning/typeChangedFrom/main.tsp +2 -1
- package/temp/.tsbuildinfo +1 -1
- package/specs/type/property/nullable/client.tsp +0 -21
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
5
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
6
|
|
|
7
7
|
@doc("Tests for additional properties of models")
|
|
8
8
|
@scenarioService("/type/property/additionalProperties")
|
|
9
9
|
namespace Type.Property.AdditionalProperties;
|
|
10
10
|
|
|
11
11
|
@doc("Template to have models operations")
|
|
12
|
-
interface ModelOperations<TModel, TDoc extends string> {
|
|
12
|
+
interface ModelOperations<TModel, TDoc extends valueof string> {
|
|
13
13
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
14
14
|
@scenario
|
|
15
|
-
@scenarioDoc(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
""",
|
|
22
|
-
{
|
|
23
|
-
doc: TDoc,
|
|
24
|
-
}
|
|
25
|
-
)
|
|
15
|
+
@scenarioDoc("""
|
|
16
|
+
Expected response body:
|
|
17
|
+
```json
|
|
18
|
+
${TDoc}
|
|
19
|
+
```
|
|
20
|
+
""")
|
|
26
21
|
@get
|
|
27
22
|
@doc("Get call")
|
|
28
23
|
get(): TModel;
|
|
@@ -30,17 +25,12 @@ interface ModelOperations<TModel, TDoc extends string> {
|
|
|
30
25
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
31
26
|
#suppress "@azure-tools/typespec-azure-core/bad-record-type" "For testing"
|
|
32
27
|
@scenario
|
|
33
|
-
@scenarioDoc(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
""",
|
|
40
|
-
{
|
|
41
|
-
doc: TDoc,
|
|
42
|
-
}
|
|
43
|
-
)
|
|
28
|
+
@scenarioDoc("""
|
|
29
|
+
Expected input body:
|
|
30
|
+
```json
|
|
31
|
+
${TDoc}
|
|
32
|
+
```
|
|
33
|
+
""")
|
|
44
34
|
@put
|
|
45
35
|
@doc("Put operation")
|
|
46
36
|
put(@body @doc("body") body: TModel): void;
|
|
@@ -55,7 +45,6 @@ model ExtendsUnknownAdditionalProperties extends Record<unknown> {
|
|
|
55
45
|
}
|
|
56
46
|
|
|
57
47
|
@route("/extendsRecordUnknown")
|
|
58
|
-
@operationGroup
|
|
59
48
|
interface ExtendsUnknown
|
|
60
49
|
extends ModelOperations<
|
|
61
50
|
ExtendsUnknownAdditionalProperties,
|
|
@@ -72,7 +61,6 @@ model ExtendsUnknownAdditionalPropertiesDerived extends ExtendsUnknownAdditional
|
|
|
72
61
|
}
|
|
73
62
|
|
|
74
63
|
@route("/extendsRecordUnknownDerived")
|
|
75
|
-
@operationGroup
|
|
76
64
|
interface ExtendsUnknownDerived
|
|
77
65
|
extends ModelOperations<
|
|
78
66
|
ExtendsUnknownAdditionalPropertiesDerived,
|
|
@@ -102,7 +90,6 @@ model ExtendsUnknownAdditionalPropertiesDiscriminatedDerived
|
|
|
102
90
|
}
|
|
103
91
|
|
|
104
92
|
@route("/extendsUnknownDiscriminated")
|
|
105
|
-
@operationGroup
|
|
106
93
|
interface ExtendsUnknownDiscriminated
|
|
107
94
|
extends ModelOperations<
|
|
108
95
|
ExtendsUnknownAdditionalPropertiesDiscriminated,
|
|
@@ -117,7 +104,6 @@ model IsUnknownAdditionalProperties is Record<unknown> {
|
|
|
117
104
|
}
|
|
118
105
|
|
|
119
106
|
@route("/isRecordUnknown")
|
|
120
|
-
@operationGroup
|
|
121
107
|
interface IsUnknown
|
|
122
108
|
extends ModelOperations<
|
|
123
109
|
IsUnknownAdditionalProperties,
|
|
@@ -134,7 +120,6 @@ model IsUnknownAdditionalPropertiesDerived extends IsUnknownAdditionalProperties
|
|
|
134
120
|
}
|
|
135
121
|
|
|
136
122
|
@route("/isRecordUnknownDerived")
|
|
137
|
-
@operationGroup
|
|
138
123
|
interface IsUnknownDerived
|
|
139
124
|
extends ModelOperations<
|
|
140
125
|
IsUnknownAdditionalPropertiesDerived,
|
|
@@ -164,7 +149,6 @@ model IsUnknownAdditionalPropertiesDiscriminatedDerived
|
|
|
164
149
|
}
|
|
165
150
|
|
|
166
151
|
@route("/isUnknownDiscriminated")
|
|
167
|
-
@operationGroup
|
|
168
152
|
interface IsUnknownDiscriminated
|
|
169
153
|
extends ModelOperations<
|
|
170
154
|
IsUnknownAdditionalPropertiesDiscriminated,
|
|
@@ -181,7 +165,6 @@ model ExtendsStringAdditionalProperties extends Record<string> {
|
|
|
181
165
|
}
|
|
182
166
|
|
|
183
167
|
@route("/extendsRecordString")
|
|
184
|
-
@operationGroup
|
|
185
168
|
interface ExtendsString
|
|
186
169
|
extends ModelOperations<
|
|
187
170
|
ExtendsStringAdditionalProperties,
|
|
@@ -196,7 +179,6 @@ model IsStringAdditionalProperties is Record<string> {
|
|
|
196
179
|
}
|
|
197
180
|
|
|
198
181
|
@route("/isRecordstring")
|
|
199
|
-
@operationGroup
|
|
200
182
|
interface IsString
|
|
201
183
|
extends ModelOperations<
|
|
202
184
|
IsStringAdditionalProperties,
|
|
@@ -212,7 +194,6 @@ model SpreadStringRecord {
|
|
|
212
194
|
}
|
|
213
195
|
|
|
214
196
|
@route("/spreadRecordString")
|
|
215
|
-
@operationGroup
|
|
216
197
|
interface SpreadString
|
|
217
198
|
extends ModelOperations<SpreadStringRecord, "{'name': 'SpreadSpringRecord', 'prop': 'abc'}"> {}
|
|
218
199
|
|
|
@@ -225,7 +206,6 @@ model ExtendsFloatAdditionalProperties extends Record<float32> {
|
|
|
225
206
|
}
|
|
226
207
|
|
|
227
208
|
@route("/extendsRecordFloat")
|
|
228
|
-
@operationGroup
|
|
229
209
|
interface ExtendsFloat
|
|
230
210
|
extends ModelOperations<ExtendsFloatAdditionalProperties, "{'id': 43.125, 'prop': 43.125}"> {}
|
|
231
211
|
|
|
@@ -237,7 +217,6 @@ model IsFloatAdditionalProperties is Record<float32> {
|
|
|
237
217
|
}
|
|
238
218
|
|
|
239
219
|
@route("/isRecordFloat")
|
|
240
|
-
@operationGroup
|
|
241
220
|
interface IsFloat
|
|
242
221
|
extends ModelOperations<IsFloatAdditionalProperties, "{'id': 43.125, 'prop': 43.125}"> {}
|
|
243
222
|
|
|
@@ -250,7 +229,6 @@ model SpreadFloatRecord {
|
|
|
250
229
|
}
|
|
251
230
|
|
|
252
231
|
@route("/spreadRecordFloat")
|
|
253
|
-
@operationGroup
|
|
254
232
|
interface SpreadFloat
|
|
255
233
|
extends ModelOperations<SpreadFloatRecord, "{'id': 43.125, 'prop': 43.125}"> {}
|
|
256
234
|
|
|
@@ -268,7 +246,6 @@ model ExtendsModelAdditionalProperties extends Record<ModelForRecord> {
|
|
|
268
246
|
}
|
|
269
247
|
|
|
270
248
|
@route("/extendsRecordModel")
|
|
271
|
-
@operationGroup
|
|
272
249
|
interface ExtendsModel
|
|
273
250
|
extends ModelOperations<
|
|
274
251
|
ExtendsModelAdditionalProperties,
|
|
@@ -282,7 +259,6 @@ model IsModelAdditionalProperties is Record<ModelForRecord> {
|
|
|
282
259
|
}
|
|
283
260
|
|
|
284
261
|
@route("/isRecordModel")
|
|
285
|
-
@operationGroup
|
|
286
262
|
interface IsModel
|
|
287
263
|
extends ModelOperations<
|
|
288
264
|
IsModelAdditionalProperties,
|
|
@@ -296,7 +272,6 @@ model SpreadModelRecord {
|
|
|
296
272
|
}
|
|
297
273
|
|
|
298
274
|
@route("/spreadRecordModel")
|
|
299
|
-
@operationGroup
|
|
300
275
|
interface SpreadModel
|
|
301
276
|
extends ModelOperations<
|
|
302
277
|
SpreadModelRecord,
|
|
@@ -311,7 +286,6 @@ model ExtendsModelArrayAdditionalProperties extends Record<ModelForRecord[]> {
|
|
|
311
286
|
}
|
|
312
287
|
|
|
313
288
|
@route("/extendsRecordModelArray")
|
|
314
|
-
@operationGroup
|
|
315
289
|
interface ExtendsModelArray
|
|
316
290
|
extends ModelOperations<
|
|
317
291
|
ExtendsModelArrayAdditionalProperties,
|
|
@@ -325,7 +299,6 @@ model IsModelArrayAdditionalProperties is Record<ModelForRecord[]> {
|
|
|
325
299
|
}
|
|
326
300
|
|
|
327
301
|
@route("/isRecordModelArray")
|
|
328
|
-
@operationGroup
|
|
329
302
|
interface IsModelArray
|
|
330
303
|
extends ModelOperations<
|
|
331
304
|
IsModelArrayAdditionalProperties,
|
|
@@ -338,7 +311,6 @@ model SpreadModelArrayRecord {
|
|
|
338
311
|
}
|
|
339
312
|
|
|
340
313
|
@route("/spreadRecordModelArray")
|
|
341
|
-
@operationGroup
|
|
342
314
|
interface SpreadModelArray
|
|
343
315
|
extends ModelOperations<
|
|
344
316
|
SpreadModelArrayRecord,
|
|
@@ -356,7 +328,6 @@ model DifferentSpreadStringRecord {
|
|
|
356
328
|
}
|
|
357
329
|
|
|
358
330
|
@route("/spreadDifferentRecordString")
|
|
359
|
-
@operationGroup
|
|
360
331
|
interface SpreadDifferentString
|
|
361
332
|
extends ModelOperations<DifferentSpreadStringRecord, "{'id': 43.125, 'prop': 'abc'}"> {}
|
|
362
333
|
|
|
@@ -370,7 +341,6 @@ model DifferentSpreadFloatRecord {
|
|
|
370
341
|
}
|
|
371
342
|
|
|
372
343
|
@route("/spreadDifferentRecordFloat")
|
|
373
|
-
@operationGroup
|
|
374
344
|
interface SpreadDifferentFloat
|
|
375
345
|
extends ModelOperations<DifferentSpreadFloatRecord, "{'name': 'abc', 'prop': 43.125}"> {}
|
|
376
346
|
|
|
@@ -382,7 +352,6 @@ model DifferentSpreadModelRecord {
|
|
|
382
352
|
}
|
|
383
353
|
|
|
384
354
|
@route("/spreadDifferentRecordModel")
|
|
385
|
-
@operationGroup
|
|
386
355
|
interface SpreadDifferentModel
|
|
387
356
|
extends ModelOperations<
|
|
388
357
|
DifferentSpreadModelRecord,
|
|
@@ -397,7 +366,6 @@ model DifferentSpreadModelArrayRecord {
|
|
|
397
366
|
}
|
|
398
367
|
|
|
399
368
|
@route("/spreadDifferentRecordModelArray")
|
|
400
|
-
@operationGroup
|
|
401
369
|
interface SpreadDifferentModelArray
|
|
402
370
|
extends ModelOperations<
|
|
403
371
|
DifferentSpreadModelArrayRecord,
|
|
@@ -412,7 +380,6 @@ model DifferentSpreadStringDerived extends DifferentSpreadStringRecord {
|
|
|
412
380
|
}
|
|
413
381
|
|
|
414
382
|
@route("/extendsDifferentSpreadString")
|
|
415
|
-
@operationGroup
|
|
416
383
|
interface ExtendsDifferentSpreadString
|
|
417
384
|
extends ModelOperations<
|
|
418
385
|
DifferentSpreadStringDerived,
|
|
@@ -427,7 +394,6 @@ model DifferentSpreadFloatDerived extends DifferentSpreadFloatRecord {
|
|
|
427
394
|
}
|
|
428
395
|
|
|
429
396
|
@route("/extendsDifferentSpreadFloat")
|
|
430
|
-
@operationGroup
|
|
431
397
|
interface ExtendsDifferentSpreadFloat
|
|
432
398
|
extends ModelOperations<
|
|
433
399
|
DifferentSpreadFloatDerived,
|
|
@@ -443,7 +409,6 @@ model DifferentSpreadModelDerived extends DifferentSpreadModelRecord {
|
|
|
443
409
|
}
|
|
444
410
|
|
|
445
411
|
@route("/extendsDifferentSpreadModel")
|
|
446
|
-
@operationGroup
|
|
447
412
|
interface ExtendsDifferentSpreadModel
|
|
448
413
|
extends ModelOperations<
|
|
449
414
|
DifferentSpreadModelDerived,
|
|
@@ -458,7 +423,6 @@ model DifferentSpreadModelArrayDerived extends DifferentSpreadModelArrayRecord {
|
|
|
458
423
|
}
|
|
459
424
|
|
|
460
425
|
@route("/extendsDifferentSpreadModelArray")
|
|
461
|
-
@operationGroup
|
|
462
426
|
interface ExtendsDifferentSpreadModelArray
|
|
463
427
|
extends ModelOperations<
|
|
464
428
|
DifferentSpreadModelArrayDerived,
|
|
@@ -476,7 +440,6 @@ model MultipleSpreadRecord {
|
|
|
476
440
|
}
|
|
477
441
|
|
|
478
442
|
@route("/multipleSpreadRecord")
|
|
479
|
-
@operationGroup
|
|
480
443
|
interface MultipleSpread
|
|
481
444
|
extends ModelOperations<
|
|
482
445
|
MultipleSpreadRecord,
|
|
@@ -493,7 +456,6 @@ model SpreadRecordForUnion {
|
|
|
493
456
|
}
|
|
494
457
|
|
|
495
458
|
@route("/spreadRecordUnion")
|
|
496
|
-
@operationGroup
|
|
497
459
|
interface SpreadRecordUnion
|
|
498
460
|
extends ModelOperations<
|
|
499
461
|
SpreadRecordForUnion,
|
|
@@ -532,7 +494,6 @@ model SpreadRecordForDiscriminatedUnion {
|
|
|
532
494
|
}
|
|
533
495
|
|
|
534
496
|
@route("/spreadRecordDiscriminatedUnion")
|
|
535
|
-
@operationGroup
|
|
536
497
|
interface SpreadRecordDiscriminatedUnion
|
|
537
498
|
extends ModelOperations<
|
|
538
499
|
SpreadRecordForDiscriminatedUnion,
|
|
@@ -549,7 +510,6 @@ model SpreadRecordForNonDiscriminatedUnion {
|
|
|
549
510
|
}
|
|
550
511
|
|
|
551
512
|
@route("/spreadRecordNonDiscriminatedUnion")
|
|
552
|
-
@operationGroup
|
|
553
513
|
interface SpreadRecordNonDiscriminatedUnion
|
|
554
514
|
extends ModelOperations<
|
|
555
515
|
SpreadRecordForNonDiscriminatedUnion,
|
|
@@ -566,7 +526,6 @@ model SpreadRecordForNonDiscriminatedUnion2 {
|
|
|
566
526
|
}
|
|
567
527
|
|
|
568
528
|
@route("/spreadRecordNonDiscriminatedUnion2")
|
|
569
|
-
@operationGroup
|
|
570
529
|
interface SpreadRecordNonDiscriminatedUnion2
|
|
571
530
|
extends ModelOperations<
|
|
572
531
|
SpreadRecordForNonDiscriminatedUnion2,
|
|
@@ -583,7 +542,6 @@ model SpreadRecordForNonDiscriminatedUnion3 {
|
|
|
583
542
|
}
|
|
584
543
|
|
|
585
544
|
@route("/spreadRecordNonDiscriminatedUnion3")
|
|
586
|
-
@operationGroup
|
|
587
545
|
interface SpreadRecordNonDiscriminatedUnion3
|
|
588
546
|
extends ModelOperations<
|
|
589
547
|
SpreadRecordForNonDiscriminatedUnion3,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
5
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
6
|
|
|
7
7
|
@doc("Illustrates models with nullable properties.")
|
|
8
8
|
@scenarioService("/type/property/nullable")
|
|
@@ -18,54 +18,43 @@ model ModelTemplate<TProperty> {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@doc("Operations associated with getting and putting models with nullable properties.")
|
|
21
|
-
interface OperationsTemplate<
|
|
21
|
+
interface OperationsTemplate<
|
|
22
|
+
TModel,
|
|
23
|
+
TDoc extends valueof string,
|
|
24
|
+
TDefaultDoc extends valueof string = "null"
|
|
25
|
+
> {
|
|
22
26
|
@doc("Get models that will return all properties in the model")
|
|
23
27
|
@scenario
|
|
24
|
-
@scenarioDoc(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
""",
|
|
31
|
-
{
|
|
32
|
-
allDoc: TDoc,
|
|
33
|
-
}
|
|
34
|
-
)
|
|
28
|
+
@scenarioDoc("""
|
|
29
|
+
Expected response body:
|
|
30
|
+
```json
|
|
31
|
+
{ "requiredProperty": "foo", "nullableProperty": ${TDoc}}
|
|
32
|
+
```
|
|
33
|
+
""")
|
|
35
34
|
@route("/non-null")
|
|
36
35
|
@get
|
|
37
36
|
getNonNull(): TModel;
|
|
38
37
|
|
|
39
38
|
@doc("Get models that will return the default object")
|
|
40
39
|
@scenario
|
|
41
|
-
@scenarioDoc(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
""",
|
|
48
|
-
{
|
|
49
|
-
defaultDoc: TDefaultDoc,
|
|
50
|
-
}
|
|
51
|
-
)
|
|
40
|
+
@scenarioDoc("""
|
|
41
|
+
Expected response body:
|
|
42
|
+
```json
|
|
43
|
+
{ "requiredProperty": "foo", "nullableProperty": ${TDefaultDoc}}
|
|
44
|
+
```
|
|
45
|
+
""")
|
|
52
46
|
@route("/null")
|
|
53
47
|
@get
|
|
54
48
|
getNull(): TModel;
|
|
55
49
|
|
|
56
50
|
@doc("Put a body with all properties present.")
|
|
57
51
|
@scenario
|
|
58
|
-
@scenarioDoc(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
""",
|
|
65
|
-
{
|
|
66
|
-
allDoc: TDoc,
|
|
67
|
-
}
|
|
68
|
-
)
|
|
52
|
+
@scenarioDoc("""
|
|
53
|
+
Expected request body:
|
|
54
|
+
```json
|
|
55
|
+
{ "requiredProperty": "foo", "nullableProperty": ${TDoc}}
|
|
56
|
+
```
|
|
57
|
+
""")
|
|
69
58
|
@route("/non-null")
|
|
70
59
|
@patch
|
|
71
60
|
patchNonNull(
|
|
@@ -78,17 +67,12 @@ interface OperationsTemplate<TModel, TDoc extends string, TDefaultDoc extends st
|
|
|
78
67
|
|
|
79
68
|
@doc("Put a body with default properties.")
|
|
80
69
|
@scenario
|
|
81
|
-
@scenarioDoc(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
""",
|
|
88
|
-
{
|
|
89
|
-
defaultDoc: TDefaultDoc,
|
|
90
|
-
}
|
|
91
|
-
)
|
|
70
|
+
@scenarioDoc("""
|
|
71
|
+
Expected request body:
|
|
72
|
+
```json
|
|
73
|
+
{ "requiredProperty": "foo", "nullableProperty": ${TDefaultDoc}}
|
|
74
|
+
```
|
|
75
|
+
""")
|
|
92
76
|
@route("/null")
|
|
93
77
|
@patch
|
|
94
78
|
patchNull(
|
|
@@ -103,34 +87,29 @@ interface OperationsTemplate<TModel, TDoc extends string, TDefaultDoc extends st
|
|
|
103
87
|
// Model with nullable string property
|
|
104
88
|
model StringProperty is ModelTemplate<string>;
|
|
105
89
|
@route("/string")
|
|
106
|
-
@operationGroup
|
|
107
90
|
interface String extends OperationsTemplate<StringProperty, "hello"> {}
|
|
108
91
|
|
|
109
92
|
// Model with nullable bytes property
|
|
110
93
|
model BytesProperty is ModelTemplate<bytes>;
|
|
111
94
|
@route("/bytes")
|
|
112
|
-
@operationGroup
|
|
113
95
|
interface Bytes extends OperationsTemplate<BytesProperty, "aGVsbG8sIHdvcmxkIQ=="> {}
|
|
114
96
|
|
|
115
97
|
// Model with nullable datetime property
|
|
116
98
|
@doc("Model with a datetime property")
|
|
117
99
|
model DatetimeProperty is ModelTemplate<utcDateTime>;
|
|
118
100
|
@route("/datetime")
|
|
119
|
-
@operationGroup
|
|
120
101
|
interface Datetime extends OperationsTemplate<DatetimeProperty, "2022-08-26T18:38:00Z"> {}
|
|
121
102
|
|
|
122
103
|
// Model with nullable duration property
|
|
123
104
|
@doc("Model with a duration property")
|
|
124
105
|
model DurationProperty is ModelTemplate<duration>;
|
|
125
106
|
@route("/duration")
|
|
126
|
-
@operationGroup
|
|
127
107
|
interface Duration extends OperationsTemplate<DurationProperty, "P123DT22H14M12.011S"> {}
|
|
128
108
|
|
|
129
109
|
// Model with nullable collection bytes property
|
|
130
110
|
@doc("Model with collection bytes properties")
|
|
131
111
|
model CollectionsByteProperty is ModelTemplate<bytes[]>;
|
|
132
112
|
@route("/collections/bytes")
|
|
133
|
-
@operationGroup
|
|
134
113
|
interface CollectionsByte
|
|
135
114
|
extends OperationsTemplate<
|
|
136
115
|
CollectionsByteProperty,
|
|
@@ -146,7 +125,6 @@ model InnerModel {
|
|
|
146
125
|
@doc("Model with collection models properties")
|
|
147
126
|
model CollectionsModelProperty is ModelTemplate<InnerModel[]>;
|
|
148
127
|
@route("/collections/model")
|
|
149
|
-
@operationGroup
|
|
150
128
|
interface CollectionsModel
|
|
151
129
|
extends OperationsTemplate<
|
|
152
130
|
CollectionsModelProperty,
|
|
@@ -157,6 +135,5 @@ interface CollectionsModel
|
|
|
157
135
|
@doc("Model with collection string properties")
|
|
158
136
|
model CollectionsStringProperty is ModelTemplate<string[]>;
|
|
159
137
|
@route("/collections/string")
|
|
160
|
-
@operationGroup
|
|
161
138
|
interface CollectionsString
|
|
162
139
|
extends OperationsTemplate<CollectionsStringProperty, "['hello', 'world']"> {}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@typespec/http";
|
|
2
2
|
import "@typespec/spec-lib";
|
|
3
3
|
|
|
4
|
-
using
|
|
5
|
-
using
|
|
4
|
+
using Http;
|
|
5
|
+
using SpecLib;
|
|
6
6
|
|
|
7
7
|
@doc("Illustrates models with optional properties.")
|
|
8
8
|
@scenarioService("/type/property/optional")
|
|
@@ -15,71 +15,55 @@ model ModelTemplate<TProperty> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@doc("Operations associated with getting and putting models with optional properties.")
|
|
18
|
-
interface OperationsTemplate<
|
|
18
|
+
interface OperationsTemplate<
|
|
19
|
+
TModel,
|
|
20
|
+
TDoc extends valueof string,
|
|
21
|
+
TDefaultDoc extends valueof string = "{}"
|
|
22
|
+
> {
|
|
19
23
|
@doc("Get models that will return all properties in the model")
|
|
20
24
|
@scenario
|
|
21
|
-
@scenarioDoc(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
""",
|
|
28
|
-
{
|
|
29
|
-
allDoc: TDoc,
|
|
30
|
-
}
|
|
31
|
-
)
|
|
25
|
+
@scenarioDoc("""
|
|
26
|
+
Expected response body:
|
|
27
|
+
```json
|
|
28
|
+
{"property": ${TDoc}}
|
|
29
|
+
```
|
|
30
|
+
""")
|
|
32
31
|
@route("/all")
|
|
33
32
|
@get
|
|
34
33
|
getAll(): TModel;
|
|
35
34
|
|
|
36
35
|
@doc("Get models that will return the default object")
|
|
37
36
|
@scenario
|
|
38
|
-
@scenarioDoc(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
""",
|
|
45
|
-
{
|
|
46
|
-
defaultDoc: TDefaultDoc,
|
|
47
|
-
}
|
|
48
|
-
)
|
|
37
|
+
@scenarioDoc("""
|
|
38
|
+
Expected response body:
|
|
39
|
+
```json
|
|
40
|
+
${TDefaultDoc}
|
|
41
|
+
```
|
|
42
|
+
""")
|
|
49
43
|
@route("/default")
|
|
50
44
|
@get
|
|
51
45
|
getDefault(): TModel;
|
|
52
46
|
|
|
53
47
|
@doc("Put a body with all properties present.")
|
|
54
48
|
@scenario
|
|
55
|
-
@scenarioDoc(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
""",
|
|
62
|
-
{
|
|
63
|
-
allDoc: TDoc,
|
|
64
|
-
}
|
|
65
|
-
)
|
|
49
|
+
@scenarioDoc("""
|
|
50
|
+
Expected request body:
|
|
51
|
+
```json
|
|
52
|
+
{"property": ${TDoc}}
|
|
53
|
+
```
|
|
54
|
+
""")
|
|
66
55
|
@route("/all")
|
|
67
56
|
@put
|
|
68
57
|
putAll(@body body: TModel): void;
|
|
69
58
|
|
|
70
59
|
@doc("Put a body with default properties.")
|
|
71
60
|
@scenario
|
|
72
|
-
@scenarioDoc(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
""",
|
|
79
|
-
{
|
|
80
|
-
defaultDoc: TDefaultDoc,
|
|
81
|
-
}
|
|
82
|
-
)
|
|
61
|
+
@scenarioDoc("""
|
|
62
|
+
Expected request body:
|
|
63
|
+
```json
|
|
64
|
+
${TDefaultDoc}
|
|
65
|
+
```
|
|
66
|
+
""")
|
|
83
67
|
@route("/default")
|
|
84
68
|
@put
|
|
85
69
|
putDefault(@body body: TModel): void;
|
|
@@ -88,48 +72,41 @@ interface OperationsTemplate<TModel, TDoc extends string, TDefaultDoc extends st
|
|
|
88
72
|
// Model with optional string property
|
|
89
73
|
model StringProperty is ModelTemplate<string>;
|
|
90
74
|
@route("/string")
|
|
91
|
-
@operationGroup
|
|
92
75
|
interface String extends OperationsTemplate<StringProperty, "\"hello\""> {}
|
|
93
76
|
|
|
94
77
|
// Model with optional bytes property
|
|
95
78
|
model BytesProperty is ModelTemplate<bytes>;
|
|
96
79
|
@route("/bytes")
|
|
97
|
-
@operationGroup
|
|
98
80
|
interface Bytes extends OperationsTemplate<BytesProperty, "\"aGVsbG8sIHdvcmxkIQ==\""> {}
|
|
99
81
|
|
|
100
82
|
// Model with optional datetime property
|
|
101
83
|
@doc("Model with a datetime property")
|
|
102
84
|
model DatetimeProperty is ModelTemplate<utcDateTime>;
|
|
103
85
|
@route("/datetime")
|
|
104
|
-
@operationGroup
|
|
105
86
|
interface Datetime extends OperationsTemplate<DatetimeProperty, "\"2022-08-26T18:38:00Z\""> {}
|
|
106
87
|
|
|
107
88
|
// Model with optional duration property
|
|
108
89
|
@doc("Model with a duration property")
|
|
109
90
|
model DurationProperty is ModelTemplate<duration>;
|
|
110
91
|
@route("/duration")
|
|
111
|
-
@operationGroup
|
|
112
92
|
interface Duration extends OperationsTemplate<DurationProperty, "\"P123DT22H14M12.011S\""> {}
|
|
113
93
|
|
|
114
94
|
// Model with optional plainDate property
|
|
115
95
|
@doc("Model with a plainDate property")
|
|
116
96
|
model PlainDateProperty is ModelTemplate<plainDate>;
|
|
117
97
|
@route("/plainDate")
|
|
118
|
-
@operationGroup
|
|
119
98
|
interface PlainDate extends OperationsTemplate<PlainDateProperty, "\"2022-12-12\""> {}
|
|
120
99
|
|
|
121
100
|
// Model with optional property
|
|
122
101
|
@doc("Model with a plainTime property")
|
|
123
102
|
model PlainTimeProperty is ModelTemplate<plainTime>;
|
|
124
103
|
@route("/plainTime")
|
|
125
|
-
@operationGroup
|
|
126
104
|
interface PlainTime extends OperationsTemplate<PlainTimeProperty, "\"13:06:12\""> {}
|
|
127
105
|
|
|
128
106
|
// Model with optional collection bytes property
|
|
129
107
|
@doc("Model with collection bytes properties")
|
|
130
108
|
model CollectionsByteProperty is ModelTemplate<bytes[]>;
|
|
131
109
|
@route("/collections/bytes")
|
|
132
|
-
@operationGroup
|
|
133
110
|
interface CollectionsByte
|
|
134
111
|
extends OperationsTemplate<
|
|
135
112
|
CollectionsByteProperty,
|
|
@@ -140,7 +117,6 @@ interface CollectionsByte
|
|
|
140
117
|
@doc("Model with collection models properties")
|
|
141
118
|
model CollectionsModelProperty is ModelTemplate<StringProperty[]>;
|
|
142
119
|
@route("/collections/model")
|
|
143
|
-
@operationGroup
|
|
144
120
|
interface CollectionsModel
|
|
145
121
|
extends OperationsTemplate<
|
|
146
122
|
CollectionsModelProperty,
|
|
@@ -151,49 +127,42 @@ interface CollectionsModel
|
|
|
151
127
|
@doc("Model with string literal property")
|
|
152
128
|
model StringLiteralProperty is ModelTemplate<"hello">;
|
|
153
129
|
@route("/string/literal")
|
|
154
|
-
@operationGroup
|
|
155
130
|
interface StringLiteral extends OperationsTemplate<StringLiteralProperty, "\"hello\""> {}
|
|
156
131
|
|
|
157
132
|
// Model with optional int literal property
|
|
158
133
|
@doc("Model with int literal property")
|
|
159
134
|
model IntLiteralProperty is ModelTemplate<1>;
|
|
160
135
|
@route("/int/literal")
|
|
161
|
-
@operationGroup
|
|
162
136
|
interface IntLiteral extends OperationsTemplate<IntLiteralProperty, "1"> {}
|
|
163
137
|
|
|
164
138
|
// Model with optional float literal property
|
|
165
139
|
@doc("Model with float literal property")
|
|
166
140
|
model FloatLiteralProperty is ModelTemplate<1.25>;
|
|
167
141
|
@route("/float/literal")
|
|
168
|
-
@operationGroup
|
|
169
142
|
interface FloatLiteral extends OperationsTemplate<FloatLiteralProperty, "1.25"> {}
|
|
170
143
|
|
|
171
144
|
// Model with optional boolean literal property
|
|
172
145
|
@doc("Model with boolean literal property")
|
|
173
146
|
model BooleanLiteralProperty is ModelTemplate<true>;
|
|
174
147
|
@route("/boolean/literal")
|
|
175
|
-
@operationGroup
|
|
176
148
|
interface BooleanLiteral extends OperationsTemplate<BooleanLiteralProperty, "true"> {}
|
|
177
149
|
|
|
178
150
|
// Model with union of string literal property
|
|
179
151
|
@doc("Model with union of string literal property")
|
|
180
152
|
model UnionStringLiteralProperty is ModelTemplate<"hello" | "world">;
|
|
181
153
|
@route("/union/string/literal")
|
|
182
|
-
@operationGroup
|
|
183
154
|
interface UnionStringLiteral extends OperationsTemplate<UnionStringLiteralProperty, "\"world\""> {}
|
|
184
155
|
|
|
185
156
|
// Model with union of int literal property
|
|
186
157
|
@doc("Model with union of int literal property")
|
|
187
158
|
model UnionIntLiteralProperty is ModelTemplate<1 | 2>;
|
|
188
159
|
@route("/union/int/literal")
|
|
189
|
-
@operationGroup
|
|
190
160
|
interface UnionIntLiteral extends OperationsTemplate<UnionIntLiteralProperty, "2"> {}
|
|
191
161
|
|
|
192
162
|
// Model with union of float literal property
|
|
193
163
|
@doc("Model with union of float literal property")
|
|
194
164
|
model UnionFloatLiteralProperty is ModelTemplate<1.25 | 2.375>;
|
|
195
165
|
@route("/union/float/literal")
|
|
196
|
-
@operationGroup
|
|
197
166
|
interface UnionFloatLiteral extends OperationsTemplate<UnionFloatLiteralProperty, "2.375"> {}
|
|
198
167
|
|
|
199
168
|
@doc("Model with required and optional properties")
|
|
@@ -206,7 +175,6 @@ model RequiredAndOptionalProperty {
|
|
|
206
175
|
}
|
|
207
176
|
@doc("Test optional and required properties")
|
|
208
177
|
@route("/requiredAndOptional")
|
|
209
|
-
@operationGroup
|
|
210
178
|
interface RequiredAndOptional {
|
|
211
179
|
@doc("Get models that will return all properties in the model")
|
|
212
180
|
@scenario
|