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

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.
Files changed (224) hide show
  1. package/CHANGELOG.md +241 -3
  2. package/README.md +11 -3
  3. package/dist/specs/authentication/noauth/union/mockapi.d.ts +3 -0
  4. package/dist/specs/authentication/noauth/union/mockapi.d.ts.map +1 -0
  5. package/dist/specs/authentication/noauth/union/mockapi.js +25 -0
  6. package/dist/specs/authentication/noauth/union/mockapi.js.map +1 -0
  7. package/dist/specs/documentation/mockapi.d.ts +3 -0
  8. package/dist/specs/documentation/mockapi.d.ts.map +1 -0
  9. package/dist/specs/documentation/mockapi.js +40 -0
  10. package/dist/specs/documentation/mockapi.js.map +1 -0
  11. package/dist/specs/encode/array/mockapi.d.ts +3 -0
  12. package/dist/specs/encode/array/mockapi.d.ts.map +1 -0
  13. package/dist/specs/encode/array/mockapi.js +33 -0
  14. package/dist/specs/encode/array/mockapi.js.map +1 -0
  15. package/dist/specs/encode/bytes/mockapi.js +16 -24
  16. package/dist/specs/encode/bytes/mockapi.js.map +1 -1
  17. package/dist/specs/encode/datetime/mockapi.js +2 -2
  18. package/dist/specs/encode/datetime/mockapi.js.map +1 -1
  19. package/dist/specs/encode/duration/mockapi.d.ts.map +1 -1
  20. package/dist/specs/encode/duration/mockapi.js +110 -3
  21. package/dist/specs/encode/duration/mockapi.js.map +1 -1
  22. package/dist/specs/encode/numeric/mockapi.js +2 -2
  23. package/dist/specs/encode/numeric/mockapi.js.map +1 -1
  24. package/dist/specs/helper.d.ts +2 -2
  25. package/dist/specs/helper.d.ts.map +1 -1
  26. package/dist/specs/parameters/basic/mockapi.d.ts.map +1 -1
  27. package/dist/specs/parameters/basic/mockapi.js +3 -3
  28. package/dist/specs/parameters/basic/mockapi.js.map +1 -1
  29. package/dist/specs/parameters/body-optionality/mockapi.d.ts.map +1 -1
  30. package/dist/specs/parameters/body-optionality/mockapi.js +14 -4
  31. package/dist/specs/parameters/body-optionality/mockapi.js.map +1 -1
  32. package/dist/specs/parameters/collection-format/mockapi.js +4 -15
  33. package/dist/specs/parameters/collection-format/mockapi.js.map +1 -1
  34. package/dist/specs/parameters/path/mockapi.d.ts +3 -0
  35. package/dist/specs/parameters/path/mockapi.d.ts.map +1 -0
  36. package/dist/specs/parameters/path/mockapi.js +29 -0
  37. package/dist/specs/parameters/path/mockapi.js.map +1 -0
  38. package/dist/specs/parameters/query/mockapi.d.ts +3 -0
  39. package/dist/specs/parameters/query/mockapi.d.ts.map +1 -0
  40. package/dist/specs/parameters/query/mockapi.js +14 -0
  41. package/dist/specs/parameters/query/mockapi.js.map +1 -0
  42. package/dist/specs/parameters/spread/mockapi.d.ts.map +1 -1
  43. package/dist/specs/parameters/spread/mockapi.js +19 -19
  44. package/dist/specs/parameters/spread/mockapi.js.map +1 -1
  45. package/dist/specs/payload/json-merge-patch/mockapi.js +4 -4
  46. package/dist/specs/payload/json-merge-patch/mockapi.js.map +1 -1
  47. package/dist/specs/payload/media-type/mockapi.js +2 -2
  48. package/dist/specs/payload/media-type/mockapi.js.map +1 -1
  49. package/dist/specs/payload/multipart/mockapi.d.ts.map +1 -1
  50. package/dist/specs/payload/multipart/mockapi.js +189 -60
  51. package/dist/specs/payload/multipart/mockapi.js.map +1 -1
  52. package/dist/specs/payload/pageable/mockapi.d.ts.map +1 -1
  53. package/dist/specs/payload/pageable/mockapi.js +594 -14
  54. package/dist/specs/payload/pageable/mockapi.js.map +1 -1
  55. package/dist/specs/payload/xml/mockapi.d.ts +3 -0
  56. package/dist/specs/payload/xml/mockapi.d.ts.map +1 -1
  57. package/dist/specs/payload/xml/mockapi.js +35 -5
  58. package/dist/specs/payload/xml/mockapi.js.map +1 -1
  59. package/dist/specs/response/status-code-range/mockapi.d.ts.map +1 -1
  60. package/dist/specs/response/status-code-range/mockapi.js +5 -9
  61. package/dist/specs/response/status-code-range/mockapi.js.map +1 -1
  62. package/dist/specs/routes/mockapi.js +16 -16
  63. package/dist/specs/routes/mockapi.js.map +1 -1
  64. package/dist/specs/serialization/encoded-name/json/mockapi.js +1 -1
  65. package/dist/specs/serialization/encoded-name/json/mockapi.js.map +1 -1
  66. package/dist/specs/server/versions/not-versioned/mockapi.js +1 -1
  67. package/dist/specs/server/versions/not-versioned/mockapi.js.map +1 -1
  68. package/dist/specs/server/versions/versioned/mockapi.js +8 -12
  69. package/dist/specs/server/versions/versioned/mockapi.js.map +1 -1
  70. package/dist/specs/special-words/mockapi.d.ts.map +1 -1
  71. package/dist/specs/special-words/mockapi.js +59 -6
  72. package/dist/specs/special-words/mockapi.js.map +1 -1
  73. package/dist/specs/streaming/jsonl/mockapi.d.ts +3 -0
  74. package/dist/specs/streaming/jsonl/mockapi.d.ts.map +1 -0
  75. package/dist/specs/streaming/jsonl/mockapi.js +30 -0
  76. package/dist/specs/streaming/jsonl/mockapi.js.map +1 -0
  77. package/dist/specs/type/array/mockapi.js +1 -1
  78. package/dist/specs/type/array/mockapi.js.map +1 -1
  79. package/dist/specs/type/dictionary/mockapi.js +1 -1
  80. package/dist/specs/type/dictionary/mockapi.js.map +1 -1
  81. package/dist/specs/type/enum/extensible/mockapi.js +1 -1
  82. package/dist/specs/type/enum/extensible/mockapi.js.map +1 -1
  83. package/dist/specs/type/enum/fixed/mockapi.js +2 -2
  84. package/dist/specs/type/enum/fixed/mockapi.js.map +1 -1
  85. package/dist/specs/type/file/mockapi.d.ts +3 -0
  86. package/dist/specs/type/file/mockapi.d.ts.map +1 -0
  87. package/dist/specs/type/file/mockapi.js +187 -0
  88. package/dist/specs/type/file/mockapi.js.map +1 -0
  89. package/dist/specs/type/model/empty/mockapi.js +2 -2
  90. package/dist/specs/type/model/empty/mockapi.js.map +1 -1
  91. package/dist/specs/type/model/inheritance/enum-discriminator/mockapi.js +1 -1
  92. package/dist/specs/type/model/inheritance/enum-discriminator/mockapi.js.map +1 -1
  93. package/dist/specs/type/model/inheritance/nested-discriminator/mockapi.js +2 -2
  94. package/dist/specs/type/model/inheritance/nested-discriminator/mockapi.js.map +1 -1
  95. package/dist/specs/type/model/inheritance/not-discriminated/mockapi.js +2 -2
  96. package/dist/specs/type/model/inheritance/not-discriminated/mockapi.js.map +1 -1
  97. package/dist/specs/type/model/inheritance/recursive/mockapi.js +1 -1
  98. package/dist/specs/type/model/inheritance/recursive/mockapi.js.map +1 -1
  99. package/dist/specs/type/model/inheritance/single-discriminator/mockapi.js +2 -2
  100. package/dist/specs/type/model/inheritance/single-discriminator/mockapi.js.map +1 -1
  101. package/dist/specs/type/model/usage/mockapi.js +4 -4
  102. package/dist/specs/type/model/usage/mockapi.js.map +1 -1
  103. package/dist/specs/type/model/visibility/mockapi.js +9 -10
  104. package/dist/specs/type/model/visibility/mockapi.js.map +1 -1
  105. package/dist/specs/type/property/additional-properties/mockapi.js +9 -6
  106. package/dist/specs/type/property/additional-properties/mockapi.js.map +1 -1
  107. package/dist/specs/type/property/nullable/mockapi.js +2 -6
  108. package/dist/specs/type/property/nullable/mockapi.js.map +1 -1
  109. package/dist/specs/type/property/optionality/mockapi.js +1 -1
  110. package/dist/specs/type/property/optionality/mockapi.js.map +1 -1
  111. package/dist/specs/type/property/value-types/mockapi.js +3 -3
  112. package/dist/specs/type/property/value-types/mockapi.js.map +1 -1
  113. package/dist/specs/type/scalar/mockapi.js +9 -9
  114. package/dist/specs/type/scalar/mockapi.js.map +1 -1
  115. package/dist/specs/type/union/discriminated/mockapi.d.ts +3 -0
  116. package/dist/specs/type/union/discriminated/mockapi.d.ts.map +1 -0
  117. package/dist/specs/type/union/discriminated/mockapi.js +212 -0
  118. package/dist/specs/type/union/discriminated/mockapi.js.map +1 -0
  119. package/dist/specs/type/union/mockapi.js +2 -2
  120. package/dist/specs/type/union/mockapi.js.map +1 -1
  121. package/dist/specs/versioning/added/mockapi.js +6 -6
  122. package/dist/specs/versioning/added/mockapi.js.map +1 -1
  123. package/dist/specs/versioning/madeOptional/mockapi.js +2 -2
  124. package/dist/specs/versioning/madeOptional/mockapi.js.map +1 -1
  125. package/dist/specs/versioning/removed/mockapi.js +11 -11
  126. package/dist/specs/versioning/removed/mockapi.js.map +1 -1
  127. package/dist/specs/versioning/renamedFrom/mockapi.js +5 -5
  128. package/dist/specs/versioning/renamedFrom/mockapi.js.map +1 -1
  129. package/dist/specs/versioning/returnTypeChangedFrom/mockapi.js +1 -1
  130. package/dist/specs/versioning/returnTypeChangedFrom/mockapi.js.map +1 -1
  131. package/dist/specs/versioning/typeChangedFrom/mockapi.js +3 -3
  132. package/dist/specs/versioning/typeChangedFrom/mockapi.js.map +1 -1
  133. package/manifest.json +11200 -0
  134. package/package.json +30 -19
  135. package/smoke/petstore/main.tsp +96 -0
  136. package/smoke/todoapp/main.tsp +293 -0
  137. package/spec-summary.md +1745 -121
  138. package/specs/authentication/noauth/union/main.tsp +30 -0
  139. package/specs/authentication/noauth/union/mockapi.ts +27 -0
  140. package/specs/documentation/main.tsp +158 -0
  141. package/specs/documentation/mockapi.ts +59 -0
  142. package/specs/encode/array/main.tsp +339 -0
  143. package/specs/encode/array/mockapi.ts +83 -0
  144. package/specs/encode/bytes/main.tsp +29 -20
  145. package/specs/encode/bytes/mockapi.ts +13 -31
  146. package/specs/encode/datetime/main.tsp +2 -7
  147. package/specs/encode/datetime/mockapi.ts +2 -2
  148. package/specs/encode/duration/main.tsp +420 -7
  149. package/specs/encode/duration/mockapi.ts +216 -2
  150. package/specs/encode/numeric/mockapi.ts +2 -2
  151. package/specs/parameters/basic/mockapi.ts +3 -3
  152. package/specs/parameters/body-optionality/main.tsp +2 -0
  153. package/specs/parameters/body-optionality/mockapi.ts +24 -4
  154. package/specs/parameters/collection-format/main.tsp +5 -25
  155. package/specs/parameters/collection-format/mockapi.ts +4 -16
  156. package/specs/parameters/path/main.tsp +48 -0
  157. package/specs/parameters/path/mockapi.ts +34 -0
  158. package/specs/parameters/query/main.tsp +22 -0
  159. package/specs/parameters/query/mockapi.ts +15 -0
  160. package/specs/parameters/spread/mockapi.ts +19 -19
  161. package/specs/payload/json-merge-patch/main.tsp +2 -2
  162. package/specs/payload/json-merge-patch/mockapi.ts +4 -4
  163. package/specs/payload/media-type/mockapi.ts +2 -2
  164. package/specs/payload/multipart/main.tsp +230 -32
  165. package/specs/payload/multipart/mockapi.ts +200 -59
  166. package/specs/payload/pageable/main.tsp +601 -0
  167. package/specs/payload/pageable/mockapi.ts +656 -14
  168. package/specs/payload/xml/main.tsp +89 -0
  169. package/specs/payload/xml/mockapi.ts +44 -5
  170. package/specs/response/status-code-range/main.tsp +2 -2
  171. package/specs/response/status-code-range/mockapi.ts +5 -9
  172. package/specs/routes/main.tsp +29 -29
  173. package/specs/routes/mockapi.ts +16 -16
  174. package/specs/serialization/encoded-name/json/main.tsp +1 -1
  175. package/specs/serialization/encoded-name/json/mockapi.ts +1 -1
  176. package/specs/server/endpoint/not-defined/main.tsp +1 -3
  177. package/specs/server/path/multiple/main.tsp +3 -5
  178. package/specs/server/versions/not-versioned/mockapi.ts +1 -1
  179. package/specs/server/versions/versioned/main.tsp +1 -1
  180. package/specs/server/versions/versioned/mockapi.ts +6 -12
  181. package/specs/special-headers/conditional-request/main.tsp +1 -1
  182. package/specs/special-headers/repeatability/main.tsp +2 -2
  183. package/specs/special-words/main.tsp +118 -6
  184. package/specs/special-words/mockapi.ts +62 -6
  185. package/specs/streaming/jsonl/main.tsp +33 -0
  186. package/specs/streaming/jsonl/mockapi.ts +32 -0
  187. package/specs/type/array/mockapi.ts +1 -1
  188. package/specs/type/dictionary/mockapi.ts +1 -1
  189. package/specs/type/enum/extensible/main.tsp +18 -2
  190. package/specs/type/enum/extensible/mockapi.ts +1 -1
  191. package/specs/type/enum/fixed/main.tsp +15 -3
  192. package/specs/type/enum/fixed/mockapi.ts +2 -2
  193. package/specs/type/file/main.tsp +109 -0
  194. package/specs/type/file/mockapi.ts +200 -0
  195. package/specs/type/model/empty/mockapi.ts +2 -2
  196. package/specs/type/model/inheritance/enum-discriminator/mockapi.ts +1 -1
  197. package/specs/type/model/inheritance/nested-discriminator/mockapi.ts +2 -2
  198. package/specs/type/model/inheritance/not-discriminated/mockapi.ts +2 -2
  199. package/specs/type/model/inheritance/recursive/mockapi.ts +1 -1
  200. package/specs/type/model/inheritance/single-discriminator/mockapi.ts +2 -2
  201. package/specs/type/model/usage/mockapi.ts +4 -4
  202. package/specs/type/model/visibility/main.tsp +9 -17
  203. package/specs/type/model/visibility/mockapi.ts +9 -10
  204. package/specs/type/property/additional-properties/main.tsp +17 -17
  205. package/specs/type/property/additional-properties/mockapi.ts +10 -10
  206. package/specs/type/property/nullable/mockapi.ts +7 -8
  207. package/specs/type/property/optionality/mockapi.ts +1 -1
  208. package/specs/type/property/value-types/mockapi.ts +3 -3
  209. package/specs/type/scalar/main.tsp +58 -9
  210. package/specs/type/scalar/mockapi.ts +9 -9
  211. package/specs/type/union/discriminated/main.tsp +251 -0
  212. package/specs/type/union/discriminated/mockapi.ts +230 -0
  213. package/specs/type/union/mockapi.ts +2 -2
  214. package/specs/versioning/added/mockapi.ts +6 -6
  215. package/specs/versioning/madeOptional/mockapi.ts +2 -2
  216. package/specs/versioning/removed/main.tsp +5 -5
  217. package/specs/versioning/removed/mockapi.ts +11 -11
  218. package/specs/versioning/renamedFrom/mockapi.ts +5 -5
  219. package/specs/versioning/returnTypeChangedFrom/main.tsp +17 -2
  220. package/specs/versioning/returnTypeChangedFrom/mockapi.ts +1 -1
  221. package/specs/versioning/typeChangedFrom/mockapi.ts +3 -3
  222. package/temp/.tsbuildinfo +1 -1
  223. package/tsconfig.build.json +0 -4
  224. package/tspconfig.yaml +0 -2
