@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
@@ -32,7 +32,6 @@ import {
32
32
 
33
33
  export class TestClient {
34
34
  #context: TestClientContext;
35
-
36
35
  constructor(endpoint: string, options?: TestClientOptions) {
37
36
  this.#context = createTestClientContext(endpoint, options);
38
37
  }
@@ -63,7 +62,6 @@ export function jsonWidgetToTransportTransform(input_?: Widget | null): any {
63
62
  if (!input_) {
64
63
  return input_ as any;
65
64
  }
66
-
67
65
  return {
68
66
  id: input_.id,
69
67
  total_weight: input_.totalWeight,
@@ -114,21 +112,17 @@ A function named `foo` is generated to handle the HTTP request. It prepares the
114
112
  ```ts src/api/testClientOperations.ts function foo
115
113
  export async function foo(client: TestClientContext, options?: FooOptions): Promise<Widget> {
116
114
  const path = parse("/").expand({});
117
-
118
115
  const httpRequestOptions = {
119
116
  headers: {},
120
117
  };
121
-
122
118
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
123
119
 
124
120
  if (typeof options?.operationOptions?.onResponse === "function") {
125
121
  options?.operationOptions?.onResponse(response);
126
122
  }
127
-
128
123
  if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
129
124
  return jsonWidgetToApplicationTransform(response.body)!;
130
125
  }
131
-
132
126
  throw createRestError(response);
133
127
  }
134
128
  ```
@@ -15,23 +15,19 @@ model Foo {
15
15
  ```ts src/api/testClientOperations.ts function foo
16
16
  export async function foo(client: TestClientContext, options?: FooOptions): Promise<Foo> {
17
17
  const path = parse("/").expand({});
18
-
19
18
  const httpRequestOptions = {
20
19
  headers: {
21
20
  accept: options?.accept ?? "application/xml",
22
21
  },
23
22
  };
24
-
25
23
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
26
24
 
27
25
  if (typeof options?.operationOptions?.onResponse === "function") {
28
26
  options?.operationOptions?.onResponse(response);
29
27
  }
30
-
31
28
  if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
32
29
  return jsonFooToApplicationTransform(response.body)!;
33
30
  }
34
-
35
31
  throw createRestError(response);
36
32
  }
37
33
  ```
@@ -36,7 +36,6 @@ export async function foo(
36
36
  options?: FooOptions,
37
37
  ): Promise<void> {
38
38
  const path = parse("/").expand({});
39
-
40
39
  const httpRequestOptions = {
41
40
  headers: {},
42
41
  body: {
@@ -46,17 +45,14 @@ export async function foo(
46
45
  is_required: options?.isRequired,
47
46
  },
48
47
  };
49
-
50
48
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
51
49
 
52
50
  if (typeof options?.operationOptions?.onResponse === "function") {
53
51
  options?.operationOptions?.onResponse(response);
54
52
  }
55
-
56
53
  if (+response.status === 204 && !response.body) {
57
54
  return;
58
55
  }
59
-
60
56
  throw createRestError(response);
61
57
  }
62
58
  ```
@@ -30,7 +30,6 @@ export async function foo(
30
30
  options?: FooOptions,
31
31
  ): Promise<void> {
32
32
  const path = parse("/").expand({});
33
-
34
33
  const httpRequestOptions = {
35
34
  headers: {},
36
35
  body: {
@@ -40,17 +39,14 @@ export async function foo(
40
39
  is_required: options?.isRequired,
41
40
  },
42
41
  };
43
-
44
42
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
45
43
 
46
44
  if (typeof options?.operationOptions?.onResponse === "function") {
47
45
  options?.operationOptions?.onResponse(response);
48
46
  }
49
-
50
47
  if (+response.status === 204 && !response.body) {
51
48
  return;
52
49
  }
53
-
54
50
  throw createRestError(response);
55
51
  }
56
52
  ```
@@ -20,22 +20,18 @@ op omit(@body body?: BodyModel): NoContentResponse;
20
20
  ```ts src/api/testClientOperations.ts function set
21
21
  export async function set(client: TestClientContext, options?: SetOptions): Promise<void> {
22
22
  const path = parse("/set").expand({});
23
-
24
23
  const httpRequestOptions = {
25
24
  headers: {},
26
25
  body: jsonBodyModelToTransportTransform(options?.body),
27
26
  };
28
-
29
27
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
30
28
 
31
29
  if (typeof options?.operationOptions?.onResponse === "function") {
32
30
  options?.operationOptions?.onResponse(response);
33
31
  }
34
-
35
32
  if (+response.status === 204 && !response.body) {
36
33
  return;
37
34
  }
38
-
39
35
  throw createRestError(response);
40
36
  }
41
37
  ```
@@ -47,7 +43,6 @@ export function jsonBodyModelToTransportTransform(input_?: BodyModel | null): an
47
43
  if (!input_) {
48
44
  return input_ as any;
49
45
  }
50
-
51
46
  return {
52
47
  name: input_.name,
53
48
  }!;
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter as a property of the input
7
7
  The path parameter is a property of a spread model input in the operation signature
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  model ReadParams {
@@ -39,21 +37,17 @@ export async function read(
39
37
  const path = parse("/widgets/{id}").expand({
40
38
  id: id,
41
39
  });
42
-
43
40
  const httpRequestOptions = {
44
41
  headers: {},
45
42
  };
46
-
47
43
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
48
44
 
49
45
  if (typeof options?.operationOptions?.onResponse === "function") {
50
46
  options?.operationOptions?.onResponse(response);
51
47
  }
52
-
53
48
  if (+response.status === 204 && !response.body) {
54
49
  return;
55
50
  }
56
-
57
51
  throw createRestError(response);
58
52
  }
59
53
  ```
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter directly on the operation s
7
7
  The path parameter is a positional parameter in the operation signature
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  @route("/widgets")
@@ -34,21 +32,17 @@ export async function read(
34
32
  const path = parse("/widgets/{id}").expand({
35
33
  id: id,
36
34
  });
37
-
38
35
  const httpRequestOptions = {
39
36
  headers: {},
40
37
  };
41
-
42
38
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
43
39
 
44
40
  if (typeof options?.operationOptions?.onResponse === "function") {
45
41
  options?.operationOptions?.onResponse(response);
46
42
  }
47
-
48
43
  if (+response.status === 204 && !response.body) {
49
44
  return;
50
45
  }
51
-
52
46
  throw createRestError(response);
53
47
  }
54
48
  ```
@@ -7,9 +7,7 @@ A request that sends a body payload of scalar type
7
7
  The body is modeled as an explicit body property of type int32
8
8
 
9
9
  ```tsp
10
- @service({
11
- title: "Widget Service",
12
- })
10
+ @service(#{ title: "Widget Service" })
13
11
  namespace DemoService;
14
12
 
15
13
  @route("/widgets")
@@ -32,22 +30,18 @@ export async function create(
32
30
  options?: CreateOptions,
33
31
  ): Promise<void> {
34
32
  const path = parse("/widgets").expand({});
35
-
36
33
  const httpRequestOptions = {
37
34
  headers: {},
38
35
  body: count,
39
36
  };
40
-
41
37
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
42
38
 
43
39
  if (typeof options?.operationOptions?.onResponse === "function") {
44
40
  options?.operationOptions?.onResponse(response);
45
41
  }
46
-
47
42
  if (+response.status === 204 && !response.body) {
48
43
  return;
49
44
  }
50
-
51
45
  throw createRestError(response);
52
46
  }
53
47
  ```
@@ -5,9 +5,7 @@ A typical request with path, query header and body parameters. The body is model
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
  @test
@@ -43,7 +41,6 @@ export async function read(
43
41
  id: id,
44
42
  foo: foo,
45
43
  });
46
-
47
44
  const httpRequestOptions = {
48
45
  headers: {
49
46
  etag: etag,
@@ -52,17 +49,14 @@ export async function read(
52
49
  name: name,
53
50
  },
54
51
  };
55
-
56
52
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
57
53
 
58
54
  if (typeof options?.operationOptions?.onResponse === "function") {
59
55
  options?.operationOptions?.onResponse(response);
60
56
  }
61
-
62
57
  if (+response.status === 204 && !response.body) {
63
58
  return;
64
59
  }
65
-
66
60
  throw createRestError(response);
67
61
  }
68
62
  ```
@@ -74,7 +68,6 @@ It should generate the client class with the read operation that calls the opera
74
68
  ```ts src/demoServiceClient.ts class WidgetsClient
75
69
  export class WidgetsClient {
76
70
  #context: WidgetsClientContext;
77
-
78
71
  constructor(endpoint: string, options?: WidgetsClientOptions) {
79
72
  this.#context = createWidgetsClientContext(endpoint, options);
80
73
  }
@@ -42,21 +42,17 @@ export async function getModel(
42
42
  options?: GetModelOptions,
43
43
  ): Promise<Fish> {
44
44
  const path = parse("/").expand({});
45
-
46
45
  const httpRequestOptions = {
47
46
  headers: {},
48
47
  };
49
-
50
48
  const response = await client.pathUnchecked(path).get(httpRequestOptions);
51
49
 
52
50
  if (typeof options?.operationOptions?.onResponse === "function") {
53
51
  options?.operationOptions?.onResponse(response);
54
52
  }
55
-
56
53
  if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
57
54
  return jsonFishToApplicationTransform(response.body)!;
58
55
  }
59
-
60
56
  throw createRestError(response);
61
57
  }
62
58
  ```
@@ -127,7 +123,6 @@ export function dateUnixTimestampDeserializer(date?: number | null): Date {
127
123
 
128
124
  return new Date(date * 1000);
129
125
  }
130
-
131
126
  export function jsonFishToTransportDiscriminator(input_?: Fish): any {
132
127
  if (!input_) {
133
128
  return input_ as any;
@@ -147,14 +142,12 @@ export function jsonFishToTransportTransform(input_?: Fish | null): any {
147
142
  if (!input_) {
148
143
  return input_ as any;
149
144
  }
150
-
151
145
  return {
152
146
  ...jsonFishToTransportDiscriminator(input_),
153
147
  age: input_.age,
154
148
  kind: input_.kind,
155
149
  }!;
156
150
  }
157
-
158
151
  export function jsonFishToApplicationDiscriminator(input_?: any): Fish {
159
152
  if (!input_) {
160
153
  return input_ as any;
@@ -174,14 +167,12 @@ export function jsonFishToApplicationTransform(input_?: any): Fish {
174
167
  if (!input_) {
175
168
  return input_ as any;
176
169
  }
177
-
178
170
  return {
179
171
  ...jsonFishToApplicationDiscriminator(input_),
180
172
  age: input_.age,
181
173
  kind: input_.kind,
182
174
  }!;
183
175
  }
184
-
185
176
  export function jsonSharkToTransportDiscriminator(input_?: Shark): any {
186
177
  if (!input_) {
187
178
  return input_ as any;
@@ -201,7 +192,6 @@ export function jsonSharkToTransportTransform(input_?: Shark | null): any {
201
192
  if (!input_) {
202
193
  return input_ as any;
203
194
  }
204
-
205
195
  return {
206
196
  ...jsonSharkToTransportDiscriminator(input_),
207
197
  kind: input_.kind,
@@ -209,7 +199,6 @@ export function jsonSharkToTransportTransform(input_?: Shark | null): any {
209
199
  age: input_.age,
210
200
  }!;
211
201
  }
212
-
213
202
  export function jsonSharkToApplicationDiscriminator(input_?: any): Shark {
214
203
  if (!input_) {
215
204
  return input_ as any;
@@ -229,7 +218,6 @@ export function jsonSharkToApplicationTransform(input_?: any): Shark {
229
218
  if (!input_) {
230
219
  return input_ as any;
231
220
  }
232
-
233
221
  return {
234
222
  ...jsonSharkToApplicationDiscriminator(input_),
235
223
  kind: input_.kind,
@@ -237,60 +225,50 @@ export function jsonSharkToApplicationTransform(input_?: any): Shark {
237
225
  age: input_.age,
238
226
  }!;
239
227
  }
240
-
241
228
  export function jsonSawSharkToTransportTransform(input_?: SawShark | null): any {
242
229
  if (!input_) {
243
230
  return input_ as any;
244
231
  }
245
-
246
232
  return {
247
233
  sharktype: input_.sharktype,
248
234
  kind: input_.kind,
249
235
  age: input_.age,
250
236
  }!;
251
237
  }
252
-
253
238
  export function jsonSawSharkToApplicationTransform(input_?: any): SawShark {
254
239
  if (!input_) {
255
240
  return input_ as any;
256
241
  }
257
-
258
242
  return {
259
243
  sharktype: input_.sharktype,
260
244
  kind: input_.kind,
261
245
  age: input_.age,
262
246
  }!;
263
247
  }
264
-
265
248
  export function jsonGoblinSharkToTransportTransform(input_?: GoblinShark | null): any {
266
249
  if (!input_) {
267
250
  return input_ as any;
268
251
  }
269
-
270
252
  return {
271
253
  sharktype: input_.sharktype,
272
254
  kind: input_.kind,
273
255
  age: input_.age,
274
256
  }!;
275
257
  }
276
-
277
258
  export function jsonGoblinSharkToApplicationTransform(input_?: any): GoblinShark {
278
259
  if (!input_) {
279
260
  return input_ as any;
280
261
  }
281
-
282
262
  return {
283
263
  sharktype: input_.sharktype,
284
264
  kind: input_.kind,
285
265
  age: input_.age,
286
266
  }!;
287
267
  }
288
-
289
268
  export function jsonSalmonToTransportTransform(input_?: Salmon | null): any {
290
269
  if (!input_) {
291
270
  return input_ as any;
292
271
  }
293
-
294
272
  return {
295
273
  kind: input_.kind,
296
274
  friends: jsonArrayFishToTransportTransform(input_.friends),
@@ -299,12 +277,10 @@ export function jsonSalmonToTransportTransform(input_?: Salmon | null): any {
299
277
  age: input_.age,
300
278
  }!;
301
279
  }
302
-
303
280
  export function jsonSalmonToApplicationTransform(input_?: any): Salmon {
304
281
  if (!input_) {
305
282
  return input_ as any;
306
283
  }
307
-
308
284
  return {
309
285
  kind: input_.kind,
310
286
  friends: jsonArrayFishToApplicationTransform(input_.friends),
@@ -40,7 +40,6 @@ export function jsonDinosaurToTransportTransform(input_?: Dinosaur | null): any
40
40
  if (!input_) {
41
41
  return input_ as any;
42
42
  }
43
-
44
43
  return {
45
44
  ...jsonDinosaurToTransportDiscriminator(input_),
46
45
  size: input_.size,
@@ -54,7 +53,6 @@ export function jsonTRexToTransportTransform(input_?: TRex | null): any {
54
53
  if (!input_) {
55
54
  return input_ as any;
56
55
  }
57
-
58
56
  return {
59
57
  kind: input_.kind,
60
58
  size: input_.size,
@@ -69,7 +67,6 @@ export function jsonDinosaurToApplicationTransform(input_?: any): Dinosaur {
69
67
  if (!input_) {
70
68
  return input_ as any;
71
69
  }
72
-
73
70
  return {
74
71
  ...jsonDinosaurToApplicationDiscriminator(input_),
75
72
  size: input_.size,
@@ -83,7 +80,6 @@ export function jsonTRexToApplicationTransform(input_?: any): TRex {
83
80
  if (!input_) {
84
81
  return input_ as any;
85
82
  }
86
-
87
83
  return {
88
84
  kind: input_.kind,
89
85
  size: input_.size,
@@ -21,9 +21,6 @@ op foo(): Widget;
21
21
  ```ts src/models/models.ts interface Widget
22
22
  export interface Widget {
23
23
  name: string;
24
- subWidget: {
25
- location: string;
26
- age?: number;
27
- };
24
+ subWidget: { location: string; age?: number };
28
25
  }
29
26
  ```
@@ -47,10 +47,8 @@ export function jsonDogToTransportTransform(input_?: Dog | null): any {
47
47
  if (!input_) {
48
48
  return input_ as any;
49
49
  }
50
-
51
50
  return {
52
51
  ...jsonRecordExtraFeatureToTransportTransform(input_.additionalProperties),
53
-
54
52
  id: input_.id,
55
53
  name: input_.name,
56
54
  color: input_.color,
@@ -65,12 +63,10 @@ export function jsonDogToApplicationTransform(input_?: any): Dog {
65
63
  if (!input_) {
66
64
  return input_ as any;
67
65
  }
68
-
69
66
  return {
70
67
  additionalProperties: jsonRecordExtraFeatureToApplicationTransform(
71
68
  (({ id, name, color, ...rest }) => rest)(input_),
72
69
  ),
73
-
74
70
  id: input_.id,
75
71
  name: input_.name,
76
72
  color: input_.color,
@@ -45,7 +45,6 @@ export function jsonPetToTransportTransform(input_?: Pet | null): any {
45
45
  if (!input_) {
46
46
  return input_ as any;
47
47
  }
48
-
49
48
  return {
50
49
  id: input_.id,
51
50
  name: input_.name,
@@ -60,7 +59,6 @@ export function jsonPetToApplicationTransform(input_?: any): Pet {
60
59
  if (!input_) {
61
60
  return input_ as any;
62
61
  }
63
-
64
62
  return {
65
63
  id: input_.id,
66
64
  name: input_.name,
@@ -75,7 +73,6 @@ export function jsonDogToTransportTransform(input_?: Dog | null): any {
75
73
  if (!input_) {
76
74
  return input_ as any;
77
75
  }
78
-
79
76
  return {
80
77
  color: input_.color,
81
78
  id: input_.id,
@@ -91,7 +88,6 @@ export function jsonDogToApplicationTransform(input_?: any): Dog {
91
88
  if (!input_) {
92
89
  return input_ as any;
93
90
  }
94
-
95
91
  return {
96
92
  color: input_.color,
97
93
  id: input_.id,
@@ -39,7 +39,6 @@ export function jsonDogToTransportTransform(input_?: Dog | null): any {
39
39
  if (!input_) {
40
40
  return input_ as any;
41
41
  }
42
-
43
42
  return {
44
43
  id: input_.id,
45
44
  name: input_.name,
@@ -55,7 +54,6 @@ export function jsonDogToApplicationTransform(input_?: any): Dog {
55
54
  if (!input_) {
56
55
  return input_ as any;
57
56
  }
58
-
59
57
  return {
60
58
  id: input_.id,
61
59
  name: input_.name,
@@ -22,24 +22,20 @@ export async function foo(
22
22
  options?: FooOptions,
23
23
  ): Promise<void> {
24
24
  const path = parse("/foo").expand({});
25
-
26
25
  const httpRequestOptions = {
27
26
  headers: {},
28
27
  body: {
29
28
  profileImage: encodeUint8Array(profileImage, "base64")!,
30
29
  },
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 (+response.status === 204 && !response.body) {
40
37
  return;
41
38
  }
42
-
43
39
  throw createRestError(response);
44
40
  }
45
41
  ```
@@ -38,7 +38,6 @@ export function jsonBarToTransportTransform(input_?: Bar | null): any {
38
38
  if (!input_) {
39
39
  return input_ as any;
40
40
  }
41
-
42
41
  return {
43
42
  address: input_.address,
44
43
  parentId: input_.parentId,
@@ -114,23 +113,19 @@ export function dateUnixTimestampDeserializer(date?: number | null): Date {
114
113
 
115
114
  return new Date(date * 1000);
116
115
  }
117
-
118
116
  export function jsonBarToTransportTransform(input_?: Bar | null): any {
119
117
  if (!input_) {
120
118
  return input_ as any;
121
119
  }
122
-
123
120
  return {
124
121
  address: input_.address,
125
122
  parentId: input_.parentId,
126
123
  }!;
127
124
  }
128
-
129
125
  export function jsonBarToApplicationTransform(input_?: any): Bar {
130
126
  if (!input_) {
131
127
  return input_ as any;
132
128
  }
133
-
134
129
  return {
135
130
  address: input_.address,
136
131
  parentId: input_.parentId,
@@ -147,7 +142,6 @@ export function jsonBarToApplicationTransform(input_?: any): Bar {
147
142
  if (!input_) {
148
143
  return input_ as any;
149
144
  }
150
-
151
145
  return {
152
146
  address: input_.address,
153
147
  parentId: input_.parentId,
@@ -20,16 +20,10 @@ op foo(
20
20
  ```ts src/api/testClientOperations.ts function foo
21
21
  export async function foo(
22
22
  client: TestClientContext,
23
- body: {
24
- temperature: {
25
- body: number;
26
- contentType: "text/plain";
27
- };
28
- },
23
+ body: { temperature: { body: number; contentType: "text/plain" } },
29
24
  options?: FooOptions,
30
25
  ): Promise<void> {
31
26
  const path = parse("/").expand({});
32
-
33
27
  const httpRequestOptions = {
34
28
  headers: {
35
29
  "content-type": options?.contentType ?? "multipart/form-data",
@@ -37,21 +31,18 @@ export async function foo(
37
31
  body: [
38
32
  {
39
33
  name: "temperature",
40
- body: body.temperature,
34
+ body: body.temperature.body,
41
35
  },
42
36
  ],
43
37
  };
44
-
45
38
  const response = await client.pathUnchecked(path).post(httpRequestOptions);
46
39
 
47
40
  if (typeof options?.operationOptions?.onResponse === "function") {
48
41
  options?.operationOptions?.onResponse(response);
49
42
  }
50
-
51
43
  if (+response.status === 204 && !response.body) {
52
44
  return;
53
45
  }
54
-
55
46
  throw createRestError(response);
56
47
  }
57
48
  ```