@typespec/http-client-js 0.16.2-dev.1 → 0.16.2

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 (225) hide show
  1. package/dist/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +24 -20
  3. package/.github/copilot-instructions.md +0 -180
  4. package/.testignore +0 -19
  5. package/.turbo/turbo-build.log +0 -3
  6. package/CHANGELOG.md +0 -159
  7. package/eng/scripts/calculate-coverage.ts +0 -33
  8. package/eng/scripts/emit-e2e.ts +0 -317
  9. package/eng/scripts/run-e2e-tests.ts +0 -166
  10. package/eng/scripts/tspconfig.yaml +0 -6
  11. package/eng/scripts/upload-spector-results.ts +0 -139
  12. package/src/components/client-context/client-context-declaration.tsx +0 -26
  13. package/src/components/client-context/client-context-factory.tsx +0 -218
  14. package/src/components/client-context/client-context-options.tsx +0 -36
  15. package/src/components/client-context/client-context.tsx +0 -23
  16. package/src/components/client-context/parametrized-endpoint.tsx +0 -51
  17. package/src/components/client-directory.tsx +0 -51
  18. package/src/components/client-operation.tsx +0 -102
  19. package/src/components/client.tsx +0 -177
  20. package/src/components/encoding-provider.tsx +0 -17
  21. package/src/components/external-packages/ts-http-runtime.ts +0 -28
  22. package/src/components/external-packages/uri-template.ts +0 -11
  23. package/src/components/http-request-options.tsx +0 -88
  24. package/src/components/http-request-parameters-expression.tsx +0 -191
  25. package/src/components/http-request.tsx +0 -80
  26. package/src/components/http-response.tsx +0 -74
  27. package/src/components/index.ts +0 -12
  28. package/src/components/models.tsx +0 -26
  29. package/src/components/operation-handlers/index.tsx +0 -2
  30. package/src/components/operation-handlers/operation-pipeline.tsx +0 -33
  31. package/src/components/operation-handlers/paging/page-item.tsx +0 -14
  32. package/src/components/operation-handlers/paging/page-response.tsx +0 -57
  33. package/src/components/operation-handlers/paging/page-settings.tsx +0 -53
  34. package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +0 -200
  35. package/src/components/operation-handlers/paging/request-send.tsx +0 -85
  36. package/src/components/operation-handlers/paging/response-deserialize.tsx +0 -60
  37. package/src/components/operation-handlers/paging/util.ts +0 -70
  38. package/src/components/operation-handlers/types.tsx +0 -18
  39. package/src/components/operation-options.tsx +0 -42
  40. package/src/components/operation-parameters.tsx +0 -44
  41. package/src/components/output.tsx +0 -32
  42. package/src/components/serializers.tsx +0 -74
  43. package/src/components/static-helpers/bytes-encoding.tsx +0 -61
  44. package/src/components/static-helpers/interfaces.tsx +0 -31
  45. package/src/components/static-helpers/multipart-helpers.tsx +0 -80
  46. package/src/components/static-helpers/paging-helper.tsx +0 -202
  47. package/src/components/static-helpers/rest-error.tsx +0 -102
  48. package/src/components/testing/client-options.tsx +0 -30
  49. package/src/components/transforms/content-type-encoding-provider.tsx +0 -26
  50. package/src/components/transforms/data-transform.tsx +0 -40
  51. package/src/components/transforms/json/json-array-transform.tsx +0 -87
  52. package/src/components/transforms/json/json-model-additional-properties-transform.tsx +0 -54
  53. package/src/components/transforms/json/json-model-base-transform.tsx +0 -24
  54. package/src/components/transforms/json/json-model-property-transform.tsx +0 -53
  55. package/src/components/transforms/json/json-model-transform.tsx +0 -115
  56. package/src/components/transforms/json/json-record-transform.tsx +0 -88
  57. package/src/components/transforms/json/json-transform-discriminator.tsx +0 -111
  58. package/src/components/transforms/json/json-transform.tsx +0 -120
  59. package/src/components/transforms/json/union-transform.tsx +0 -87
  60. package/src/components/transforms/json/utils/transport-namer.ts +0 -12
  61. package/src/components/transforms/multipart/array-part-transform.tsx +0 -44
  62. package/src/components/transforms/multipart/file-part-transform.tsx +0 -45
  63. package/src/components/transforms/multipart/multipart-transform.tsx +0 -30
  64. package/src/components/transforms/multipart/part-transform.tsx +0 -22
  65. package/src/components/transforms/multipart/simple-part-transform.tsx +0 -42
  66. package/src/components/transforms/operation-transform-declaration.tsx +0 -83
  67. package/src/components/transforms/operation-transform-expression.tsx +0 -62
  68. package/src/components/transforms/scalar-transform.tsx +0 -301
  69. package/src/components/transforms/transform-name-policy.ts +0 -134
  70. package/src/components/utils/unpack-model-property.ts +0 -44
  71. package/src/components/utils/url-template.tsx +0 -25
  72. package/src/context/encoding/encoding-context.tsx +0 -28
  73. package/src/context/encoding/types.ts +0 -6
  74. package/src/emitter.tsx +0 -85
  75. package/src/index.ts +0 -5
  76. package/src/lib.ts +0 -120
  77. package/src/testing/index.ts +0 -11
  78. package/src/utils/client-discovery.ts +0 -28
  79. package/src/utils/multipart.ts +0 -29
  80. package/src/utils/operations.ts +0 -112
  81. package/src/utils/parameters.tsx +0 -155
  82. package/test/e2e/assets/image.jpg +0 -0
  83. package/test/e2e/assets/image.png +0 -0
  84. package/test/e2e/http/authentication/api-key/main.test.ts +0 -38
  85. package/test/e2e/http/authentication/oauth2/main.test.ts +0 -31
  86. package/test/e2e/http/authentication/union/main.test.ts +0 -26
  87. package/test/e2e/http/encode/bytes/main.test.ts +0 -191
  88. package/test/e2e/http/encode/datetime/main.test.ts +0 -176
  89. package/test/e2e/http/encode/duration/main.test.ts +0 -126
  90. package/test/e2e/http/encode/numeric/main.test.ts +0 -26
  91. package/test/e2e/http/parameters/basic/main.test.ts +0 -35
  92. package/test/e2e/http/parameters/body-optionality/main.test.ts +0 -43
  93. package/test/e2e/http/parameters/collection-format/main.test.ts +0 -40
  94. package/test/e2e/http/parameters/spread/main.test.ts +0 -56
  95. package/test/e2e/http/payload/content-negotiation/main.test.ts +0 -40
  96. package/test/e2e/http/payload/json-merge-patch/main.test.ts +0 -122
  97. package/test/e2e/http/payload/media-type/main.test.ts +0 -28
  98. package/test/e2e/http/payload/multipart/main.test.ts +0 -200
  99. package/test/e2e/http/payload/pageable/main.test.ts +0 -78
  100. package/test/e2e/http/payload/xml/main.test.ts +0 -287
  101. package/test/e2e/http/routes/main.test.ts +0 -284
  102. package/test/e2e/http/serialization/encoded-name/json/main.test.ts +0 -20
  103. package/test/e2e/http/server/endpoint/not-defined/main.test.ts +0 -11
  104. package/test/e2e/http/server/path/multiple/main.test.ts +0 -22
  105. package/test/e2e/http/server/path/single/main.test.ts +0 -11
  106. package/test/e2e/http/server/versions/not-versioned/main.test.ts +0 -22
  107. package/test/e2e/http/server/versions/versioned/main.test.ts +0 -28
  108. package/test/e2e/http/special-headers/conditional-request/main.test.ts +0 -35
  109. package/test/e2e/http/special-headers/repeatability/main.test.ts +0 -18
  110. package/test/e2e/http/special-words/main.test.ts +0 -434
  111. package/test/e2e/http/type/array/array.test.ts +0 -256
  112. package/test/e2e/http/type/dictionary/main.test.ts +0 -229
  113. package/test/e2e/http/type/enum/extensible/main.test.ts +0 -34
  114. package/test/e2e/http/type/enum/fixed/main.test.ts +0 -29
  115. package/test/e2e/http/type/model/empty/main.test.ts +0 -21
  116. package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +0 -51
  117. package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +0 -168
  118. package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +0 -42
  119. package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +0 -46
  120. package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +0 -99
  121. package/test/e2e/http/type/model/visibility/main.test.ts +0 -64
  122. package/test/e2e/http/type/property/additional-properties/main.test.ts +0 -185
  123. package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -448
  124. package/test/e2e/http/type/property/nullable/main.test.ts +0 -275
  125. package/test/e2e/http/type/property/optionality/main.test.ts +0 -256
  126. package/test/e2e/http/type/property/value-types/main.test.ts +0 -193
  127. package/test/e2e/http/type/scalar/main.test.ts +0 -133
  128. package/test/e2e/http/type/scalar/scalar.test.ts +0 -95
  129. package/test/e2e/http/type/union/main.test.ts +0 -207
  130. package/test/e2e/http/versioning/added/main.test.ts +0 -60
  131. package/test/e2e/http/versioning/madeOptional/main.test.ts +0 -34
  132. package/test/e2e/http/versioning/removed/main.test.ts +0 -75
  133. package/test/e2e/http/versioning/renamedFrom/main.test.ts +0 -52
  134. package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +0 -22
  135. package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +0 -31
  136. package/test/scenarios/additional-properties/extends.md +0 -67
  137. package/test/scenarios/additional-properties/is.md +0 -42
  138. package/test/scenarios/additional-properties/spread.md +0 -68
  139. package/test/scenarios/auth/basic_auth.md +0 -68
  140. package/test/scenarios/auth/bearer.md +0 -68
  141. package/test/scenarios/auth/client_parameters.md +0 -78
  142. package/test/scenarios/auth/client_structure.md +0 -36
  143. package/test/scenarios/auth/key_credential.md +0 -69
  144. package/test/scenarios/auth/oauth2.md +0 -90
  145. package/test/scenarios/auth/sub_client_override.md +0 -114
  146. package/test/scenarios/client/client_context.md +0 -34
  147. package/test/scenarios/client/dotted_namespace.md +0 -27
  148. package/test/scenarios/client/global_namespace.md +0 -69
  149. package/test/scenarios/client/multiple_top_level_clients.md +0 -72
  150. package/test/scenarios/client/nested_client.md +0 -102
  151. package/test/scenarios/client/wrapping_namespace.md +0 -41
  152. package/test/scenarios/encoding/bytes_body.md +0 -44
  153. package/test/scenarios/encoding/bytes_json_property.md +0 -55
  154. package/test/scenarios/encoding/bytes_nullable.md +0 -139
  155. package/test/scenarios/encoding/header_bytes.md +0 -130
  156. package/test/scenarios/encoding/header_date.md +0 -216
  157. package/test/scenarios/encoding/model_with_bytes_property.md +0 -45
  158. package/test/scenarios/encoding/query_bytes.md +0 -42
  159. package/test/scenarios/encoding/query_date.md +0 -216
  160. package/test/scenarios/http-operations/basic-request.md +0 -144
  161. package/test/scenarios/http-operations/basic-response.md +0 -219
  162. package/test/scenarios/http-operations/basic.md +0 -128
  163. package/test/scenarios/http-operations/constant-header.md +0 -33
  164. package/test/scenarios/http-operations/create-operation.md +0 -58
  165. package/test/scenarios/http-operations/on_response.md +0 -52
  166. package/test/scenarios/http-operations/optional-request-body.md +0 -50
  167. package/test/scenarios/http-operations/paging.md +0 -242
  168. package/test/scenarios/http-operations/path-parameter-in-model.md +0 -53
  169. package/test/scenarios/http-operations/path-parameter.md +0 -48
  170. package/test/scenarios/http-operations/query-parameter.md +0 -41
  171. package/test/scenarios/http-operations/scalar-payload.md +0 -57
  172. package/test/scenarios/http-operations/with-parameters.md +0 -78
  173. package/test/scenarios/models/array-properties.md +0 -47
  174. package/test/scenarios/models/basic.md +0 -118
  175. package/test/scenarios/models/dictionary-properties.md +0 -44
  176. package/test/scenarios/models/inheritance_2_discriminators.md +0 -346
  177. package/test/scenarios/models/inheritance_discriminator.md +0 -88
  178. package/test/scenarios/models/inline-models.md +0 -29
  179. package/test/scenarios/models/model_additional_properties.md +0 -75
  180. package/test/scenarios/models/model_extends.md +0 -97
  181. package/test/scenarios/models/model_spread.md +0 -63
  182. package/test/scenarios/models/nested_property.md +0 -41
  183. package/test/scenarios/models/property_references_property.md +0 -150
  184. package/test/scenarios/multipart/anonymous_part.md +0 -53
  185. package/test/scenarios/multipart/file.md +0 -154
  186. package/test/scenarios/multipart/file_content_type.md +0 -92
  187. package/test/scenarios/multipart/non-string-float.md +0 -55
  188. package/test/scenarios/multipart/simple_part.md +0 -65
  189. package/test/scenarios/operation-parameters/body_root_anonymous.md +0 -87
  190. package/test/scenarios/operation-parameters/constant_as_optional.md +0 -54
  191. package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -54
  192. package/test/scenarios/operation-parameters/no_content_type.md +0 -62
  193. package/test/scenarios/operation-parameters/no_parameters.md +0 -50
  194. package/test/scenarios/operation-parameters/only_optional.md +0 -62
  195. package/test/scenarios/operation-parameters/only_required.md +0 -58
  196. package/test/scenarios/operation-parameters/reserved_names.md +0 -60
  197. package/test/scenarios/operation-parameters/spread_body.md +0 -70
  198. package/test/scenarios/operation-parameters/spread_with_nested.md +0 -82
  199. package/test/scenarios/operation-parameters/union_body.md +0 -86
  200. package/test/scenarios/operation-parameters/with_body_property.md +0 -67
  201. package/test/scenarios/operation-parameters/with_body_root.md +0 -69
  202. package/test/scenarios/serializers/arrays.md +0 -191
  203. package/test/scenarios/serializers/basic_model.md +0 -111
  204. package/test/scenarios/serializers/basic_model_wire_name.md +0 -48
  205. package/test/scenarios/serializers/discriminated_union.md +0 -86
  206. package/test/scenarios/serializers/discriminated_union_spread.md +0 -115
  207. package/test/scenarios/serializers/file.md +0 -67
  208. package/test/scenarios/serializers/model_date_time.md +0 -65
  209. package/test/scenarios/serializers/multipart.md +0 -62
  210. package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +0 -157
  211. package/test/scenarios/serializers/property_references_property.md +0 -72
  212. package/test/scenarios/serializers/record.md +0 -97
  213. package/test/scenarios/serializers/scalars.md +0 -34
  214. package/test/scenarios/serializers/spread.md +0 -69
  215. package/test/scenarios/serializers/string_union.md +0 -55
  216. package/test/scenarios/server/default_url.md +0 -45
  217. package/test/scenarios/server/multiple-parameters.md +0 -55
  218. package/test/scenarios/server/no-server.md +0 -37
  219. package/test/scenarios/server/parametrized-endpoint.md +0 -51
  220. package/test/scenarios.test.ts +0 -24
  221. package/test/test-host.ts +0 -22
  222. package/tsconfig.json +0 -16
  223. package/tsconfig.test.json +0 -9
  224. package/vitest.config.e2e.ts +0 -16
  225. package/vitest.config.ts +0 -15