@@ -4,6 +4,7 @@ import {
4
4
  MockRequest,
5
5
  passOnSuccess,
6
6
  ScenarioMockApi,
7
+ ValidationError,
7
8
  } from "@typespec/spec-api";
8
9
 
9
10
  export const Scenarios: Record<string, ScenarioMockApi> = {};
@@ -13,7 +14,7 @@ function createBodyServerTests(uri: string, data: any, value: any) {
13
14
  uri,
14
15
  method: "post",
15
16
  request: {
16
- body: data,
17
+ body: json(data),
17
18
  },
18
19
  response: {
19
20
  status: 200,
@@ -65,6 +66,63 @@ Scenarios.Encode_Duration_Property_floatSecondsArray = createBodyServerTests(
65
66
  [35.625, 46.75],
66
67
  );
67
68
 
69
+ Scenarios.Encode_Duration_Property_int32Milliseconds = createBodyServerTests(
70
+ "/encode/duration/property/int32-milliseconds",
71
+ {
72
+ value: 36000,
73
+ },
74
+ 36000,
75
+ );
76
+ Scenarios.Encode_Duration_Property_floatMilliseconds = createBodyServerTests(
77
+ "/encode/duration/property/float-milliseconds",
78
+ {
79
+ value: 35625,
80
+ },
81
+ 35625,
82
+ );
83
+ Scenarios.Encode_Duration_Property_float64Milliseconds = createBodyServerTests(
84
+ "/encode/duration/property/float64-milliseconds",
85
+ {
86
+ value: 35625,
87
+ },
88
+ 35625,
89
+ );
90
+ Scenarios.Encode_Duration_Property_floatMillisecondsArray = createBodyServerTests(
91
+ "/encode/duration/property/float-milliseconds-array",
92
+ {
93
+ value: [35625, 46750],
94
+ },
95
+ [35625, 46750],
96
+ );
97
+ Scenarios.Encode_Duration_Property_int32SecondsLargerUnit = createBodyServerTests(
98
+ "/encode/duration/property/int32-seconds-larger-unit",
99
+ {
100
+ value: 120,
101
+ },
102
+ 120,
103
+ );
104
+ Scenarios.Encode_Duration_Property_floatSecondsLargerUnit = createBodyServerTests(
105
+ "/encode/duration/property/float-seconds-larger-unit",
106
+ {
107
+ value: 150.0,
108
+ },
109
+ 150.0,
110
+ );
111
+ Scenarios.Encode_Duration_Property_int32MillisecondsLargerUnit = createBodyServerTests(
112
+ "/encode/duration/property/int32-milliseconds-larger-unit",
113
+ {
114
+ value: 180000,
115
+ },
116
+ 180000,
117
+ );
118
+ Scenarios.Encode_Duration_Property_floatMillisecondsLargerUnit = createBodyServerTests(
119
+ "/encode/duration/property/float-milliseconds-larger-unit",
120
+ {
121
+ value: 210000.0,
122
+ },
123
+ 210000.0,
124
+ );
125
+
68
126
  function createQueryServerTests(
69
127
  uri: string,
70
128
  paramData: any,
@@ -75,7 +133,7 @@ function createQueryServerTests(
75
133
  uri,
76
134
  method: "get",
77
135
  request: {
78
- params: paramData,
136
+ query: paramData,
79
137
  },
80
138
  response: {
81
139
  status: 204,
@@ -89,6 +147,34 @@ function createQueryServerTests(
89
147
  kind: "MockApiDefinition",
90
148
  });
91
149
  }
150
+
151
+ function createQueryFloatServerTests(uri: string, paramData: any, value: number) {
152
+ return passOnSuccess({
153
+ uri,
154
+ method: "get",
155
+ request: {
156
+ query: paramData,
157
+ },
158
+ response: {
159
+ status: 204,
160
+ },
161
+ handler: (req: MockRequest) => {
162
+ const actual = req.query["input"] as string;
163
+ const actualNum = parseFloat(actual);
164
+ if (isNaN(actualNum) || actualNum !== value) {
165
+ throw new ValidationError(
166
+ `Expected query param input=${value} but got ${actual}`,
167
+ String(value),
168
+ actual,
169
+ );
170
+ }
171
+ return {
172
+ status: 204,
173
+ };
174
+ },
175
+ kind: "MockApiDefinition",
176
+ });
177
+ }
92
178
  Scenarios.Encode_Duration_Query_default = createQueryServerTests(
93
179
  "/encode/duration/query/default",
94
180
  {
@@ -133,6 +219,64 @@ Scenarios.Encode_Duration_Query_float64Seconds = createQueryServerTests(
133
219
  "35.625",
134
220
  );
135
221
 
222
+ Scenarios.Encode_Duration_Query_int32Milliseconds = createQueryServerTests(
223
+ "/encode/duration/query/int32-milliseconds",
224
+ {
225
+ input: 36000,
226
+ },
227
+ "36000",
228
+ );
229
+ Scenarios.Encode_Duration_Query_floatMilliseconds = createQueryFloatServerTests(
230
+ "/encode/duration/query/float-milliseconds",
231
+ {
232
+ input: 35625,
233
+ },
234
+ 35625,
235
+ );
236
+ Scenarios.Encode_Duration_Query_float64Milliseconds = createQueryFloatServerTests(
237
+ "/encode/duration/query/float64-milliseconds",
238
+ {
239
+ input: 35625,
240
+ },
241
+ 35625,
242
+ );
243
+ Scenarios.Encode_Duration_Query_int32MillisecondsArray = createQueryServerTests(
244
+ "/encode/duration/query/int32-milliseconds-array",
245
+ {
246
+ input: [36000, 47000].join(","),
247
+ },
248
+ ["36000", "47000"],
249
+ "csv",
250
+ );
251
+ Scenarios.Encode_Duration_Query_int32SecondsLargerUnit = createQueryServerTests(
252
+ "/encode/duration/query/int32-seconds-larger-unit",
253
+ {
254
+ input: 120,
255
+ },
256
+ "120",
257
+ );
258
+ Scenarios.Encode_Duration_Query_floatSecondsLargerUnit = createQueryFloatServerTests(
259
+ "/encode/duration/query/float-seconds-larger-unit",
260
+ {
261
+ input: 150,
262
+ },
263
+ 150,
264
+ );
265
+ Scenarios.Encode_Duration_Query_int32MillisecondsLargerUnit = createQueryServerTests(
266
+ "/encode/duration/query/int32-milliseconds-larger-unit",
267
+ {
268
+ input: 180000,
269
+ },
270
+ "180000",
271
+ );
272
+ Scenarios.Encode_Duration_Query_floatMillisecondsLargerUnit = createQueryFloatServerTests(
273
+ "/encode/duration/query/float-milliseconds-larger-unit",
274
+ {
275
+ input: 210000,
276
+ },
277
+ 210000,
278
+ );
279
+
136
280
  function createHeaderServerTests(uri: string, headersData: any, value: any) {
137
281
  return passOnSuccess({
138
282
  uri,
@@ -147,6 +291,31 @@ function createHeaderServerTests(uri: string, headersData: any, value: any) {
147
291
  });
148
292
  }
149
293
 
294
+ function createHeaderFloatServerTests(uri: string, value: number) {
295
+ return passOnSuccess({
296
+ uri,
297
+ method: "get",
298
+ response: {
299
+ status: 204,
300
+ },
301
+ handler: (req: MockRequest) => {
302
+ const actual = req.headers["duration"];
303
+ const actualNum = parseFloat(actual);
304
+ if (isNaN(actualNum) || actualNum !== value) {
305
+ throw new ValidationError(
306
+ `Expected header duration=${value} but got ${actual}`,
307
+ String(value),
308
+ actual,
309
+ );
310
+ }
311
+ return {
312
+ status: 204,
313
+ };
314
+ },
315
+ kind: "MockApiDefinition",
316
+ });
317
+ }
318
+
150
319
  Scenarios.Encode_Duration_Header_default = createHeaderServerTests(
151
320
  "/encode/duration/header/default",
152
321
  {
@@ -189,3 +358,48 @@ Scenarios.Encode_Duration_Header_iso8601Array = createHeaderServerTests(
189
358
  },
190
359
  "P40D,P50D",
191
360
  );
361
+
362
+ Scenarios.Encode_Duration_Header_int32Milliseconds = createHeaderServerTests(
363
+ "/encode/duration/header/int32-milliseconds",
364
+ {
365
+ duration: "36000",
366
+ },
367
+ "36000",
368
+ );
369
+ Scenarios.Encode_Duration_Header_floatMilliseconds = createHeaderFloatServerTests(
370
+ "/encode/duration/header/float-milliseconds",
371
+ 35625,
372
+ );
373
+ Scenarios.Encode_Duration_Header_float64Milliseconds = createHeaderFloatServerTests(
374
+ "/encode/duration/header/float64-milliseconds",
375
+ 35625,
376
+ );
377
+ Scenarios.Encode_Duration_Header_int32MillisecondsArray = createHeaderServerTests(
378
+ "/encode/duration/header/int32-milliseconds-array",
379
+ {
380
+ duration: ["36000", "47000"].join(","),
381
+ },
382
+ "36000,47000",
383
+ );
384
+ Scenarios.Encode_Duration_Header_int32SecondsLargerUnit = createHeaderServerTests(
385
+ "/encode/duration/header/int32-seconds-larger-unit",
386
+ {
387
+ duration: "120",
388
+ },
389
+ "120",
390
+ );
391
+ Scenarios.Encode_Duration_Header_floatSecondsLargerUnit = createHeaderFloatServerTests(
392
+ "/encode/duration/header/float-seconds-larger-unit",
393
+ 150,
394
+ );
395
+ Scenarios.Encode_Duration_Header_int32MillisecondsLargerUnit = createHeaderServerTests(
396
+ "/encode/duration/header/int32-milliseconds-larger-unit",
397
+ {
398
+ duration: "180000",
399
+ },
400
+ "180000",
401
+ );
402
+ Scenarios.Encode_Duration_Header_floatMillisecondsLargerUnit = createHeaderFloatServerTests(
403
+ "/encode/duration/header/float-milliseconds-larger-unit",
404
+ 210000,
405
+ );
@@ -7,9 +7,9 @@ function createTests(uri: string, value: any) {
7
7
  uri,
8
8
  method: "post",
9
9
  request: {
10
- body: {
10
+ body: json({
11
11
  value,
12
- },
12
+ }),
13
13
  },
14
14
  response: {
15
15
  status: 200,
@@ -1,4 +1,4 @@
1
- import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
1
+ import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
2
2
 
3
3
  export const Scenarios: Record<string, ScenarioMockApi> = {};
4
4
  function createServerTests(uri: string) {
@@ -6,9 +6,9 @@ function createServerTests(uri: string) {
6
6
  uri,
7
7
  method: "put",
8
8
  request: {
9
- body: {
9
+ body: json({
10
10
  name: "foo",
11
- },
11
+ }),
12
12
  },
13
13
  response: {
14
14
  status: 204,
@@ -33,8 +33,10 @@ op requiredExplicit(@body body: BodyModel): NoContentResponse;
33
33
  ```json
34
34
  { "name": "foo" }
35
35
  ```
36
+ Expected Content-Type header: application/json
36
37
 
37
38
  Expected no request body for `omit`
39
+ Expected Content-Type header: must NOT be present
38
40
  """)
39
41
  @route("/optional-explicit")
40
42
  namespace OptionalExplicit {
@@ -1,4 +1,10 @@
1
- import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
1
+ import {
2
+ json,
3
+ MockRequest,
4
+ passOnSuccess,
5
+ ScenarioMockApi,
6
+ ValidationError,
7
+ } from "@typespec/spec-api";
2
8
 
3
9
  export const Scenarios: Record<string, ScenarioMockApi> = {};
4
10
  function createServerTests(uri: string, data: any) {
@@ -6,7 +12,7 @@ function createServerTests(uri: string, data: any) {
6
12
  uri,
7
13
  method: "post",
8
14
  request: {
9
- body: data,
15
+ body: json(data),
10
16
  },
11
17
  response: {
12
18
  status: 204,
@@ -27,13 +33,18 @@ Scenarios.Parameters_BodyOptionality_OptionalExplicit = passOnSuccess([
27
33
  uri: "/parameters/body-optionality/optional-explicit/set",
28
34
  method: "post",
29
35
  request: {
30
- body: {
36
+ body: json({
31
37
  name: "foo",
32
- },
38
+ }),
33
39
  },
34
40
  response: {
35
41
  status: 204,
36
42
  },
43
+ handler: (req: MockRequest) => {
44
+ // Validate that Content-Type header is present when body is provided
45
+ req.expect.containsHeader("content-type", "application/json");
46
+ return { status: 204 };
47
+ },
37
48
  kind: "MockApiDefinition",
38
49
  },
39
50
  {
@@ -45,6 +56,15 @@ Scenarios.Parameters_BodyOptionality_OptionalExplicit = passOnSuccess([
45
56
  },
46
57
  handler: (req: MockRequest) => {
47
58
  req.expect.rawBodyEquals(undefined);
59
+ // Validate that Content-Type header is NOT present when body is omitted
60
+ const contentTypeHeader = req.headers["content-type"];
61
+ if (contentTypeHeader !== undefined) {
62
+ throw new ValidationError(
63
+ "Content-Type header must NOT be present when body is omitted",
64
+ undefined,
65
+ contentTypeHeader,
66
+ );
67
+ }
48
68
  return { status: 204 };
49
69
  },
50
70
  kind: "MockApiDefinition",
@@ -27,25 +27,9 @@ namespace Query {
27
27
  """)
28
28
  @route("/ssv")
29
29
  op ssv(
30
- #suppress "deprecated" "Deprecated in next release"
31
30
  @doc("Possible values for colors are [blue,red,green]")
32
- @query({
33
- format: "ssv",
34
- })
35
- colors: string[],
36
- ): NoContentResponse;
37
-
38
- @scenario
39
- @scenarioDoc("""
40
- This test is testing sending a tsv collection format array query parameters
41
- """)
42
- @route("/tsv")
43
- op tsv(
44
- #suppress "deprecated" "Deprecated in next release"
45
- @doc("Possible values for colors are [blue,red,green]")
46
- @query({
47
- format: "tsv",
48
- })
31
+ @query
32
+ @encode(ArrayEncoding.spaceDelimited)
49
33
  colors: string[],
50
34
  ): NoContentResponse;
51
35
 
@@ -55,11 +39,9 @@ namespace Query {
55
39
  """)
56
40
  @route("/pipes")
57
41
  op pipes(
58
- #suppress "deprecated" "Deprecated in next release"
59
42
  @doc("Possible values for colors are [blue,red,green]")
60
- @query({
61
- format: "pipes",
62
- })
43
+ @query
44
+ @encode(ArrayEncoding.pipeDelimited)
63
45
  colors: string[],
64
46
  ): NoContentResponse;
65
47
 
@@ -84,9 +66,7 @@ namespace Header {
84
66
  @route("/csv")
85
67
  op csv(
86
68
  @doc("Possible values for colors are [blue,red,green]")
87
- @header({
88
- format: "csv",
89
- })
69
+ @header
90
70
  colors: string[],
91
71
  ): NoContentResponse;
92
72
  }
@@ -8,7 +8,7 @@ Scenarios.Parameters_CollectionFormat_Query_multi = passOnSuccess({
8
8
  uri: `/parameters/collection-format/query/multi`,
9
9
  method: "get",
10
10
  request: {
11
- params: { colors: ["blue", "red", "green"] },
11
+ query: { colors: ["blue", "red", "green"] },
12
12
  },
13
13
  response: {
14
14
  status: 204,
@@ -26,7 +26,7 @@ Scenarios.Parameters_CollectionFormat_Query_csv = passOnSuccess({
26
26
  uri: `/parameters/collection-format/query/csv`,
27
27
  method: "get",
28
28
  request: {
29
- params: { colors: colors.join(",") },
29
+ query: { colors: colors.join(",") },
30
30
  },
31
31
  response: {
32
32
  status: 204,
@@ -38,19 +38,7 @@ Scenarios.Parameters_CollectionFormat_Query_ssv = passOnSuccess({
38
38
  uri: `/parameters/collection-format/query/ssv`,
39
39
  method: "get",
40
40
  request: {
41
- params: { colors: colors.join(" ") },
42
- },
43
- response: {
44
- status: 204,
45
- },
46
- kind: "MockApiDefinition",
47
- });
48
-
49
- Scenarios.Parameters_CollectionFormat_Query_tsv = passOnSuccess({
50
- uri: `/parameters/collection-format/query/tsv`,
51
- method: "get",
52
- request: {
53
- params: { colors: colors.join("\t") },
41
+ query: { colors: colors.join(" ") },
54
42
  },
55
43
  response: {
56
44
  status: 204,
@@ -62,7 +50,7 @@ Scenarios.Parameters_CollectionFormat_Query_pipes = passOnSuccess({
62
50
  uri: `/parameters/collection-format/query/pipes`,
63
51
  method: "get",
64
52
  request: {
65
- params: { colors: colors.join("|") },
53
+ query: { colors: colors.join("|") },
66
54
  },
67
55
  response: {
68
56
  status: 204,
@@ -0,0 +1,48 @@
1
+ import "@typespec/http";
2
+ import "@typespec/spector";
3
+
4
+ using Http;
5
+ using Spector;
6
+
7
+ @doc("Test for path parameters cases.")
8
+ @scenarioService("/parameters/path")
9
+ namespace Parameters.Path;
10
+
11
+ @scenario
12
+ @scenarioDoc("""
13
+ Test case for normal path parameter.
14
+
15
+ Should generate an operation like below:
16
+ ```
17
+ normal(name: string)
18
+ ```
19
+
20
+ Expected request path:
21
+ ```
22
+ /normal/foo
23
+ ```
24
+ """)
25
+ @route("/normal/{name}")
26
+ op normal(@path name: string): NoContentResponse;
27
+
28
+ @scenario
29
+ @scenarioDoc("""
30
+ Test case for optional path parameter.
31
+
32
+ Should generate an operation like below:
33
+ ```
34
+ optional(name?: string)
35
+ ```
36
+
37
+ Expected two request:
38
+ First request path:
39
+ ```
40
+ /optional
41
+ ```
42
+ Second request path:
43
+ ```
44
+ /optional/foo
45
+ ```
46
+ """)
47
+ @route("/optional{/name}")
48
+ op optional(@path name?: string): NoContentResponse;
@@ -0,0 +1,34 @@
1
+ import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
2
+
3
+ export const Scenarios: Record<string, ScenarioMockApi> = {};
4
+
5
+ Scenarios.Parameters_Path_normal = passOnSuccess({
6
+ uri: "/parameters/path/normal/foo",
7
+ method: "get",
8
+
9
+ response: {
10
+ status: 204,
11
+ },
12
+ kind: "MockApiDefinition",
13
+ });
14
+
15
+ Scenarios.Parameters_Path_optional = passOnSuccess([
16
+ {
17
+ uri: "/parameters/path/optional",
18
+ method: "get",
19
+
20
+ response: {
21
+ status: 204,
22
+ },
23
+ kind: "MockApiDefinition",
24
+ },
25
+ {
26
+ uri: "/parameters/path/optional/foo",
27
+ method: "get",
28
+
29
+ response: {
30
+ status: 204,
31
+ },
32
+ kind: "MockApiDefinition",
33
+ },
34
+ ]);
@@ -0,0 +1,22 @@
1
+ import "@typespec/http";
2
+ import "@typespec/spector";
3
+
4
+ using Http;
5
+ using Spector;
6
+
7
+ @doc("Test for query parameter cases.")
8
+ @scenarioService("/parameters/query")
9
+ namespace Parameters.Query;
10
+
11
+ @doc("Constant query parameter verification")
12
+ @route("/constant")
13
+ interface Constant {
14
+ /** post constant query value */
15
+ @scenario
16
+ @scenarioDoc("Expect to handle a constant value for query and mock api returns nothing")
17
+ @post
18
+ post(
19
+ @query
20
+ queryParam: "constantValue",
21
+ ): void;
22
+ }
@@ -0,0 +1,15 @@
1
+ import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
2
+
3
+ export const Scenarios: Record<string, ScenarioMockApi> = {};
4
+
5
+ Scenarios.Parameters_Query_Constant_post = passOnSuccess({
6
+ uri: "/parameters/query/constant",
7
+ method: `post`,
8
+ request: {
9
+ query: { queryParam: "constantValue" },
10
+ },
11
+ response: {
12
+ status: 204,
13
+ },
14
+ kind: "MockApiDefinition",
15
+ });