@typespec/http-client-js 0.2.0-dev.1 → 0.2.0-dev.11

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 (252) hide show
  1. package/.github/copilot-instructions.md +193 -0
  2. package/README.md +31 -15
  3. package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -1
  4. package/dist/src/components/client-context/client-context-declaration.js.map +1 -1
  5. package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
  6. package/dist/src/components/client-context/client-context-factory.js +7 -4
  7. package/dist/src/components/client-context/client-context-factory.js.map +1 -1
  8. package/dist/src/components/client-context/client-context-options.d.ts.map +1 -1
  9. package/dist/src/components/client-context/client-context-options.js +13 -9
  10. package/dist/src/components/client-context/client-context-options.js.map +1 -1
  11. package/dist/src/components/client-context/client-context.d.ts.map +1 -1
  12. package/dist/src/components/client-context/client-context.js +7 -12
  13. package/dist/src/components/client-context/client-context.js.map +1 -1
  14. package/dist/src/components/client-context/parametrized-endpoint.d.ts +1 -1
  15. package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -1
  16. package/dist/src/components/client-context/parametrized-endpoint.js +22 -13
  17. package/dist/src/components/client-context/parametrized-endpoint.js.map +1 -1
  18. package/dist/src/components/client-directory.d.ts +2 -2
  19. package/dist/src/components/client-directory.d.ts.map +1 -1
  20. package/dist/src/components/client-directory.js +33 -21
  21. package/dist/src/components/client-directory.js.map +1 -1
  22. package/dist/src/components/client-operation.d.ts.map +1 -1
  23. package/dist/src/components/client-operation.js +6 -6
  24. package/dist/src/components/client-operation.js.map +1 -1
  25. package/dist/src/components/client.d.ts +1 -1
  26. package/dist/src/components/client.d.ts.map +1 -1
  27. package/dist/src/components/client.js +83 -64
  28. package/dist/src/components/client.js.map +1 -1
  29. package/dist/src/components/encoding-provider.d.ts.map +1 -1
  30. package/dist/src/components/encoding-provider.js +0 -1
  31. package/dist/src/components/encoding-provider.js.map +1 -1
  32. package/dist/src/components/http-request-options.d.ts.map +1 -1
  33. package/dist/src/components/http-request-options.js +3 -3
  34. package/dist/src/components/http-request-options.js.map +1 -1
  35. package/dist/src/components/http-request-parameters-expression.d.ts +1 -2
  36. package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
  37. package/dist/src/components/http-request-parameters-expression.js +37 -33
  38. package/dist/src/components/http-request-parameters-expression.js.map +1 -1
  39. package/dist/src/components/http-request.d.ts.map +1 -1
  40. package/dist/src/components/http-request.js +24 -20
  41. package/dist/src/components/http-request.js.map +1 -1
  42. package/dist/src/components/http-response.d.ts +1 -1
  43. package/dist/src/components/http-response.d.ts.map +1 -1
  44. package/dist/src/components/http-response.js +36 -33
  45. package/dist/src/components/http-response.js.map +1 -1
  46. package/dist/src/components/models.d.ts.map +1 -1
  47. package/dist/src/components/models.js +21 -18
  48. package/dist/src/components/models.js.map +1 -1
  49. package/dist/src/components/operation-options.d.ts.map +1 -1
  50. package/dist/src/components/operation-options.js +17 -14
  51. package/dist/src/components/operation-options.js.map +1 -1
  52. package/dist/src/components/output.js +0 -1
  53. package/dist/src/components/output.js.map +1 -1
  54. package/dist/src/components/serializers.d.ts.map +1 -1
  55. package/dist/src/components/serializers.js +21 -14
  56. package/dist/src/components/serializers.js.map +1 -1
  57. package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -1
  58. package/dist/src/components/static-helpers/bytes-encoding.js +2 -2
  59. package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -1
  60. package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -1
  61. package/dist/src/components/static-helpers/interfaces.js.map +1 -1
  62. package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -1
  63. package/dist/src/components/static-helpers/multipart-helpers.js +4 -4
  64. package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -1
  65. package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
  66. package/dist/src/components/static-helpers/rest-error.js +66 -57
  67. package/dist/src/components/static-helpers/rest-error.js.map +1 -1
  68. package/dist/src/components/testing/client-options.d.ts.map +1 -1
  69. package/dist/src/components/testing/client-options.js +0 -2
  70. package/dist/src/components/testing/client-options.js.map +1 -1
  71. package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -1
  72. package/dist/src/components/transforms/content-type-encoding-provider.js +0 -1
  73. package/dist/src/components/transforms/content-type-encoding-provider.js.map +1 -1
  74. package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
  75. package/dist/src/components/transforms/json/json-array-transform.js.map +1 -1
  76. package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -1
  77. package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +4 -4
  78. package/dist/src/components/transforms/json/json-model-additional-properties-transform.js.map +1 -1
  79. package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -1
  80. package/dist/src/components/transforms/json/json-model-base-transform.js.map +1 -1
  81. package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
  82. package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -1
  83. package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
  84. package/dist/src/components/transforms/json/json-model-transform.js +20 -17
  85. package/dist/src/components/transforms/json/json-model-transform.js.map +1 -1
  86. package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
  87. package/dist/src/components/transforms/json/json-record-transform.js.map +1 -1
  88. package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
  89. package/dist/src/components/transforms/json/json-transform-discriminator.js +5 -10
  90. package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -1
  91. package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
  92. package/dist/src/components/transforms/json/json-transform.js.map +1 -1
  93. package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
  94. package/dist/src/components/transforms/json/union-transform.js +2 -2
  95. package/dist/src/components/transforms/json/union-transform.js.map +1 -1
  96. package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -1
  97. package/dist/src/components/transforms/multipart/array-part-transform.js.map +1 -1
  98. package/dist/src/components/transforms/multipart/file-part-transform.js +1 -1
  99. package/dist/src/components/transforms/multipart/file-part-transform.js.map +1 -1
  100. package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
  101. package/dist/src/components/transforms/multipart/multipart-transform.js +9 -6
  102. package/dist/src/components/transforms/multipart/multipart-transform.js.map +1 -1
  103. package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
  104. package/dist/src/components/transforms/multipart/simple-part-transform.js +23 -13
  105. package/dist/src/components/transforms/multipart/simple-part-transform.js.map +1 -1
  106. package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
  107. package/dist/src/components/transforms/operation-transform-declaration.js +2 -2
  108. package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -1
  109. package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
  110. package/dist/src/components/transforms/operation-transform-expression.js.map +1 -1
  111. package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -1
  112. package/dist/src/components/utils/unpack-model-property.js +11 -2
  113. package/dist/src/components/utils/unpack-model-property.js.map +1 -1
  114. package/dist/src/components/utils/url-template.d.ts.map +1 -1
  115. package/dist/src/components/utils/url-template.js.map +1 -1
  116. package/dist/src/emitter.d.ts.map +1 -1
  117. package/dist/src/emitter.js +6 -6
  118. package/dist/src/emitter.js.map +1 -1
  119. package/dist/src/lib.d.ts.map +1 -1
  120. package/dist/src/lib.js +2 -1
  121. package/dist/src/lib.js.map +1 -1
  122. package/dist/src/utils/operations.d.ts +13 -1
  123. package/dist/src/utils/operations.d.ts.map +1 -1
  124. package/dist/src/utils/operations.js +71 -0
  125. package/dist/src/utils/operations.js.map +1 -1
  126. package/dist/src/utils/parameters.d.ts.map +1 -1
  127. package/dist/src/utils/parameters.js +1 -1
  128. package/dist/src/utils/parameters.js.map +1 -1
  129. package/dist/tsconfig.tsbuildinfo +1 -1
  130. package/eng/scripts/emit-e2e.js +1 -1
  131. package/package.json +16 -14
  132. package/src/components/client-context/client-context-declaration.tsx +8 -1
  133. package/src/components/client-context/client-context-factory.tsx +50 -30
  134. package/src/components/client-context/client-context-options.tsx +13 -6
  135. package/src/components/client-context/client-context.tsx +5 -3
  136. package/src/components/client-context/parametrized-endpoint.tsx +26 -15
  137. package/src/components/client-directory.tsx +26 -16
  138. package/src/components/client-operation.tsx +24 -12
  139. package/src/components/client.tsx +77 -39
  140. package/src/components/encoding-provider.tsx +1 -3
  141. package/src/components/http-request-options.tsx +24 -14
  142. package/src/components/http-request-parameters-expression.tsx +34 -37
  143. package/src/components/http-request.tsx +26 -16
  144. package/src/components/http-response.tsx +31 -26
  145. package/src/components/models.tsx +18 -14
  146. package/src/components/operation-options.tsx +18 -5
  147. package/src/components/output.tsx +9 -9
  148. package/src/components/serializers.tsx +21 -9
  149. package/src/components/static-helpers/bytes-encoding.tsx +26 -8
  150. package/src/components/static-helpers/interfaces.tsx +14 -9
  151. package/src/components/static-helpers/multipart-helpers.tsx +34 -13
  152. package/src/components/static-helpers/rest-error.tsx +56 -18
  153. package/src/components/testing/client-options.tsx +0 -3
  154. package/src/components/transforms/content-type-encoding-provider.tsx +1 -3
  155. package/src/components/transforms/json/json-array-transform.tsx +6 -4
  156. package/src/components/transforms/json/json-model-additional-properties-transform.tsx +18 -13
  157. package/src/components/transforms/json/json-model-base-transform.tsx +6 -1
  158. package/src/components/transforms/json/json-model-property-transform.tsx +7 -9
  159. package/src/components/transforms/json/json-model-transform.tsx +44 -16
  160. package/src/components/transforms/json/json-record-transform.tsx +5 -3
  161. package/src/components/transforms/json/json-transform-discriminator.tsx +17 -30
  162. package/src/components/transforms/json/json-transform.tsx +5 -3
  163. package/src/components/transforms/json/union-transform.tsx +20 -8
  164. package/src/components/transforms/multipart/array-part-transform.tsx +6 -3
  165. package/src/components/transforms/multipart/file-part-transform.tsx +1 -1
  166. package/src/components/transforms/multipart/multipart-transform.tsx +4 -6
  167. package/src/components/transforms/multipart/part-transform.tsx +1 -1
  168. package/src/components/transforms/multipart/simple-part-transform.tsx +16 -13
  169. package/src/components/transforms/operation-transform-declaration.tsx +24 -7
  170. package/src/components/transforms/operation-transform-expression.tsx +12 -5
  171. package/src/components/utils/unpack-model-property.ts +13 -2
  172. package/src/components/utils/url-template.tsx +10 -6
  173. package/src/emitter.tsx +4 -3
  174. package/src/lib.ts +6 -1
  175. package/src/utils/operations.ts +96 -1
  176. package/src/utils/parameters.tsx +5 -1
  177. package/test/e2e/http/payload/multipart/main.test.ts +20 -24
  178. package/test/e2e/http/type/property/additional-properties/spreads.test.ts +4 -1
  179. package/test/scenarios/additional-properties/extends.md +0 -4
  180. package/test/scenarios/additional-properties/is.md +0 -4
  181. package/test/scenarios/additional-properties/spread.md +0 -4
  182. package/test/scenarios/auth/basic_auth.md +1 -4
  183. package/test/scenarios/auth/bearer.md +1 -4
  184. package/test/scenarios/auth/client_parameters.md +1 -4
  185. package/test/scenarios/auth/client_structure.md +1 -3
  186. package/test/scenarios/auth/key_credential.md +1 -4
  187. package/test/scenarios/auth/sub_client_override.md +1 -5
  188. package/test/scenarios/client/client_context.md +1 -3
  189. package/test/scenarios/client/dotted_namespace.md +1 -4
  190. package/test/scenarios/client/global_namespace.md +0 -5
  191. package/test/scenarios/client/multiple_top_level_clients.md +0 -2
  192. package/test/scenarios/client/nested_client.md +1 -5
  193. package/test/scenarios/client/wrapping_namespace.md +1 -3
  194. package/test/scenarios/encoding/bytes_body.md +0 -4
  195. package/test/scenarios/encoding/bytes_json_property.md +0 -5
  196. package/test/scenarios/encoding/bytes_nullable.md +0 -14
  197. package/test/scenarios/encoding/header_bytes.md +0 -12
  198. package/test/scenarios/encoding/header_date.md +0 -20
  199. package/test/scenarios/encoding/model_with_bytes_property.md +0 -5
  200. package/test/scenarios/encoding/query_bytes.md +0 -4
  201. package/test/scenarios/encoding/query_date.md +0 -20
  202. package/test/scenarios/http-operations/basic-request.md +3 -21
  203. package/test/scenarios/http-operations/basic-response.md +4 -31
  204. package/test/scenarios/http-operations/basic.md +0 -6
  205. package/test/scenarios/http-operations/constant-header.md +0 -4
  206. package/test/scenarios/http-operations/create-operation.md +0 -4
  207. package/test/scenarios/http-operations/on_response.md +0 -4
  208. package/test/scenarios/http-operations/optional-request-body.md +0 -5
  209. package/test/scenarios/http-operations/path-parameter-in-model.md +1 -7
  210. package/test/scenarios/http-operations/path-parameter.md +1 -7
  211. package/test/scenarios/http-operations/scalar-payload.md +1 -7
  212. package/test/scenarios/http-operations/with-parameters.md +1 -8
  213. package/test/scenarios/models/inheritance_2_discriminators.md +0 -24
  214. package/test/scenarios/models/inheritance_discriminator.md +0 -4
  215. package/test/scenarios/models/inline-models.md +1 -4
  216. package/test/scenarios/models/model_additional_properties.md +0 -4
  217. package/test/scenarios/models/model_extends.md +0 -4
  218. package/test/scenarios/models/model_spread.md +0 -2
  219. package/test/scenarios/models/nested_property.md +0 -4
  220. package/test/scenarios/models/property_references_property.md +0 -6
  221. package/test/scenarios/multipart/anonymous_part.md +2 -11
  222. package/test/scenarios/multipart/file.md +0 -12
  223. package/test/scenarios/multipart/file_content_type.md +15 -5
  224. package/test/scenarios/multipart/non-string-float.md +50 -0
  225. package/test/scenarios/multipart/simple_part.md +0 -4
  226. package/test/scenarios/operation-parameters/body_root_anonymous.md +2 -17
  227. package/test/scenarios/operation-parameters/constant_as_optional.md +0 -5
  228. package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -5
  229. package/test/scenarios/operation-parameters/no_content_type.md +0 -5
  230. package/test/scenarios/operation-parameters/no_parameters.md +0 -5
  231. package/test/scenarios/operation-parameters/only_optional.md +0 -5
  232. package/test/scenarios/operation-parameters/only_required.md +0 -5
  233. package/test/scenarios/operation-parameters/reserved_names.md +0 -5
  234. package/test/scenarios/operation-parameters/spread_body.md +0 -5
  235. package/test/scenarios/operation-parameters/spread_with_nested.md +0 -5
  236. package/test/scenarios/operation-parameters/union_body.md +0 -6
  237. package/test/scenarios/operation-parameters/with_body_property.md +0 -5
  238. package/test/scenarios/operation-parameters/with_body_root.md +0 -5
  239. package/test/scenarios/serializers/arrays.md +0 -8
  240. package/test/scenarios/serializers/basic_model.md +0 -4
  241. package/test/scenarios/serializers/basic_model_wire_name.md +0 -2
  242. package/test/scenarios/serializers/discriminated_union.md +1 -1
  243. package/test/scenarios/serializers/discriminated_union_spread.md +1 -5
  244. package/test/scenarios/serializers/multipart.md +0 -4
  245. package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +1 -8
  246. package/test/scenarios/serializers/property_references_property.md +72 -0
  247. package/test/scenarios/serializers/record.md +0 -4
  248. package/test/scenarios/serializers/scalars.md +0 -5
  249. package/test/scenarios/serializers/spread.md +1 -7
  250. package/test/scenarios/serializers/string_union.md +1 -7
  251. package/test/scenarios/server/multiple-parameters.md +1 -3
  252. package/test/scenarios/server/parametrized-endpoint.md +1 -3