@@ -1,70 +0,0 @@
1
- # Should emit an operation that has a spread model as parameters
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- model Widget {
8
- id: string;
9
- name: string;
10
- age?: string;
11
- }
12
-
13
- @post op create(...Widget): void;
14
- ```
15
-
16
- ## Operation
17
-
18
- The operation has has no required parameters so options and client should be the only ones in the signature
19
-
20
- ```ts src/api/testClientOperations.ts function create
21
- export async function create(
22
- client: TestClientContext,
23
- id: string,
24
- name: string,
25
- options?: CreateOptions,
26
- ): Promise<void> {
27
- const path = parse("/").expand({});
28
- const httpRequestOptions = {
29
- headers: {},
30
- body: {
31
- id: id,
32
- name: name,
33
- age: options?.age,
34
- },
35
- };
36
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
37
-
38
- if (typeof options?.operationOptions?.onResponse === "function") {
39
- options?.operationOptions?.onResponse(response);
40
- }
41
- if (+response.status === 204 && !response.body) {
42
- return;
43
- }
44
- throw createRestError(response);
45
- }
46
- ```
47
-
48
- ## Options
49
-
50
- The options bag should like all the optional parameters of the operation
51
-
52
- ```ts src/api/testClientOperations.ts interface CreateOptions
53
- export interface CreateOptions extends OperationOptions {
54
- age?: string;
55
- }
56
- ```
57
-
58
- ## Client
59
-
60
- ```ts src/testClient.ts class TestClient
61
- export class TestClient {
62
- #context: TestClientContext;
63
- constructor(endpoint: string, options?: TestClientOptions) {
64
- this.#context = createTestClientContext(endpoint, options);
65
- }
66
- async create(id: string, name: string, options?: CreateOptions) {
67
- return create(this.#context, id, name, options);
68
- }
69
- }
70
- ```
@@ -1,82 +0,0 @@
1
- # Should emit an operation that has a spread model with a nested model as parameter
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- model Address {
8
- street: string;
9
- city: string;
10
- state: string;
11
- zipCode: string;
12
- interiorNumber?: string;
13
- }
14
-
15
- model Widget {
16
- id: string;
17
- name: string;
18
- age?: string;
19
- address?: Address;
20
- }
21
-
22
- @post op create(...Widget): void;
23
- ```
24
-
25
- ## Operation
26
-
27
- The operation has has no required parameters so options and client should be the only ones in the signature
28
-
29
- ```ts src/api/testClientOperations.ts function create
30
- export async function create(
31
- client: TestClientContext,
32
- id: string,
33
- name: string,
34
- options?: CreateOptions,
35
- ): Promise<void> {
36
- const path = parse("/").expand({});
37
- const httpRequestOptions = {
38
- headers: {},
39
- body: {
40
- id: id,
41
- name: name,
42
- age: options?.age,
43
- address: jsonAddressToTransportTransform(options?.address),
44
- },
45
- };
46
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
47
-
48
- if (typeof options?.operationOptions?.onResponse === "function") {
49
- options?.operationOptions?.onResponse(response);
50
- }
51
- if (+response.status === 204 && !response.body) {
52
- return;
53
- }
54
- throw createRestError(response);
55
- }
56
- ```
57
-
58
- ## Options
59
-
60
- The options bag should like all the optional parameters of the operation
61
-
62
- ```ts src/api/testClientOperations.ts interface CreateOptions
63
- export interface CreateOptions extends OperationOptions {
64
- age?: string;
65
- interiorNumber?: string;
66
- address?: Address;
67
- }
68
- ```
69
-
70
- ## Client
71
-
72
- ```ts src/testClient.ts class TestClient
73
- export class TestClient {
74
- #context: TestClientContext;
75
- constructor(endpoint: string, options?: TestClientOptions) {
76
- this.#context = createTestClientContext(endpoint, options);
77
- }
78
- async create(id: string, name: string, options?: CreateOptions) {
79
- return create(this.#context, id, name, options);
80
- }
81
- }
82
- ```
@@ -1,86 +0,0 @@
1
- # Should emit an operation that has body property parameter
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- enum LR {
8
- left,
9
- right,
10
- }
11
- enum UD {
12
- up,
13
- down,
14
- }
15
-
16
- model EnumsOnlyCases {
17
- /** This should be receive/send the left variant */
18
- lr: LR | UD;
19
-
20
- /** This should be receive/send the up variant */
21
- ud: UD | UD;
22
- }
23
-
24
- @post op send(prop: EnumsOnlyCases): void;
25
- ```
26
-
27
- ## Operation
28
-
29
- ```ts src/api/testClientOperations.ts function send
30
- export async function send(
31
- client: TestClientContext,
32
- prop: EnumsOnlyCases,
33
- options?: SendOptions,
34
- ): Promise<void> {
35
- const path = parse("/").expand({});
36
- const httpRequestOptions = {
37
- headers: {},
38
- body: {
39
- prop: jsonEnumsOnlyCasesToTransportTransform(prop),
40
- },
41
- };
42
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
43
-
44
- if (typeof options?.operationOptions?.onResponse === "function") {
45
- options?.operationOptions?.onResponse(response);
46
- }
47
- if (+response.status === 204 && !response.body) {
48
- return;
49
- }
50
- throw createRestError(response);
51
- }
52
- ```
53
-
54
- ## Options
55
-
56
- The options bag should like all the optional parameters of the operation
57
-
58
- ```ts src/api/testClientOperations.ts interface SendOptions
59
- export interface SendOptions extends OperationOptions {}
60
- ```
61
-
62
- ## Client
63
-
64
- ```ts src/testClient.ts class TestClient
65
- export class TestClient {
66
- #context: TestClientContext;
67
- constructor(endpoint: string, options?: TestClientOptions) {
68
- this.#context = createTestClientContext(endpoint, options);
69
- }
70
- async send(prop: EnumsOnlyCases, options?: SendOptions) {
71
- return send(this.#context, prop, options);
72
- }
73
- }
74
- ```
75
-
76
- ```ts src/models/internal/serializers.ts function jsonEnumsOnlyCasesToTransportTransform
77
- export function jsonEnumsOnlyCasesToTransportTransform(input_?: EnumsOnlyCases | null): any {
78
- if (!input_) {
79
- return input_ as any;
80
- }
81
- return {
82
- lr: input_.lr,
83
- ud: input_.ud,
84
- }!;
85
- }
86
- ```
@@ -1,67 +0,0 @@
1
- # Should emit an operation that has a @body explicitly set.
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- model Widget {
8
- id: string;
9
- name: string;
10
- age?: string;
11
- }
12
-
13
- @post op create(@body widget: Widget, @header foo?: string): void;
14
- ```
15
-
16
- ## Operation
17
-
18
- The operation has has no required parameters so options and client should be the only ones in the signature
19
-
20
- ```ts src/api/testClientOperations.ts function create
21
- export async function create(
22
- client: TestClientContext,
23
- widget: Widget,
24
- options?: CreateOptions,
25
- ): Promise<void> {
26
- const path = parse("/").expand({});
27
- const httpRequestOptions = {
28
- headers: {
29
- ...(options?.foo && { foo: options.foo }),
30
- },
31
- body: jsonWidgetToTransportTransform(widget),
32
- };
33
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
34
-
35
- if (typeof options?.operationOptions?.onResponse === "function") {
36
- options?.operationOptions?.onResponse(response);
37
- }
38
- if (+response.status === 204 && !response.body) {
39
- return;
40
- }
41
- throw createRestError(response);
42
- }
43
- ```
44
-
45
- ## Options
46
-
47
- The options bag should like all the optional parameters of the operation
48
-
49
- ```ts src/api/testClientOperations.ts interface CreateOptions
50
- export interface CreateOptions extends OperationOptions {
51
- foo?: string;
52
- }
53
- ```
54
-
55
- ## Client
56
-
57
- ```ts src/testClient.ts class TestClient
58
- export class TestClient {
59
- #context: TestClientContext;
60
- constructor(endpoint: string, options?: TestClientOptions) {
61
- this.#context = createTestClientContext(endpoint, options);
62
- }
63
- async create(widget: Widget, options?: CreateOptions) {
64
- return create(this.#context, widget, options);
65
- }
66
- }
67
- ```
@@ -1,69 +0,0 @@
1
- # Should emit an operation that has a @bodyRoot set.
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- model Widget {
8
- id: string;
9
- name: string;
10
- age?: string;
11
- @header foo?: string;
12
- }
13
-
14
- @post op create(@bodyRoot widget: Widget): void;
15
- ```
16
-
17
- ## Operation
18
-
19
- The operation has has no required parameters so options and client should be the only ones in the signature
20
-
21
- ```ts src/api/testClientOperations.ts function create
22
- export async function create(
23
- client: TestClientContext,
24
- widget: Widget,
25
- options?: CreateOptions,
26
- ): Promise<void> {
27
- const path = parse("/").expand({});
28
- const httpRequestOptions = {
29
- headers: {
30
- ...(widget.foo && { foo: widget.foo }),
31
- },
32
- body: jsonWidgetToTransportTransform(widget),
33
- };
34
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
35
-
36
- if (typeof options?.operationOptions?.onResponse === "function") {
37
- options?.operationOptions?.onResponse(response);
38
- }
39
- if (+response.status === 204 && !response.body) {
40
- return;
41
- }
42
- throw createRestError(response);
43
- }
44
- ```
45
-
46
- ## Options
47
-
48
- The options bag should like all the optional parameters of the operation
49
-
50
- ```ts src/api/testClientOperations.ts interface CreateOptions
51
- export interface CreateOptions extends OperationOptions {
52
- age?: string;
53
- foo?: string;
54
- }
55
- ```
56
-
57
- ## Client
58
-
59
- ```ts src/testClient.ts class TestClient
60
- export class TestClient {
61
- #context: TestClientContext;
62
- constructor(endpoint: string, options?: TestClientOptions) {
63
- this.#context = createTestClientContext(endpoint, options);
64
- }
65
- async create(widget: Widget, options?: CreateOptions) {
66
- return create(this.#context, widget, options);
67
- }
68
- }
69
- ```
@@ -1,191 +0,0 @@
1
- # **Handling Serialization and Deserialization of Primitive Array Properties**
2
-
3
- This test verifies that a **primitive array property** (`int32[]`) is correctly handled in the generated TypeScript code. The expected output includes:
4
-
5
- - A `Foo` model with a `myValues` property mapped to `Array<number>`.
6
- - `jsonFooToTransportTransform` and `jsonFooToApplicationTransform` functions that internally use an `arraySerializer`.
7
- - Transformation functions for `int32[]`, ensuring elements are properly processed.
8
-
9
- ### **Potential Optimization Consideration**
10
-
11
- Since primitive types **do not require transformation**, generating explicit functions like `jsonArrayInt32ToTransportTransform` and `jsonArrayInt32ToApplicationTransform` might be **redundant**. Optimizing this could **eliminate unnecessary transformations**, reducing the amount of generated code while maintaining correctness.
12
-
13
- ## **TypeSpec**
14
-
15
- ```tsp
16
- model Foo {
17
- my_values: int32[];
18
- }
19
- op foo(): Foo;
20
- ```
21
-
22
- ## **TypeScript**
23
-
24
- ### **Generated Model**
25
-
26
- A TypeScript model representing `Foo` with `myValues` properly typed as `Array<number>`.
27
-
28
- ```ts src/models/models.ts interface Foo
29
- export interface Foo {
30
- myValues: Array<number>;
31
- }
32
- ```
33
-
34
- ### **Primitive Array Transformation (Consider Optimization)**
35
-
36
- The generated transformation functions iterate over `int32[]` values, but since **no actual transformation occurs**, this code could be **optimized away**.
37
-
38
- ```ts src/models/internal/serializers.ts function jsonArrayInt32ToTransportTransform
39
- export function jsonArrayInt32ToTransportTransform(items_?: Array<number> | null): any {
40
- if (!items_) {
41
- return items_ as any;
42
- }
43
- const _transformedArray = [];
44
-
45
- for (const item of items_ ?? []) {
46
- const transformedItem = item as any;
47
- _transformedArray.push(transformedItem);
48
- }
49
-
50
- return _transformedArray as any;
51
- }
52
- ```
53
-
54
- ### **Serializer for `Foo`**
55
-
56
- Uses `jsonArrayInt32ToTransportTransform` for `myValues`, though this could be optimized by **directly passing the array** instead of applying a redundant transformation function.
57
-
58
- ```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
59
- export function jsonFooToTransportTransform(input_?: Foo | null): any {
60
- if (!input_) {
61
- return input_ as any;
62
- }
63
- return {
64
- my_values: jsonArrayInt32ToTransportTransform(input_.myValues),
65
- }!;
66
- }
67
- ```
68
-
69
- ### **Operation Function for `Foo`**
70
-
71
- Handles the API request, expecting a `Widget` response and applying the correct deserialization function.
72
-
73
- ```ts src/api/clientOperations.ts function foo
74
- export async function foo(client: ClientContext, options?: FooOptions): Promise<Foo> {
75
- const path = parse("/").expand({});
76
- const httpRequestOptions = {
77
- headers: {},
78
- };
79
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
80
-
81
- if (typeof options?.operationOptions?.onResponse === "function") {
82
- options?.operationOptions?.onResponse(response);
83
- }
84
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
85
- return jsonFooToApplicationTransform(response.body)!;
86
- }
87
- throw createRestError(response);
88
- }
89
- ```
90
-
91
- ### **Primitive Array Deserialization (Consider Optimization)**
92
-
93
- Again, the transformation logic is redundant for primitive types. Instead of generating a function, the deserializer could **use the array directly**.
94
-
95
- ```ts src/models/internal/serializers.ts function jsonArrayInt32ToApplicationTransform
96
- export function jsonArrayInt32ToApplicationTransform(items_?: any): Array<number> {
97
- if (!items_) {
98
- return items_ as any;
99
- }
100
- const _transformedArray = [];
101
-
102
- for (const item of items_ ?? []) {
103
- const transformedItem = item as any;
104
- _transformedArray.push(transformedItem);
105
- }
106
-
107
- return _transformedArray as any;
108
- }
109
- ```
110
-
111
- ### **Deserializer for `Foo`**
112
-
113
- Uses the same unnecessary transformation for `myValues`. Optimizing the pipeline could **eliminate this step** for primitive arrays.
114
-
115
- ```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
116
- export function jsonFooToApplicationTransform(input_?: any): Foo {
117
- if (!input_) {
118
- return input_ as any;
119
- }
120
- return {
121
- myValues: jsonArrayInt32ToApplicationTransform(input_.my_values),
122
- }!;
123
- }
124
- ```
125
-
126
- ---
127
-
128
- # **Handling Serialization and Deserialization of Complex Array Properties**
129
-
130
- This test verifies that **arrays of complex types** (`Bar[]`) are correctly handled in the generated TypeScript code. Unlike primitive arrays, complex types **require transformation functions** to ensure serialization and deserialization are applied correctly.
131
-
132
- ## **TypeSpec**
133
-
134
- ```tsp
135
- model Bar {
136
- bar_value: string;
137
- }
138
-
139
- model Foo {
140
- my_values: Bar[];
141
- }
142
- op foo(): Foo;
143
- ```
144
-
145
- ## **TypeScript**
146
-
147
- ### **Generated Models**
148
-
149
- Defines TypeScript interfaces for `Foo` and `Bar`, ensuring `myValues` is properly typed as `Array<Bar>`.
150
-
151
- ```ts src/models/models.ts interface Foo
152
- export interface Foo {
153
- myValues: Array<Bar>;
154
- }
155
- ```
156
-
157
- ```ts src/models/models.ts interface Bar
158
- export interface Bar {
159
- barValue: string;
160
- }
161
- ```
162
-
163
- ### **Serializer for `Foo`**
164
-
165
- Uses `jsonArrayBarToTransportTransform` to serialize each `Bar` instance inside `myValues`, ensuring proper transformation of complex objects.
166
-
167
- ```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
168
- export function jsonFooToTransportTransform(input_?: Foo | null): any {
169
- if (!input_) {
170
- return input_ as any;
171
- }
172
- return {
173
- my_values: jsonArrayBarToTransportTransform(input_.myValues),
174
- }!;
175
- }
176
- ```
177
-
178
- ### **Deserializer for `Foo`**
179
-
180
- Similarly, the deserializer converts each `Bar` instance in `myValues` back into an application model using `jsonArrayBarToApplicationTransform`.
181
-
182
- ```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
183
- export function jsonFooToApplicationTransform(input_?: any): Foo {
184
- if (!input_) {
185
- return input_ as any;
186
- }
187
- return {
188
- myValues: jsonArrayBarToApplicationTransform(input_.my_values),
189
- }!;
190
- }
191
- ```
@@ -1,111 +0,0 @@
1
- # Should Generate a Type, Serializer, and Deserializer for a Simple Model
2
-
3
- ## TypeSpec
4
-
5
- This TypeSpec block defines a simple model, Foo, containing two properties: name (a string) and age (an integer). The foo operation returns an instance of Foo, ensuring that the generated TypeScript code includes the correct type definitions and transformation functions.
6
-
7
- ```tsp
8
- model Foo {
9
- name: string;
10
- age: int32;
11
- }
12
- op foo(): Foo;
13
- ```
14
-
15
- ## TypeScript
16
-
17
- ### Interface Definition (Foo)
18
-
19
- The test expects a TypeScript interface Foo to be generated in src/models/models.ts, preserving the original properties from the TypeSpec definition.
20
-
21
- ```ts src/models/models.ts interface Foo
22
- export interface Foo {
23
- name: string;
24
- age: number;
25
- }
26
- ```
27
-
28
- ### Serializer (jsonFooToTransportTransform)
29
-
30
- This function should correctly transform a Foo instance into a transport-friendly format, ensuring all properties are properly mapped.
31
-
32
- ```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
33
- export function jsonFooToTransportTransform(input_?: Foo | null): any {
34
- if (!input_) {
35
- return input_ as any;
36
- }
37
- return {
38
- name: input_.name,
39
- age: input_.age,
40
- }!;
41
- }
42
- ```
43
-
44
- ### Deserializer (jsonFooToApplicationTransform)
45
-
46
- This function should correctly reconstruct a Foo instance from a transport-friendly representation, ensuring all properties are properly mapped back.
47
-
48
- ```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
49
- export function jsonFooToApplicationTransform(input_?: any): Foo {
50
- if (!input_) {
51
- return input_ as any;
52
- }
53
- return {
54
- name: input_.name,
55
- age: input_.age,
56
- }!;
57
- }
58
- ```
59
-
60
- # Should Call Nested Serializers and Deserializers for Model Properties
61
-
62
- ## TypeSpec
63
-
64
- This TypeSpec block defines two models, Foo and Bar, where Foo includes a nested reference to Bar. The foo operation returns either a Foo or a Bar, testing how the serialization and deserialization logic handles model properties that reference other models.
65
-
66
- ```tsp
67
- model Bar {
68
- address: string;
69
- }
70
-
71
- model Foo {
72
- name: string;
73
- age: int32;
74
- bar: Bar;
75
- }
76
- op foo(): Foo | Bar;
77
- ```
78
-
79
- ## TypeScript
80
-
81
- ### Serializer for Foo (jsonFooToTransportTransform)
82
-
83
- This function should transform Foo into a transport-friendly format while ensuring that the bar property is serialized using the jsonBarToTransportTransform function.
84
-
85
- ```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
86
- export function jsonFooToTransportTransform(input_?: Foo | null): any {
87
- if (!input_) {
88
- return input_ as any;
89
- }
90
- return {
91
- name: input_.name,
92
- age: input_.age,
93
- bar: jsonBarToTransportTransform(input_.bar),
94
- }!;
95
- }
96
- ```
97
-
98
- ### Serializer for Bar (jsonBarToTransportTransform)
99
-
100
- This function should transform a Bar instance into its transport format, correctly mapping its properties.
101
-
102
- ```ts src/models/internal/serializers.ts function jsonBarToTransportTransform
103
- export function jsonBarToTransportTransform(input_?: Bar | null): any {
104
- if (!input_) {
105
- return input_ as any;
106
- }
107
- return {
108
- address: input_.address,
109
- }!;
110
- }
111
- ```