@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,92 +0,0 @@
1
- # Should handle part files with specific content type
2
-
3
- ```tsp
4
- namespace Test;
5
- model FileSpecificContentType extends File {
6
- filename: string;
7
- contentType: "image/jpg";
8
- }
9
-
10
- model FileWithHttpPartSpecificContentTypeRequest {
11
- profileImage: HttpPart<FileSpecificContentType>;
12
- }
13
-
14
- @post
15
- @route("/check-filename-and-specific-content-type-with-httppart")
16
- op imageJpegContentType(
17
- @header contentType: "multipart/form-data",
18
- @multipartBody body: FileWithHttpPartSpecificContentTypeRequest,
19
- ): NoContentResponse;
20
- ```
21
-
22
- ## Operations
23
-
24
- ```ts src/api/testClientOperations.ts function imageJpegContentType
25
- export async function imageJpegContentType(
26
- client: TestClientContext,
27
- body: FileWithHttpPartSpecificContentTypeRequest,
28
- options?: ImageJpegContentTypeOptions,
29
- ): Promise<void> {
30
- const path = parse("/check-filename-and-specific-content-type-with-httppart").expand({});
31
- const httpRequestOptions = {
32
- headers: {
33
- "content-type": options?.contentType ?? "multipart/form-data",
34
- },
35
- body: [createFilePartDescriptor("profileImage", body.profileImage, "image/jpg")],
36
- };
37
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
38
-
39
- if (typeof options?.operationOptions?.onResponse === "function") {
40
- options?.operationOptions?.onResponse(response);
41
- }
42
- if (+response.status === 204 && !response.body) {
43
- return;
44
- }
45
- throw createRestError(response);
46
- }
47
- ```
48
-
49
- ## Serializers
50
-
51
- ```ts src/models/internal/serializers.ts function jsonFileWithHttpPartSpecificContentTypeRequestToApplicationTransform
52
- export function jsonFileWithHttpPartSpecificContentTypeRequestToApplicationTransform(
53
- input_?: any,
54
- ): FileWithHttpPartSpecificContentTypeRequest {
55
- if (!input_) {
56
- return input_ as any;
57
- }
58
- return {
59
- profileImage: jsonFileSpecificContentTypeToApplicationTransform(input_.profileImage),
60
- }!;
61
- }
62
- ```
63
-
64
- ```ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform
65
- export function jsonFileSpecificContentTypeToApplicationTransform(
66
- input_?: any,
67
- ): FileSpecificContentType {
68
- if (!input_) {
69
- return input_ as any;
70
- }
71
- return {
72
- filename: input_.filename,
73
- contentType: input_.contentType,
74
- contents: input_.contents,
75
- }!;
76
- }
77
- ```
78
-
79
- ```ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform
80
- export function jsonFileSpecificContentTypeToTransportTransform(
81
- input_?: FileSpecificContentType | null,
82
- ): any {
83
- if (!input_) {
84
- return input_ as any;
85
- }
86
- return {
87
- filename: input_.filename,
88
- contentType: input_.contentType,
89
- contents: input_.contents,
90
- }!;
91
- }
92
- ```
@@ -1,55 +0,0 @@
1
- # Tests content-type: multipart/form-data for non string
2
-
3
- ## Spec
4
-
5
- ```tsp
6
- namespace Test;
7
- @post
8
- @route("/non-string-float")
9
- op float(
10
- @header contentType: "multipart/form-data",
11
- @multipartBody body: {
12
- temperature: HttpPart<{
13
- @body body: float64;
14
- @header contentType: "text/plain";
15
- }>;
16
- },
17
- ): NoContentResponse;
18
- ```
19
-
20
- ## Operation
21
-
22
- ```ts src/api/testClientOperations.ts function float
23
- export async function float(
24
- client: TestClientContext,
25
- body: {
26
- temperature: {
27
- body: number;
28
- contentType: "text/plain";
29
- };
30
- },
31
- options?: FloatOptions,
32
- ): Promise<void> {
33
- const path = parse("/non-string-float").expand({});
34
- const httpRequestOptions = {
35
- headers: {
36
- "content-type": options?.contentType ?? "multipart/form-data",
37
- },
38
- body: [
39
- {
40
- name: "temperature",
41
- body: body.temperature.body,
42
- },
43
- ],
44
- };
45
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
46
-
47
- if (typeof options?.operationOptions?.onResponse === "function") {
48
- options?.operationOptions?.onResponse(response);
49
- }
50
- if (+response.status === 204 && !response.body) {
51
- return;
52
- }
53
- throw createRestError(response);
54
- }
55
- ```
@@ -1,65 +0,0 @@
1
- # Simple multipart part
2
-
3
- ```tsp
4
- namespace Test;
5
-
6
- model Foo {
7
- name: HttpPart<string>;
8
- age: HttpPart<int32>;
9
- description?: HttpPart<string>;
10
- }
11
-
12
- op doThing(@header contentType: "multipart/form-data", @multipartBody bodyParam: Foo): void;
13
- ```
14
-
15
- ## Models
16
-
17
- This basic case uses TypeSpec's `Http.File`, which specifies an optional `filename` and `contentType`.
18
-
19
- ```ts src/models/models.ts interface Foo
20
- export interface Foo {
21
- name: string;
22
- age: number;
23
- description?: string;
24
- }
25
- ```
26
-
27
- ## Operations
28
-
29
- ```ts src/api/testClientOperations.ts function doThing
30
- export async function doThing(
31
- client: TestClientContext,
32
- bodyParam: Foo,
33
- options?: DoThingOptions,
34
- ): Promise<void> {
35
- const path = parse("/").expand({});
36
- const httpRequestOptions = {
37
- headers: {
38
- "content-type": options?.contentType ?? "multipart/form-data",
39
- },
40
- body: [
41
- {
42
- name: "name",
43
- body: bodyParam.name,
44
- },
45
- {
46
- name: "age",
47
- body: bodyParam.age,
48
- },
49
- {
50
- name: "description",
51
- body: bodyParam.description,
52
- },
53
- ],
54
- };
55
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
56
-
57
- if (typeof options?.operationOptions?.onResponse === "function") {
58
- options?.operationOptions?.onResponse(response);
59
- }
60
- if (+response.status === 204 && !response.body) {
61
- return;
62
- }
63
- throw createRestError(response);
64
- }
65
- ```
@@ -1,87 +0,0 @@
1
- # Should emit an operation that has a @bodyRoot set.
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @post op create(
8
- @bodyRoot widget: {
9
- id: string;
10
- name: string;
11
- age?: string;
12
- @header foo?: string;
13
- },
14
- ): 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: {
25
- id: string;
26
- name: string;
27
- age?: string;
28
- foo?: string;
29
- },
30
- options?: CreateOptions,
31
- ): Promise<void> {
32
- const path = parse("/").expand({});
33
- const httpRequestOptions = {
34
- headers: {
35
- ...(widget.foo && { foo: widget.foo }),
36
- },
37
- body: {
38
- id: widget.id,
39
- name: widget.name,
40
- age: widget.options?.age,
41
- foo: widget.options?.foo,
42
- },
43
- };
44
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
45
-
46
- if (typeof options?.operationOptions?.onResponse === "function") {
47
- options?.operationOptions?.onResponse(response);
48
- }
49
- if (+response.status === 204 && !response.body) {
50
- return;
51
- }
52
- throw createRestError(response);
53
- }
54
- ```
55
-
56
- ## Options
57
-
58
- The options bag should like all the optional parameters of the operation
59
-
60
- ```ts src/api/testClientOperations.ts interface CreateOptions
61
- export interface CreateOptions extends OperationOptions {
62
- age?: string;
63
- foo?: string;
64
- }
65
- ```
66
-
67
- ## Client
68
-
69
- ```ts src/testClient.ts class TestClient
70
- export class TestClient {
71
- #context: TestClientContext;
72
- constructor(endpoint: string, options?: TestClientOptions) {
73
- this.#context = createTestClientContext(endpoint, options);
74
- }
75
- async create(
76
- widget: {
77
- id: string;
78
- name: string;
79
- age?: string;
80
- foo?: string;
81
- },
82
- options?: CreateOptions,
83
- ) {
84
- return create(this.#context, widget, options);
85
- }
86
- }
87
- ```
@@ -1,54 +0,0 @@
1
- # Should emit an operation that has a content type with a single possible value
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op get(@header contentType: "application/json"): int32;
8
- ```
9
-
10
- ## Operation
11
-
12
- Even when there are no parameters defined in the spec, it will have an optional options bag which contains operation options.
13
-
14
- ```ts src/api/testClientOperations.ts function get
15
- export async function get(client: TestClientContext, options?: GetOptions): Promise<number> {
16
- const path = parse("/").expand({});
17
- const httpRequestOptions = {
18
- headers: {
19
- "content-type": options?.contentType ?? "application/json",
20
- },
21
- };
22
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
23
-
24
- if (typeof options?.operationOptions?.onResponse === "function") {
25
- options?.operationOptions?.onResponse(response);
26
- }
27
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
28
- return response.body!;
29
- }
30
- throw createRestError(response);
31
- }
32
- ```
33
-
34
- ## Options
35
-
36
- ```ts src/api/testClientOperations.ts interface GetOptions
37
- export interface GetOptions extends OperationOptions {
38
- contentType?: "application/json";
39
- }
40
- ```
41
-
42
- ## Client
43
-
44
- ```ts src/testClient.ts class TestClient
45
- export class TestClient {
46
- #context: TestClientContext;
47
- constructor(endpoint: string, options?: TestClientOptions) {
48
- this.#context = createTestClientContext(endpoint, options);
49
- }
50
- async get(options?: GetOptions) {
51
- return get(this.#context, options);
52
- }
53
- }
54
- ```
@@ -1,54 +0,0 @@
1
- # Should emit an operation that has a default value
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op get(@header contentType: string = "application/json"): int32;
8
- ```
9
-
10
- ## Operation
11
-
12
- Even when there are no parameters defined in the spec, it will have an optional options bag which contains operation options.
13
-
14
- ```ts src/api/testClientOperations.ts function get
15
- export async function get(client: TestClientContext, options?: GetOptions): Promise<number> {
16
- const path = parse("/").expand({});
17
- const httpRequestOptions = {
18
- headers: {
19
- "content-type": options?.contentType ?? "application/json",
20
- },
21
- };
22
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
23
-
24
- if (typeof options?.operationOptions?.onResponse === "function") {
25
- options?.operationOptions?.onResponse(response);
26
- }
27
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
28
- return response.body!;
29
- }
30
- throw createRestError(response);
31
- }
32
- ```
33
-
34
- ## Options
35
-
36
- ```ts src/api/testClientOperations.ts interface GetOptions
37
- export interface GetOptions extends OperationOptions {
38
- contentType?: string;
39
- }
40
- ```
41
-
42
- ## Client
43
-
44
- ```ts src/testClient.ts class TestClient
45
- export class TestClient {
46
- #context: TestClientContext;
47
- constructor(endpoint: string, options?: TestClientOptions) {
48
- this.#context = createTestClientContext(endpoint, options);
49
- }
50
- async get(options?: GetOptions) {
51
- return get(this.#context, options);
52
- }
53
- }
54
- ```
@@ -1,62 +0,0 @@
1
- # Should emit an operation that has a no content type explicitly defined.
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
- model Foo {
7
- id: string;
8
- name: string;
9
- }
10
- @post op get(...Foo): void;
11
- ```
12
-
13
- ## Operation
14
-
15
- Even when there are no parameters defined in the spec, it will have an optional options bag which contains operation options.
16
-
17
- ```ts src/api/testClientOperations.ts function get
18
- export async function get(
19
- client: TestClientContext,
20
- id: string,
21
- name: string,
22
- options?: GetOptions,
23
- ): Promise<void> {
24
- const path = parse("/").expand({});
25
- const httpRequestOptions = {
26
- headers: {},
27
- body: {
28
- id: id,
29
- name: name,
30
- },
31
- };
32
- const response = await client.pathUnchecked(path).post(httpRequestOptions);
33
-
34
- if (typeof options?.operationOptions?.onResponse === "function") {
35
- options?.operationOptions?.onResponse(response);
36
- }
37
- if (+response.status === 204 && !response.body) {
38
- return;
39
- }
40
- throw createRestError(response);
41
- }
42
- ```
43
-
44
- ## Options
45
-
46
- ```ts src/api/testClientOperations.ts interface GetOptions
47
- export interface GetOptions extends OperationOptions {}
48
- ```
49
-
50
- ## Client
51
-
52
- ```ts src/testClient.ts class TestClient
53
- export class TestClient {
54
- #context: TestClientContext;
55
- constructor(endpoint: string, options?: TestClientOptions) {
56
- this.#context = createTestClientContext(endpoint, options);
57
- }
58
- async get(id: string, name: string, options?: GetOptions) {
59
- return get(this.#context, id, name, options);
60
- }
61
- }
62
- ```
@@ -1,50 +0,0 @@
1
- # Should emit an operation that has no parameters
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op get(): int32;
8
- ```
9
-
10
- ## Operation
11
-
12
- Even when there are no parameters defined in the spec, it will have an optional options bag which contains operation options.
13
-
14
- ```ts src/api/testClientOperations.ts function get
15
- export async function get(client: TestClientContext, options?: GetOptions): Promise<number> {
16
- const path = parse("/").expand({});
17
- const httpRequestOptions = {
18
- headers: {},
19
- };
20
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
21
-
22
- if (typeof options?.operationOptions?.onResponse === "function") {
23
- options?.operationOptions?.onResponse(response);
24
- }
25
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
26
- return response.body!;
27
- }
28
- throw createRestError(response);
29
- }
30
- ```
31
-
32
- ## Options
33
-
34
- ```ts src/api/testClientOperations.ts interface GetOptions
35
- export interface GetOptions extends OperationOptions {}
36
- ```
37
-
38
- ## Client
39
-
40
- ```ts src/testClient.ts class TestClient
41
- export class TestClient {
42
- #context: TestClientContext;
43
- constructor(endpoint: string, options?: TestClientOptions) {
44
- this.#context = createTestClientContext(endpoint, options);
45
- }
46
- async get(options?: GetOptions) {
47
- return get(this.#context, options);
48
- }
49
- }
50
- ```
@@ -1,62 +0,0 @@
1
- # Should emit an operation that has only optional parameters
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op getWithParams(name?: string, age?: int32): int32;
8
- ```
9
-
10
- ## Operation
11
-
12
- The operation has has no required parameters so options and client should be the only ones in the signature
13
-
14
- ```ts src/api/testClientOperations.ts function getWithParams
15
- export async function getWithParams(
16
- client: TestClientContext,
17
- options?: GetWithParamsOptions,
18
- ): Promise<number> {
19
- const path = parse("/").expand({});
20
- const httpRequestOptions = {
21
- headers: {},
22
- body: {
23
- name: options?.name,
24
- age: options?.age,
25
- },
26
- };
27
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
28
-
29
- if (typeof options?.operationOptions?.onResponse === "function") {
30
- options?.operationOptions?.onResponse(response);
31
- }
32
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
33
- return response.body!;
34
- }
35
- throw createRestError(response);
36
- }
37
- ```
38
-
39
- ## Options
40
-
41
- The options bag should like all the optional parameters of the operation
42
-
43
- ```ts src/api/testClientOperations.ts interface GetWithParamsOptions
44
- export interface GetWithParamsOptions extends OperationOptions {
45
- name?: string;
46
- age?: number;
47
- }
48
- ```
49
-
50
- ## Client
51
-
52
- ```ts src/testClient.ts class TestClient
53
- export class TestClient {
54
- #context: TestClientContext;
55
- constructor(endpoint: string, options?: TestClientOptions) {
56
- this.#context = createTestClientContext(endpoint, options);
57
- }
58
- async getWithParams(options?: GetWithParamsOptions) {
59
- return getWithParams(this.#context, options);
60
- }
61
- }
62
- ```
@@ -1,58 +0,0 @@
1
- # Should emit an operation that has required parameters
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op getWithParams(@query name: string, @query age: int32): int32;
8
- ```
9
-
10
- ## Operation
11
-
12
- The operation has required parameters defined in the spec, which will be included in the options bag.
13
-
14
- ```ts src/api/testClientOperations.ts function getWithParams
15
- export async function getWithParams(
16
- client: TestClientContext,
17
- name: string,
18
- age: number,
19
- options?: GetWithParamsOptions,
20
- ): Promise<number> {
21
- const path = parse("/{?name,age}").expand({
22
- name: name,
23
- age: age,
24
- });
25
- const httpRequestOptions = {
26
- headers: {},
27
- };
28
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
29
-
30
- if (typeof options?.operationOptions?.onResponse === "function") {
31
- options?.operationOptions?.onResponse(response);
32
- }
33
- if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
34
- return response.body!;
35
- }
36
- throw createRestError(response);
37
- }
38
- ```
39
-
40
- ## Options
41
-
42
- ```ts src/api/testClientOperations.ts interface GetWithParamsOptions
43
- export interface GetWithParamsOptions extends OperationOptions {}
44
- ```
45
-
46
- ## Client
47
-
48
- ```ts src/testClient.ts class TestClient
49
- export class TestClient {
50
- #context: TestClientContext;
51
- constructor(endpoint: string, options?: TestClientOptions) {
52
- this.#context = createTestClientContext(endpoint, options);
53
- }
54
- async getWithParams(name: string, age: number, options?: GetWithParamsOptions) {
55
- return getWithParams(this.#context, name, age, options);
56
- }
57
- }
58
- ```
@@ -1,60 +0,0 @@
1
- # Should emit an operation that has parameters with reserved words
2
-
3
- ```tsp
4
- @service
5
- namespace Test;
6
-
7
- @get op get(await: string, break?: boolean): void;
8
- ```
9
-
10
- ## Operation
11
-
12
- Even when there are no parameters defined in the spec, it will have an optional options bag which contains operation options.
13
-
14
- ```ts src/api/testClientOperations.ts function get
15
- export async function get(
16
- client: TestClientContext,
17
- await_: string,
18
- options?: GetOptions,
19
- ): Promise<void> {
20
- const path = parse("/").expand({});
21
- const httpRequestOptions = {
22
- headers: {},
23
- body: {
24
- await: await_,
25
- break: options?.break_,
26
- },
27
- };
28
- const response = await client.pathUnchecked(path).get(httpRequestOptions);
29
-
30
- if (typeof options?.operationOptions?.onResponse === "function") {
31
- options?.operationOptions?.onResponse(response);
32
- }
33
- if (+response.status === 204 && !response.body) {
34
- return;
35
- }
36
- throw createRestError(response);
37
- }
38
- ```
39
-
40
- ## Options
41
-
42
- ```ts src/api/testClientOperations.ts interface GetOptions
43
- export interface GetOptions extends OperationOptions {
44
- break_?: boolean;
45
- }
46
- ```
47
-
48
- ## Client
49
-
50
- ```ts src/testClient.ts class TestClient
51
- export class TestClient {
52
- #context: TestClientContext;
53
- constructor(endpoint: string, options?: TestClientOptions) {
54
- this.#context = createTestClientContext(endpoint, options);
55
- }
56
- async get(await_: string, options?: GetOptions) {
57
- return get(this.#context, await_, options);
58
- }
59
- }
60
- ```