package/src/lib.ts CHANGED
@@ -8,7 +8,12 @@ const EmitterOptionsSchema: JSONSchemaType<JsClientEmitterOptions> = {
8
8
  type: "object",
9
9
  additionalProperties: true,
10
10
  properties: {
11
- "package-name": { type: "string", nullable: true, default: "test-package" },
11
+ "package-name": {
12
+ type: "string",
13
+ nullable: true,
14
+ default: "test-package",
15
+ description: "Name of the package as it will be in package.json",
16
+ },
12
17
  },
13
18
  required: [],
14
19
  };
@@ -1,6 +1,101 @@
1
- import { ModelProperty } from "@typespec/compiler";
1
+ import { Model, ModelProperty, Operation, Union } from "@typespec/compiler";
2
+ import {
3
+ unsafe_mutateSubgraph as mutateSubgraph,
4
+ unsafe_Mutator as Mutator,
5
+ unsafe_MutatorFlow as MutatorFlow,
6
+ unsafe_MutatorRecord,
7
+ } from "@typespec/compiler/experimental";
2
8
  import { $ } from "@typespec/compiler/experimental/typekit";
3
9
 
10
+ /**
11
+ * Prepares operation for client representation. This includes adding an options bag for optional parameters.
12
+ * @param operation operation to be prepared
13
+ * @returns the prepared operation
14
+ */
15
+ export function prepareOperation(operation: Operation): Operation {
16
+ return mutateSubgraph($.program, [httpParamsMutator], operation).type as Operation;
17
+ }
18
+
19
+ /**
20
+ * Mutates anonymous types to be named.
21
+ */
22
+ const anonymousMutatorRecord: unsafe_MutatorRecord<Model | Union> = {
23
+ filter(t) {
24
+ return MutatorFlow.MutateAndRecur;
25
+ },
26
+ mutate(t, clone) {
27
+ if (!clone.name) {
28
+ clone.name = $.type.getPlausibleName(clone);
29
+ }
30
+ },
31
+ };
32
+
33
+ export const anonymousMutator: Mutator = {
34
+ name: "Anonymous types",
35
+ Model: anonymousMutatorRecord,
36
+ Union: anonymousMutatorRecord,
37
+ };
38
+
39
+ /**
40
+ * Mutates the operation so that the parameters model is split into required and optional parameters.
41
+ */
42
+ export const httpParamsMutator: Mutator = {
43
+ name: "Http parameters",
44
+ Operation: {
45
+ filter() {
46
+ return MutatorFlow.DoNotRecur;
47
+ },
48
+ mutate(o, clone, _program, realm) {
49
+ const httpOperation = $.httpOperation.get(o);
50
+ const returnType = $.httpOperation.getReturnType(httpOperation);
51
+ clone.returnType = returnType;
52
+ const params = $.httpRequest.getParameters(httpOperation, [
53
+ "query",
54
+ "header",
55
+ "path",
56
+ "body",
57
+ "contentType",
58
+ ]);
59
+
60
+ if (!params) {
61
+ return;
62
+ }
63
+
64
+ clone.parameters = params;
65
+
66
+ const optionals = [...clone.parameters.properties.values()]
67
+ .filter((p) => p.optional)
68
+ .reduce(
69
+ (acc, prop) => {
70
+ acc[prop.name] = prop;
71
+ return acc;
72
+ },
73
+ {} as Record<string, ModelProperty>,
74
+ );
75
+
76
+ const optionsBag = $.model.create({
77
+ properties: optionals,
78
+ });
79
+
80
+ const optionsProp = $.modelProperty.create({
81
+ name: "options",
82
+ type: optionsBag,
83
+ optional: true,
84
+ });
85
+
86
+ for (const [key, prop] of clone.parameters.properties) {
87
+ if (prop.optional || isConstantHeader(prop)) {
88
+ clone.parameters.properties.delete(key);
89
+ }
90
+ }
91
+
92
+ if (Object.keys(optionals).length > 0) {
93
+ clone.parameters.properties.set("options", optionsProp);
94
+ }
95
+ },
96
+ },
97
+ };
98
+
4
99
  export function isConstantHeader(modelProperty: ModelProperty) {
5
100
  if (!$.modelProperty.isHttpHeader(modelProperty)) {
6
101
  return false;
@@ -57,7 +57,11 @@ function buildClientParameterDescriptor(
57
57
  {
58
58
  refkey: ay.refkey(modelProperty),
59
59
  optional: modelProperty.optional,
60
- type: ay.mapJoin(credentialType, (t) => t, { joiner: " | " }),
60
+ type: ay.mapJoin(
61
+ () => credentialType,
62
+ (t) => t,
63
+ { joiner: " | " },
64
+ ),
61
65
  },
62
66
  ];
63
67
  }
@@ -4,30 +4,26 @@ import { fileURLToPath } from "url";
4
4
  import { beforeEach, describe, it } from "vitest";
5
5
  import { FormDataClient, HttpPartsClient } from "../../../generated/payload/multipart/src/index.js";
6
6
 
7
- describe("Payload.MultiPart", () => {
8
- let __filename;
9
- let __dirname;
10
- let jpegContents: Uint8Array;
11
- let pngContents: Uint8Array;
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+
10
+ const jpegImagePath = resolve(__dirname, "../../../assets/image.jpg");
11
+ const jpegBuffer = await readFile(jpegImagePath);
12
+ const jpegContents = new Uint8Array(jpegBuffer);
13
+
14
+ const pngImagePath = resolve(__dirname, "../../../assets/image.png");
15
+ const pngBuffer = await readFile(pngImagePath);
16
+ const pngContents = new Uint8Array(pngBuffer);
12
17
 
18
+ describe("Payload.MultiPart", () => {
19
+ // Skipping as implicit multipart is going to be deprecated in TypeSpec
13
20
  describe.skip("FormDataClient", () => {
14
21
  const client = new FormDataClient({
15
22
  allowInsecureConnection: true,
16
23
  retryOptions: { maxRetries: 1 },
17
24
  });
18
25
 
19
- beforeEach(async () => {
20
- __filename = fileURLToPath(import.meta.url);
21
- __dirname = dirname(__filename);
22
-
23
- const jpegImagePath = resolve(__dirname, "../../../assets/image.jpg");
24
- const jpegBuffer = await readFile(jpegImagePath);
25
- jpegContents = new Uint8Array(jpegBuffer);
26
-
27
- const pngImagePath = resolve(__dirname, "../../../assets/image.png");
28
- const pngBuffer = await readFile(pngImagePath);
29
- pngContents = new Uint8Array(pngBuffer);
30
- });
26
+ beforeEach(async () => {});
31
27
 
32
28
  it("should send mixed parts with multipart/form-data", async () => {
33
29
  await client.basic({
@@ -82,7 +78,7 @@ describe("Payload.MultiPart", () => {
82
78
  });
83
79
  });
84
80
 
85
- describe.skip("FormDataClient.HttpParts.ContentType", () => {
81
+ describe("FormDataClient.HttpParts.ContentType", () => {
86
82
  const client = new HttpPartsClient({
87
83
  allowInsecureConnection: true,
88
84
  retryOptions: { maxRetries: 1 },
@@ -93,7 +89,7 @@ describe("Payload.MultiPart", () => {
93
89
  profileImage: {
94
90
  contents: jpegContents,
95
91
  contentType: "image/jpg",
96
- filename: "image.jpg",
92
+ filename: "hello.jpg",
97
93
  },
98
94
  });
99
95
  });
@@ -102,8 +98,8 @@ describe("Payload.MultiPart", () => {
102
98
  await client.contentTypeClient.requiredContentType({
103
99
  profileImage: {
104
100
  contents: jpegContents,
105
- contentType: "image/jpg",
106
- filename: "image.jpg",
101
+ contentType: "application/octet-stream",
102
+ filename: "hello.jpg",
107
103
  },
108
104
  });
109
105
  });
@@ -112,14 +108,14 @@ describe("Payload.MultiPart", () => {
112
108
  await client.contentTypeClient.optionalContentType({
113
109
  profileImage: {
114
110
  contents: jpegContents,
115
- filename: "image.jpg",
111
+ filename: "hello.jpg",
116
112
  },
117
113
  });
118
114
  });
119
115
  });
120
116
 
121
117
  describe("FormDataClient.HttpParts", () => {
122
- it.skip("should send json array and file array", async () => {
118
+ it("should send json array and file array", async () => {
123
119
  const client = new HttpPartsClient({
124
120
  allowInsecureConnection: true,
125
121
  retryOptions: {
@@ -146,7 +142,7 @@ describe("Payload.MultiPart", () => {
146
142
  });
147
143
 
148
144
  describe("FormDataClient.HttpParts.NonString", () => {
149
- it.skip("should handle non-string float", async () => {
145
+ it("should handle non-string float", async () => {
150
146
  const client = new HttpPartsClient({
151
147
  allowInsecureConnection: true,
152
148
  retryOptions: {
@@ -377,7 +377,10 @@ describe("Missing AdditionalProperties Endpoints", () => {
377
377
  });
378
378
  });
379
379
 
380
- describe("SpreadRecordDiscriminatedUnion", () => {
380
+ /**
381
+ * Deprecated @discriminator in unions
382
+ */
383
+ describe.skip("SpreadRecordDiscriminatedUnion", () => {
381
384
  const client = new SpreadRecordDiscriminatedUnionClient(clientOptions);
382
385
  const expected: SpreadRecordForDiscriminatedUnion = {
383
386
  name: "abc",
@@ -37,10 +37,8 @@ export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
37
37
  if (!input_) {
38
38
  return input_ as any;
39
39
  }
40
-
41
40
  return {
42
41
  ...jsonRecordUnknownToTransportTransform(input_.additionalProperties),
43
-
44
42
  name: input_.name,
45
43
  age: input_.age,
46
44
  optional: input_.optional,
@@ -57,12 +55,10 @@ export function jsonWidgetToApplicationTransform(input_?: any): Widget {
57
55
  if (!input_) {
58
56
  return input_ as any;
59
57
  }
60
-
61
58
  return {
62
59
  additionalProperties: jsonRecordUnknownToApplicationTransform(
63
60
  (({ name, age, optional, ...rest }) => rest)(input_),
64
61
  ),
65
-
66
62
  name: input_.name,
67
63
  age: input_.age,
68
64
  optional: input_.optional,
@@ -26,21 +26,17 @@ export async function foo(
26
26
  options?: FooOptions,
27
27
  ): Promise<Record<string, string>> {
28
28
  const path = parse("/").expand({});
29
-
30
29
  const httpRequestOptions = {
31
30
  headers: {},
32
31
  };
33
-
34
32
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
35
33
 
36
34
  if (typeof options?.operationOptions?.onResponse === "function") {
37
35
  options?.operationOptions?.onResponse(response);
38
36
  }
39
-
40
37
  if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
41
38
  return jsonRecordStringToApplicationTransform(response.body)!;
42
39
  }
43
-
44
40
  throw createRestError(response);
45
41
  }
46
42
  ```
@@ -38,10 +38,8 @@ export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
38
38
  if (!input_) {
39
39
  return input_ as any;
40
40
  }
41
-
42
41
  return {
43
42
  ...jsonRecordStringToTransportTransform(input_.additionalProperties),
44
-
45
43
  name: input_.name,
46
44
  age: input_.age,
47
45
  optional: input_.optional,
@@ -58,12 +56,10 @@ export function jsonWidgetToApplicationTransform(input_?: any): Widget {
58
56
  if (!input_) {
59
57
  return input_ as any;
60
58
  }
61
-
62
59
  return {
63
60
  additionalProperties: jsonRecordStringToApplicationTransform(
64
61
  (({ name, age, optional, ...rest }) => rest)(input_),
65
62
  ),
66
-
67
63
  name: input_.name,
68
64
  age: input_.age,
69
65
  optional: input_.optional,
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a basic authentication scheme co
7
7
  The spec contains a simple service with a Bearer authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BasicAuth)
14
12
  namespace Test;
15
13
 
@@ -27,7 +25,6 @@ The client signature should include a positional parameter for credential of typ
27
25
  ```ts src/testClient.ts class TestClient
28
26
  export class TestClient {
29
27
  #context: TestClientContext;
30
-
31
28
  constructor(endpoint: string, credential: KeyCredential, options?: TestClientOptions) {
32
29
  this.#context = createTestClientContext(endpoint, credential, options);
33
30
  }
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a simple bearer authentication s
7
7
  The spec contains a simple service with a Bearer authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BearerAuth)
14
12
  namespace Test;
15
13
 
@@ -27,7 +25,6 @@ The client signature should include a positional parameter for credential of typ
27
25
  ```ts src/testClient.ts class TestClient
28
26
  export class TestClient {
29
27
  #context: TestClientContext;
30
-
31
28
  constructor(endpoint: string, credential: KeyCredential, options?: TestClientOptions) {
32
29
  this.#context = createTestClientContext(endpoint, credential, options);
33
30
  }
@@ -7,9 +7,7 @@ This test validates that the emitter can generate the correct client signature w
7
7
  The spec contains 2 Schemas Bearer and ApiKey
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BearerAuth | ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
14
12
  namespace Test;
15
13
 
@@ -28,7 +26,6 @@ TODO: Revisit if we need additional types since it will be difficult at runtime
28
26
  ```ts src/testClient.ts class TestClient
29
27
  export class TestClient {
30
28
  #context: TestClientContext;
31
-
32
29
  constructor(endpoint: string, credential: KeyCredential, options?: TestClientOptions) {
33
30
  this.#context = createTestClientContext(endpoint, credential, options);
34
31
  }
@@ -3,9 +3,7 @@
3
3
  ## TypeSpec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "My API",
8
- })
6
+ @service(#{ title: "My API" })
9
7
  @useAuth(BearerAuth)
10
8
  namespace MyApi;
11
9
 
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a key auth scheme correctly with
7
7
  The spec contains a simple service with a ApiKey authentication scheme
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
14
12
  namespace Test;
15
13
 
@@ -27,7 +25,6 @@ The client signature should include a positional parameter for credential of typ
27
25
  ```ts src/testClient.ts class TestClient
28
26
  export class TestClient {
29
27
  #context: TestClientContext;
30
-
31
28
  constructor(endpoint: string, credential: KeyCredential, options?: TestClientOptions) {
32
29
  this.#context = createTestClientContext(endpoint, credential, options);
33
30
  }
@@ -7,9 +7,7 @@ The sub client sets NoAuth to override the auth scheme of the parent
7
7
  The spec contains a client with BasicAuth and a sub client with no auth
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Test Service",
12
- })
10
+ @service(#{ title: "Test Service" })
13
11
  @useAuth(BasicAuth)
14
12
  namespace Test;
15
13
 
@@ -36,7 +34,6 @@ The subclient is not a child of the TestClient because they have different param
36
34
  ```ts src/testClient.ts class TestClient
37
35
  export class TestClient {
38
36
  #context: TestClientContext;
39
-
40
37
  constructor(endpoint: string, credential: KeyCredential, options?: TestClientOptions) {
41
38
  this.#context = createTestClientContext(endpoint, credential, options);
42
39
  }
@@ -51,7 +48,6 @@ The sub client shouldn't take a credential
51
48
  ```ts src/testClient.ts class SubClient
52
49
  export class SubClient {
53
50
  #context: SubClientContext;
54
-
55
51
  constructor(endpoint: string, options?: SubClientOptions) {
56
52
  this.#context = createSubClientContext(endpoint, options);
57
53
  }
@@ -3,9 +3,7 @@
3
3
  ## TypeSpec
4
4
 
5
5
  ```tsp
6
- @service({
7
- title: "Widget Service",
8
- })
6
+ @service(#{ title: "Widget Service" })
9
7
  namespace DemoService;
10
8
  op foo(): void;
11
9
  ```
@@ -5,9 +5,7 @@
5
5
  A dotted namespace where only the last part has content. The leading namespaces have no operations and a single sub namespace
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "TestService",
10
- })
8
+ @service(#{ title: "TestService" })
11
9
  namespace Foo.Bar.Baz;
12
10
  @get op get(): string[];
13
11
  ```
@@ -19,7 +17,6 @@ The client should match the last namespace.
19
17
  ```ts src/bazClient.ts class BazClient
20
18
  export class BazClient {
21
19
  #context: BazClientContext;
22
-
23
20
  constructor(endpoint: string, options?: BazClientOptions) {
24
21
  this.#context = createBazClientContext(endpoint, options);
25
22
  }
@@ -39,7 +39,6 @@ It should generate a client for the Global Namespace with a single operation `fo
39
39
  ```ts src/client.ts class Client
40
40
  export class Client {
41
41
  #context: ClientContext;
42
-
43
42
  constructor(endpoint: string, options?: ClientOptions) {
44
43
  this.#context = createClientContext(endpoint, options);
45
44
  }
@@ -54,21 +53,17 @@ It should generate an operation for foo
54
53
  ```ts src/api/clientOperations.ts function foo
55
54
  export async function foo(client: ClientContext, options?: FooOptions): Promise<void> {
56
55
  const path = parse("/").expand({});
57
-
58
56
  const httpRequestOptions = {
59
57
  headers: {},
60
58
  };
61
-
62
59
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
63
60
 
64
61
  if (typeof options?.operationOptions?.onResponse === "function") {
65
62
  options?.operationOptions?.onResponse(response);
66
63
  }
67
-
68
64
  if (+response.status === 204 && !response.body) {
69
65
  return;
70
66
  }
71
-
72
67
  throw createRestError(response);
73
68
  }
74
69
  ```
@@ -37,7 +37,6 @@ import {
37
37
 
38
38
  export class FooClient {
39
39
  #context: FooClientContext;
40
-
41
40
  constructor(endpoint: string, options?: FooClientOptions) {
42
41
  this.#context = createFooClientContext(endpoint, options);
43
42
  }
@@ -60,7 +59,6 @@ import {
60
59
 
61
60
  export class BarClient {
62
61
  #context: BarClientContext;
63
-
64
62
  constructor(endpoint: string, options?: BarClientOptions) {
65
63
  this.#context = createBarClientContext(endpoint, options);
66
64
  }
@@ -5,9 +5,7 @@ This specs nests namespace > namespace > interface
5
5
  ## TypeSpec
6
6
 
7
7
  ```tsp
8
- @service({
9
- title: "Widget Service",
10
- })
8
+ @service(#{ title: "Widget Service" })
11
9
  namespace DemoService;
12
10
 
13
11
  model Widget {
@@ -77,10 +75,8 @@ export class DemoServiceClient {
77
75
  this.widgetsClient = new WidgetsClient(endpoint, options);
78
76
  }
79
77
  }
80
-
81
78
  export class WidgetsClient {
82
79
  #context: WidgetsClientContext;
83
-
84
80
  constructor(endpoint: string, options?: WidgetsClientOptions) {
85
81
  this.#context = createWidgetsClientContext(endpoint, options);
86
82
  }
@@ -9,9 +9,7 @@ In this scenario the emitter is expected to resolve the root namespace as a clie
9
9
  A dotted namespace where only the last part has stuff
10
10
 
11
11
  ```tsp
12
- @service({
13
- title: "TestService",
14
- })
12
+ @service(#{ title: "TestService" })
15
13
  namespace Foo;
16
14
 
17
15
  @route("/bar")
@@ -22,27 +22,23 @@ export async function foo(
22
22
  options?: FooOptions,
23
23
  ): Promise<Uint8Array> {
24
24
  const path = parse("/default").expand({});
25
-
26
25
  const httpRequestOptions = {
27
26
  headers: {
28
27
  "content-type": options?.contentType ?? "application/octet-stream",
29
28
  },
30
29
  body: value,
31
30
  };
32
-
33
31
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
34
32
 
35
33
  if (typeof options?.operationOptions?.onResponse === "function") {
36
34
  options?.operationOptions?.onResponse(response);
37
35
  }
38
-
39
36
  if (
40
37
  +response.status === 200 &&
41
38
  response.headers["content-type"]?.includes("application/octet-stream")
42
39
  ) {
43
40
  return response.body!;
44
41
  }
45
-
46
42
  throw createRestError(response);
47
43
  }
48
44
  ```
@@ -23,24 +23,20 @@ export async function foo(
23
23
  options?: FooOptions,
24
24
  ): Promise<BytesBody> {
25
25
  const path = parse("/default").expand({});
26
-
27
26
  const httpRequestOptions = {
28
27
  headers: {},
29
28
  body: {
30
29
  value: encodeUint8Array(value, "base64")!,
31
30
  },
32
31
  };
33
-
34
32
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
35
33
 
36
34
  if (typeof options?.operationOptions?.onResponse === "function") {
37
35
  options?.operationOptions?.onResponse(response);
38
36
  }
39
-
40
37
  if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
41
38
  return jsonBytesBodyToApplicationTransform(response.body)!;
42
39
  }
43
-
44
40
  throw createRestError(response);
45
41
  }
46
42
  ```
@@ -52,7 +48,6 @@ export function jsonBytesBodyToApplicationTransform(input_?: any): BytesBody {
52
48
  if (!input_) {
53
49
  return input_ as any;
54
50
  }
55
-
56
51
  return {
57
52
  value: decodeBase64(input_.value)!,
58
53
  }!;