@typespec/http-specs 0.38.0-dev.3 → 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 +8 -7
- 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,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 various property types for models")
|
|
8
8
|
@scenarioService("/type/property/value-types")
|
|
@@ -16,37 +16,27 @@ model ModelTemplate<TProperty> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
@doc("Template to have models operations")
|
|
19
|
-
interface ModelOperations<TModel, TDoc extends string> {
|
|
19
|
+
interface ModelOperations<TModel, TDoc extends valueof string> {
|
|
20
20
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
21
21
|
@scenario
|
|
22
|
-
@scenarioDoc(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
""",
|
|
29
|
-
{
|
|
30
|
-
doc: TDoc,
|
|
31
|
-
}
|
|
32
|
-
)
|
|
22
|
+
@scenarioDoc("""
|
|
23
|
+
Expected response body:
|
|
24
|
+
```json
|
|
25
|
+
{"property": ${TDoc}}
|
|
26
|
+
```
|
|
27
|
+
""")
|
|
33
28
|
@get
|
|
34
29
|
@doc("Get call")
|
|
35
30
|
get(): TModel;
|
|
36
31
|
|
|
37
32
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
38
33
|
@scenario
|
|
39
|
-
@scenarioDoc(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
""",
|
|
46
|
-
{
|
|
47
|
-
doc: TDoc,
|
|
48
|
-
}
|
|
49
|
-
)
|
|
34
|
+
@scenarioDoc("""
|
|
35
|
+
Expected input body:
|
|
36
|
+
```json
|
|
37
|
+
{"property": ${TDoc}}
|
|
38
|
+
```
|
|
39
|
+
""")
|
|
50
40
|
@put
|
|
51
41
|
@doc("Put operation")
|
|
52
42
|
put(@body @doc("body") body: TModel): void;
|
|
@@ -56,63 +46,54 @@ interface ModelOperations<TModel, TDoc extends string> {
|
|
|
56
46
|
@doc("Model with a boolean property")
|
|
57
47
|
model BooleanProperty is ModelTemplate<boolean>;
|
|
58
48
|
@route("/boolean")
|
|
59
|
-
@operationGroup
|
|
60
49
|
interface Boolean extends ModelOperations<BooleanProperty, "true"> {}
|
|
61
50
|
|
|
62
51
|
// Test a model with a string property
|
|
63
52
|
@doc("Model with a string property")
|
|
64
53
|
model StringProperty is ModelTemplate<string>;
|
|
65
54
|
@route("/string")
|
|
66
|
-
@operationGroup
|
|
67
55
|
interface String extends ModelOperations<StringProperty, "\"hello\""> {}
|
|
68
56
|
|
|
69
57
|
// Test a model with a bytes property
|
|
70
58
|
@doc("Model with a bytes property")
|
|
71
59
|
model BytesProperty is ModelTemplate<bytes>;
|
|
72
60
|
@route("/bytes")
|
|
73
|
-
@operationGroup
|
|
74
61
|
interface Bytes extends ModelOperations<BytesProperty, "aGVsbG8sIHdvcmxkIQ=="> {}
|
|
75
62
|
|
|
76
63
|
// Test a model with an int property
|
|
77
64
|
@doc("Model with a int property")
|
|
78
65
|
model IntProperty is ModelTemplate<int32>;
|
|
79
66
|
@route("/int")
|
|
80
|
-
@operationGroup
|
|
81
67
|
interface Int extends ModelOperations<IntProperty, "42"> {}
|
|
82
68
|
|
|
83
69
|
// Test a model with a float property
|
|
84
70
|
@doc("Model with a float property")
|
|
85
71
|
model FloatProperty is ModelTemplate<float32>;
|
|
86
72
|
@route("/float")
|
|
87
|
-
@operationGroup
|
|
88
73
|
interface Float extends ModelOperations<FloatProperty, "43.125"> {}
|
|
89
74
|
|
|
90
75
|
// Test a model with a decimal property
|
|
91
76
|
@doc("Model with a decimal property")
|
|
92
77
|
model DecimalProperty is ModelTemplate<decimal>;
|
|
93
78
|
@route("/decimal")
|
|
94
|
-
@operationGroup
|
|
95
79
|
interface Decimal extends ModelOperations<DecimalProperty, "0.33333"> {}
|
|
96
80
|
|
|
97
81
|
// Test a model with a decimal128 property
|
|
98
82
|
@doc("Model with a decimal128 property")
|
|
99
83
|
model Decimal128Property is ModelTemplate<decimal128>;
|
|
100
84
|
@route("/decimal128")
|
|
101
|
-
@operationGroup
|
|
102
85
|
interface Decimal128 extends ModelOperations<Decimal128Property, "0.33333"> {}
|
|
103
86
|
|
|
104
87
|
// Test a model with a datetime property
|
|
105
88
|
@doc("Model with a datetime property")
|
|
106
89
|
model DatetimeProperty is ModelTemplate<utcDateTime>;
|
|
107
90
|
@route("/datetime")
|
|
108
|
-
@operationGroup
|
|
109
91
|
interface Datetime extends ModelOperations<DatetimeProperty, "2022-08-26T18:38:00Z"> {}
|
|
110
92
|
|
|
111
93
|
// Test a model with a duration property
|
|
112
94
|
@doc("Model with a duration property")
|
|
113
95
|
model DurationProperty is ModelTemplate<duration>;
|
|
114
96
|
@route("/duration")
|
|
115
|
-
@operationGroup
|
|
116
97
|
interface Duration extends ModelOperations<DurationProperty, "P123DT22H14M12.011S"> {}
|
|
117
98
|
|
|
118
99
|
// Test a model with an enum property
|
|
@@ -127,9 +108,7 @@ union InnerEnum {
|
|
|
127
108
|
ValueTwo: "ValueTwo",
|
|
128
109
|
}
|
|
129
110
|
|
|
130
|
-
#suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "For testing"
|
|
131
111
|
@doc("Enum that will be used as a property for model EnumProperty. Non-extensible.")
|
|
132
|
-
@Azure.Core.fixed
|
|
133
112
|
enum FixedInnerEnum {
|
|
134
113
|
@doc("First value.")
|
|
135
114
|
ValueOne,
|
|
@@ -141,13 +120,11 @@ enum FixedInnerEnum {
|
|
|
141
120
|
@doc("Model with enum properties")
|
|
142
121
|
model EnumProperty is ModelTemplate<FixedInnerEnum>;
|
|
143
122
|
@route("/enum")
|
|
144
|
-
@operationGroup
|
|
145
123
|
interface Enum extends ModelOperations<EnumProperty, "\"ValueOne\""> {}
|
|
146
124
|
|
|
147
125
|
@doc("Model with extensible enum properties")
|
|
148
126
|
model ExtensibleEnumProperty is ModelTemplate<InnerEnum>;
|
|
149
127
|
@route("/extensible-enum")
|
|
150
|
-
@operationGroup
|
|
151
128
|
interface ExtensibleEnum extends ModelOperations<ExtensibleEnumProperty, "\"UnknownValue\""> {}
|
|
152
129
|
|
|
153
130
|
// Test a model with a model property
|
|
@@ -159,14 +136,12 @@ model InnerModel {
|
|
|
159
136
|
@doc("Model with model properties")
|
|
160
137
|
model ModelProperty is ModelTemplate<InnerModel>;
|
|
161
138
|
@route("/model")
|
|
162
|
-
@operationGroup
|
|
163
139
|
interface Model extends ModelOperations<ModelProperty, "{'property': 'hello'}"> {}
|
|
164
140
|
|
|
165
141
|
// Test a model with a string collection property
|
|
166
142
|
@doc("Model with collection string properties")
|
|
167
143
|
model CollectionsStringProperty is ModelTemplate<string[]>;
|
|
168
144
|
@route("/collections/string")
|
|
169
|
-
@operationGroup
|
|
170
145
|
interface CollectionsString
|
|
171
146
|
extends ModelOperations<CollectionsStringProperty, "['hello', 'world']"> {}
|
|
172
147
|
|
|
@@ -174,14 +149,12 @@ interface CollectionsString
|
|
|
174
149
|
@doc("Model with collection int properties")
|
|
175
150
|
model CollectionsIntProperty is ModelTemplate<int32[]>;
|
|
176
151
|
@route("/collections/int")
|
|
177
|
-
@operationGroup
|
|
178
152
|
interface CollectionsInt extends ModelOperations<CollectionsIntProperty, "[1, 2]"> {}
|
|
179
153
|
|
|
180
154
|
// Test a model with a model collection property
|
|
181
155
|
@doc("Model with collection model properties")
|
|
182
156
|
model CollectionsModelProperty is ModelTemplate<InnerModel[]>;
|
|
183
157
|
@route("/collections/model")
|
|
184
|
-
@operationGroup
|
|
185
158
|
interface CollectionsModel
|
|
186
159
|
extends ModelOperations<
|
|
187
160
|
CollectionsModelProperty,
|
|
@@ -192,7 +165,6 @@ interface CollectionsModel
|
|
|
192
165
|
@doc("Model with dictionary string properties")
|
|
193
166
|
model DictionaryStringProperty is ModelTemplate<Record<string>>;
|
|
194
167
|
@route("/dictionary/string")
|
|
195
|
-
@operationGroup
|
|
196
168
|
interface DictionaryString
|
|
197
169
|
extends ModelOperations<DictionaryStringProperty, "{'k1': 'hello', 'k2': 'world'}"> {}
|
|
198
170
|
|
|
@@ -200,77 +172,65 @@ interface DictionaryString
|
|
|
200
172
|
@doc("Model with a property never. (This property should not be included).")
|
|
201
173
|
model NeverProperty is ModelTemplate<never>;
|
|
202
174
|
@route("/never")
|
|
203
|
-
@operationGroup
|
|
204
175
|
interface Never extends ModelOperations<NeverProperty, "<don't include this property>"> {}
|
|
205
176
|
|
|
206
177
|
// Test a model with unknown and string
|
|
207
178
|
@doc("Model with a property unknown, and the data is a string.")
|
|
208
179
|
model UnknownStringProperty is ModelTemplate<unknown>;
|
|
209
180
|
@route("/unknown/string")
|
|
210
|
-
@operationGroup
|
|
211
181
|
interface UnknownString extends ModelOperations<UnknownStringProperty, "\"hello\""> {}
|
|
212
182
|
|
|
213
183
|
// Test a model with unknown and int
|
|
214
184
|
@doc("Model with a property unknown, and the data is a int32.")
|
|
215
185
|
model UnknownIntProperty is ModelTemplate<unknown>;
|
|
216
186
|
@route("/unknown/int")
|
|
217
|
-
@operationGroup
|
|
218
187
|
interface UnknownInt extends ModelOperations<UnknownIntProperty, "42"> {}
|
|
219
188
|
|
|
220
189
|
// Test a model with unknown and a dictionnary
|
|
221
190
|
@doc("Model with a property unknown, and the data is a dictionnary.")
|
|
222
191
|
model UnknownDictProperty is ModelTemplate<unknown>;
|
|
223
192
|
@route("/unknown/dict")
|
|
224
|
-
@operationGroup
|
|
225
193
|
interface UnknownDict extends ModelOperations<UnknownDictProperty, "{'k1': 'hello', 'k2': 42}"> {}
|
|
226
194
|
|
|
227
195
|
// Test a model with unknown and an array
|
|
228
196
|
@doc("Model with a property unknown, and the data is an array.")
|
|
229
197
|
model UnknownArrayProperty is ModelTemplate<unknown>;
|
|
230
198
|
@route("/unknown/array")
|
|
231
|
-
@operationGroup
|
|
232
199
|
interface UnknownArray extends ModelOperations<UnknownArrayProperty, "['hello', 'world']"> {}
|
|
233
200
|
|
|
234
201
|
@doc("Model with a string literal property.")
|
|
235
202
|
model StringLiteralProperty is ModelTemplate<"hello">;
|
|
236
203
|
@route("/string/literal")
|
|
237
|
-
@operationGroup
|
|
238
204
|
interface StringLiteral extends ModelOperations<StringLiteralProperty, "\"hello\""> {}
|
|
239
205
|
|
|
240
206
|
@doc("Model with a int literal property.")
|
|
241
207
|
model IntLiteralProperty is ModelTemplate<42>;
|
|
242
208
|
@route("/int/literal")
|
|
243
|
-
@operationGroup
|
|
244
209
|
interface IntLiteral extends ModelOperations<IntLiteralProperty, "42"> {}
|
|
245
210
|
|
|
246
211
|
@doc("Model with a float literal property.")
|
|
247
212
|
model FloatLiteralProperty is ModelTemplate<43.125>;
|
|
248
213
|
@route("/float/literal")
|
|
249
|
-
@operationGroup
|
|
250
214
|
interface FloatLiteral extends ModelOperations<FloatLiteralProperty, "43.125"> {}
|
|
251
215
|
|
|
252
216
|
@doc("Model with a boolean literal property.")
|
|
253
217
|
model BooleanLiteralProperty is ModelTemplate<true>;
|
|
254
218
|
@route("/boolean/literal")
|
|
255
|
-
@operationGroup
|
|
256
219
|
interface BooleanLiteral extends ModelOperations<BooleanLiteralProperty, "true"> {}
|
|
257
220
|
|
|
258
221
|
@doc("Model with a union of string literal as property.")
|
|
259
222
|
model UnionStringLiteralProperty is ModelTemplate<"hello" | "world">;
|
|
260
223
|
@route("/union/string/literal")
|
|
261
|
-
@operationGroup
|
|
262
224
|
interface UnionStringLiteral extends ModelOperations<UnionStringLiteralProperty, "\"world\""> {}
|
|
263
225
|
|
|
264
226
|
@doc("Model with a union of int literal as property.")
|
|
265
227
|
model UnionIntLiteralProperty is ModelTemplate<42 | 43>;
|
|
266
228
|
@route("/union/int/literal")
|
|
267
|
-
@operationGroup
|
|
268
229
|
interface UnionIntLiteral extends ModelOperations<UnionIntLiteralProperty, "42"> {}
|
|
269
230
|
|
|
270
231
|
@doc("Model with a union of float literal as property.")
|
|
271
232
|
model UnionFloatLiteralProperty is ModelTemplate<43.125 | 46.875>;
|
|
272
233
|
@route("/union/float/literal")
|
|
273
|
-
@operationGroup
|
|
274
234
|
interface UnionFloatLiteral extends ModelOperations<UnionFloatLiteralProperty, "46.875"> {}
|
|
275
235
|
|
|
276
236
|
union ExtendedEnum {
|
|
@@ -281,5 +241,4 @@ union ExtendedEnum {
|
|
|
281
241
|
model UnionEnumValueProperty is ModelTemplate<ExtendedEnum.EnumValue2>;
|
|
282
242
|
|
|
283
243
|
@route("/union-enum-value")
|
|
284
|
-
@operationGroup
|
|
285
244
|
interface UnionEnumValue extends ModelOperations<UnionEnumValueProperty, "\"value2\""> {}
|
|
@@ -1,13 +1,12 @@
|
|
|
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
|
@scenarioService("/type/scalar")
|
|
8
8
|
namespace Type.Scalar;
|
|
9
9
|
|
|
10
|
-
@operationGroup
|
|
11
10
|
@route("/string")
|
|
12
11
|
interface String {
|
|
13
12
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
@@ -25,7 +24,6 @@ interface String {
|
|
|
25
24
|
put(@body @doc("_") body: string): void;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
@operationGroup
|
|
29
27
|
@route("/boolean")
|
|
30
28
|
interface Boolean {
|
|
31
29
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
@@ -43,7 +41,6 @@ interface Boolean {
|
|
|
43
41
|
put(@body @doc("_") body: boolean): void;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
@operationGroup
|
|
47
44
|
@route("/unknown")
|
|
48
45
|
interface Unknown {
|
|
49
46
|
#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "For testing"
|
|
@@ -62,49 +59,34 @@ interface Unknown {
|
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
@doc("Template to have scalar types operations")
|
|
65
|
-
interface ScalarTypesOperations<T, TDoc extends string> {
|
|
62
|
+
interface ScalarTypesOperations<T, TDoc extends valueof string> {
|
|
66
63
|
@scenario
|
|
67
|
-
@scenarioDoc(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
""",
|
|
74
|
-
{
|
|
75
|
-
doc: TDoc,
|
|
76
|
-
}
|
|
77
|
-
)
|
|
64
|
+
@scenarioDoc("""
|
|
65
|
+
Expected response body:
|
|
66
|
+
```json
|
|
67
|
+
${TDoc}
|
|
68
|
+
```
|
|
69
|
+
""")
|
|
78
70
|
@get
|
|
79
71
|
@route("/response_body")
|
|
80
72
|
responseBody(): T;
|
|
81
73
|
|
|
82
74
|
@scenario
|
|
83
|
-
@scenarioDoc(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
""",
|
|
90
|
-
{
|
|
91
|
-
doc: TDoc,
|
|
92
|
-
}
|
|
93
|
-
)
|
|
75
|
+
@scenarioDoc("""
|
|
76
|
+
Expected input body:
|
|
77
|
+
```json
|
|
78
|
+
${TDoc}
|
|
79
|
+
```
|
|
80
|
+
""")
|
|
94
81
|
@put
|
|
95
82
|
@route("/resquest_body")
|
|
96
83
|
requestBody(@body body: T): void;
|
|
97
84
|
|
|
98
85
|
@scenario
|
|
99
|
-
@scenarioDoc(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
""",
|
|
104
|
-
{
|
|
105
|
-
doc: TDoc,
|
|
106
|
-
}
|
|
107
|
-
)
|
|
86
|
+
@scenarioDoc("""
|
|
87
|
+
Expected request parameter:
|
|
88
|
+
value=${TDoc}
|
|
89
|
+
""")
|
|
108
90
|
@get
|
|
109
91
|
@route("/request_parameter")
|
|
110
92
|
requestParameter(@query value: T): void;
|
|
@@ -112,42 +94,34 @@ interface ScalarTypesOperations<T, TDoc extends string> {
|
|
|
112
94
|
|
|
113
95
|
@doc("Decimal type")
|
|
114
96
|
@route("/decimal")
|
|
115
|
-
@operationGroup
|
|
116
97
|
interface DecimalType extends ScalarTypesOperations<decimal, "0.33333"> {}
|
|
117
98
|
|
|
118
99
|
@doc("Decimal128 type")
|
|
119
100
|
@route("/decimal128")
|
|
120
|
-
@operationGroup
|
|
121
101
|
interface Decimal128Type extends ScalarTypesOperations<decimal128, "0.33333"> {}
|
|
122
102
|
|
|
123
103
|
@doc("Template to verify number types")
|
|
124
|
-
interface NumberTypesVerifyOperations<
|
|
104
|
+
interface NumberTypesVerifyOperations<
|
|
105
|
+
T,
|
|
106
|
+
VerifyValues extends valueof string,
|
|
107
|
+
ResultValue extends valueof string
|
|
108
|
+
> {
|
|
125
109
|
@scenario
|
|
126
|
-
@scenarioDoc(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
""",
|
|
131
|
-
{
|
|
132
|
-
doc: VerifyValues,
|
|
133
|
-
}
|
|
134
|
-
)
|
|
110
|
+
@scenarioDoc("""
|
|
111
|
+
Get verify values:
|
|
112
|
+
${VerifyValues}
|
|
113
|
+
""")
|
|
135
114
|
@get
|
|
136
115
|
@route("/prepare_verify")
|
|
137
116
|
prepareVerify(): T[];
|
|
138
117
|
|
|
139
118
|
@scenario
|
|
140
|
-
@scenarioDoc(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
""",
|
|
147
|
-
{
|
|
148
|
-
doc: ResultValue,
|
|
149
|
-
}
|
|
150
|
-
)
|
|
119
|
+
@scenarioDoc("""
|
|
120
|
+
Expected input body:
|
|
121
|
+
```json
|
|
122
|
+
${ResultValue}
|
|
123
|
+
```
|
|
124
|
+
""")
|
|
151
125
|
@post
|
|
152
126
|
@route("/verify")
|
|
153
127
|
verify(@body body: T): void;
|
|
@@ -155,10 +129,8 @@ interface NumberTypesVerifyOperations<T, VerifyValues extends string, ResultValu
|
|
|
155
129
|
|
|
156
130
|
@doc("Decimal type verification")
|
|
157
131
|
@route("/decimal")
|
|
158
|
-
@operationGroup
|
|
159
132
|
interface DecimalVerify extends NumberTypesVerifyOperations<decimal, "[0.1, 0.1, 0.1]", "0.3"> {}
|
|
160
133
|
|
|
161
134
|
@doc("Decimal128 type verification")
|
|
162
135
|
@route("/decimal128")
|
|
163
|
-
@operationGroup
|
|
164
136
|
interface Decimal128Verify extends NumberTypesVerifyOperations<decimal, "[0.1, 0.1, 0.1]", "0.3"> {}
|
|
@@ -1,13 +1,12 @@
|
|
|
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
|
/**
|
|
8
8
|
* Describe scenarios for various combinations of unions.
|
|
9
9
|
*/
|
|
10
|
-
@supportedBy("dpg")
|
|
11
10
|
@scenarioService("/type/union")
|
|
12
11
|
namespace Type.Union;
|
|
13
12
|
|
|
@@ -32,14 +31,12 @@ enum UD {
|
|
|
32
31
|
* Describe union of string "a" | "b" | "c"
|
|
33
32
|
*/
|
|
34
33
|
@route("/strings-only")
|
|
35
|
-
@operationGroup
|
|
36
34
|
interface StringsOnly extends GetAndSend<"a" | "b" | "c", "\"b\""> {}
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
37
|
* Describe union of string string | "b" | "c"
|
|
40
38
|
*/
|
|
41
39
|
@route("/string-extensible")
|
|
42
|
-
@operationGroup
|
|
43
40
|
interface StringExtensible extends GetAndSend<string | "b" | "c", "\"custom\""> {}
|
|
44
41
|
|
|
45
42
|
union StringExtensibleNamedUnion {
|
|
@@ -51,28 +48,24 @@ union StringExtensibleNamedUnion {
|
|
|
51
48
|
* Describe union of string string | "b" | "c" but where the union is named and some of the variants are named
|
|
52
49
|
*/
|
|
53
50
|
@route("/string-extensible-named")
|
|
54
|
-
@operationGroup
|
|
55
51
|
interface StringExtensibleNamed extends GetAndSend<StringExtensibleNamedUnion, "\"custom\""> {}
|
|
56
52
|
|
|
57
53
|
/**
|
|
58
54
|
* Describe union of integer 1 | 2 | 3
|
|
59
55
|
*/
|
|
60
56
|
@route("/ints-only")
|
|
61
|
-
@operationGroup
|
|
62
57
|
interface IntsOnly extends GetAndSend<1 | 2 | 3, "2"> {}
|
|
63
58
|
|
|
64
59
|
/**
|
|
65
60
|
* Describe union of floats 1.1 | 2.2 | 3.3
|
|
66
61
|
*/
|
|
67
62
|
@route("/floats-only")
|
|
68
|
-
@operationGroup
|
|
69
63
|
interface FloatsOnly extends GetAndSend<1.1 | 2.2 | 3.3, "2.2"> {}
|
|
70
64
|
|
|
71
65
|
/**
|
|
72
66
|
* Describe union of models
|
|
73
67
|
*/
|
|
74
68
|
@route("/models-only")
|
|
75
|
-
@operationGroup
|
|
76
69
|
interface ModelsOnly
|
|
77
70
|
extends GetAndSend<
|
|
78
71
|
Cat | Dog,
|
|
@@ -95,7 +88,6 @@ model EnumsOnlyCases {
|
|
|
95
88
|
* Describe union of 2 different enums
|
|
96
89
|
*/
|
|
97
90
|
@route("/enums-only")
|
|
98
|
-
@operationGroup
|
|
99
91
|
interface EnumsOnly
|
|
100
92
|
extends GetAndSend<
|
|
101
93
|
LR | UD,
|
|
@@ -120,7 +112,6 @@ model StringAndArrayCases {
|
|
|
120
112
|
* Describe union of a string and an array of strings
|
|
121
113
|
*/
|
|
122
114
|
@route("/string-and-array")
|
|
123
|
-
@operationGroup
|
|
124
115
|
interface StringAndArray
|
|
125
116
|
extends GetAndSend<
|
|
126
117
|
string | string[],
|
|
@@ -152,7 +143,6 @@ model MixedLiteralsCases {
|
|
|
152
143
|
* Describe union of floats "a" | 2 | 3.3
|
|
153
144
|
*/
|
|
154
145
|
@route("/mixed-literals")
|
|
155
|
-
@operationGroup
|
|
156
146
|
interface MixedLiterals
|
|
157
147
|
extends GetAndSend<
|
|
158
148
|
MixedLiteralsUnion,
|
|
@@ -189,7 +179,6 @@ model MixedTypesCases {
|
|
|
189
179
|
* Describe union of floats "a" | 2 | 3.3
|
|
190
180
|
*/
|
|
191
181
|
@route("/mixed-types")
|
|
192
|
-
@operationGroup
|
|
193
182
|
interface MixedTypes
|
|
194
183
|
extends GetAndSend<
|
|
195
184
|
MixedTypesUnion,
|
|
@@ -217,7 +206,7 @@ interface MixedTypes
|
|
|
217
206
|
/**
|
|
218
207
|
* Helper interface to describe a test involving getting and sending a specific data
|
|
219
208
|
*/
|
|
220
|
-
interface GetAndSend<Union, Payload extends string, Cases = Union> {
|
|
209
|
+
interface GetAndSend<Union, Payload extends valueof string, Cases = Union> {
|
|
221
210
|
@scenario
|
|
222
211
|
@scenarioDoc(
|
|
223
212
|
"""
|
|
@@ -228,12 +217,11 @@ interface GetAndSend<Union, Payload extends string, Cases = Union> {
|
|
|
228
217
|
|
|
229
218
|
Expected response body:
|
|
230
219
|
```json
|
|
231
|
-
{ "prop": {
|
|
220
|
+
{ "prop": ${Payload}}
|
|
232
221
|
```
|
|
233
222
|
""",
|
|
234
223
|
{
|
|
235
224
|
type: Union,
|
|
236
|
-
value: Payload,
|
|
237
225
|
}
|
|
238
226
|
)
|
|
239
227
|
get(): {
|
|
@@ -250,12 +238,11 @@ interface GetAndSend<Union, Payload extends string, Cases = Union> {
|
|
|
250
238
|
|
|
251
239
|
Expected request to send body:
|
|
252
240
|
```json
|
|
253
|
-
{ "prop": {
|
|
241
|
+
{ "prop": ${Payload}}
|
|
254
242
|
```
|
|
255
243
|
""",
|
|
256
244
|
{
|
|
257
245
|
type: Union,
|
|
258
|
-
value: Payload,
|
|
259
246
|
}
|
|
260
247
|
)
|
|
261
248
|
send(prop: Cases): void;
|