@typespec/http-client-js 0.4.0-dev.2 → 0.4.0-dev.4
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.
- package/.testignore +5 -0
- package/CHANGELOG.md +0 -1
- package/dist/src/components/client-operation.d.ts +4 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +64 -32
- package/dist/src/components/client-operation.js.map +1 -1
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +2 -1
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/components/http-request-options.d.ts +4 -4
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +10 -11
- package/dist/src/components/http-request-options.js.map +1 -1
- package/dist/src/components/http-request.d.ts +3 -3
- package/dist/src/components/http-request.d.ts.map +1 -1
- package/dist/src/components/http-request.js +35 -31
- package/dist/src/components/http-request.js.map +1 -1
- package/dist/src/components/http-response.d.ts +3 -3
- package/dist/src/components/http-response.d.ts.map +1 -1
- package/dist/src/components/http-response.js +11 -6
- package/dist/src/components/http-response.js.map +1 -1
- package/dist/src/components/operation-handlers/index.d.ts +3 -0
- package/dist/src/components/operation-handlers/index.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/index.js +3 -0
- package/dist/src/components/operation-handlers/index.js.map +1 -0
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts +15 -0
- package/dist/src/components/operation-handlers/operation-pipeline.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/operation-pipeline.js +28 -0
- package/dist/src/components/operation-handlers/operation-pipeline.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-item.d.ts +3 -0
- package/dist/src/components/operation-handlers/paging/page-item.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-item.js +17 -0
- package/dist/src/components/operation-handlers/paging/page-item.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-response.d.ts +10 -0
- package/dist/src/components/operation-handlers/paging/page-response.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-response.js +50 -0
- package/dist/src/components/operation-handlers/paging/page-response.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts +11 -0
- package/dist/src/components/operation-handlers/paging/page-settings.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/page-settings.js +52 -0
- package/dist/src/components/operation-handlers/paging/page-settings.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts +3 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js +170 -0
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/request-send.d.ts +12 -0
- package/dist/src/components/operation-handlers/paging/request-send.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/request-send.js +78 -0
- package/dist/src/components/operation-handlers/paging/request-send.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts +11 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.js +51 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.js.map +1 -0
- package/dist/src/components/operation-handlers/paging/util.d.ts +17 -0
- package/dist/src/components/operation-handlers/paging/util.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/paging/util.js +46 -0
- package/dist/src/components/operation-handlers/paging/util.js.map +1 -0
- package/dist/src/components/operation-handlers/types.d.ts +16 -0
- package/dist/src/components/operation-handlers/types.d.ts.map +1 -0
- package/dist/src/components/operation-handlers/types.js +1 -0
- package/dist/src/components/operation-handlers/types.js.map +1 -0
- package/dist/src/components/operation-options.d.ts +2 -0
- package/dist/src/components/operation-options.d.ts.map +1 -1
- package/dist/src/components/operation-options.js +2 -1
- package/dist/src/components/operation-options.js.map +1 -1
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/output.js +4 -0
- package/dist/src/components/output.js.map +1 -1
- package/dist/src/components/serializers.d.ts.map +1 -1
- package/dist/src/components/serializers.js +10 -1
- package/dist/src/components/serializers.js.map +1 -1
- package/dist/src/components/static-helpers/paging-helper.d.ts +5 -0
- package/dist/src/components/static-helpers/paging-helper.d.ts.map +1 -0
- package/dist/src/components/static-helpers/paging-helper.js +197 -0
- package/dist/src/components/static-helpers/paging-helper.js.map +1 -0
- package/dist/src/components/transforms/operation-transform-expression.d.ts +2 -2
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +2 -1
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +17 -2
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/client-operation.tsx +37 -13
- package/src/components/client.tsx +2 -1
- package/src/components/http-request-options.tsx +11 -12
- package/src/components/http-request.tsx +22 -21
- package/src/components/http-response.tsx +8 -9
- package/src/components/operation-handlers/index.tsx +2 -0
- package/src/components/operation-handlers/operation-pipeline.tsx +33 -0
- package/src/components/operation-handlers/paging/page-item.tsx +13 -0
- package/src/components/operation-handlers/paging/page-response.tsx +55 -0
- package/src/components/operation-handlers/paging/page-settings.tsx +53 -0
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +192 -0
- package/src/components/operation-handlers/paging/request-send.tsx +70 -0
- package/src/components/operation-handlers/paging/response-deserialize.tsx +54 -0
- package/src/components/operation-handlers/paging/util.ts +70 -0
- package/src/components/operation-handlers/types.tsx +18 -0
- package/src/components/operation-options.tsx +6 -3
- package/src/components/output.tsx +2 -1
- package/src/components/serializers.tsx +14 -1
- package/src/components/static-helpers/paging-helper.tsx +195 -0
- package/src/components/transforms/operation-transform-expression.tsx +3 -3
- package/src/emitter.tsx +2 -0
- package/src/lib.ts +6 -0
- package/test/e2e/http/parameters/collection-format/main.test.ts +0 -5
- package/test/e2e/http/payload/multipart/main.test.ts +1 -1
- package/test/e2e/http/payload/pageable/main.test.ts +78 -22
- package/test/scenarios/http-operations/paging.md +244 -0
- package/test/scenarios/multipart/file_content_type.md +15 -0
- package/test/scenarios/serializers/file.md +67 -0
- package/tsconfig.test.json +2 -1
|
@@ -2,7 +2,7 @@ import * as ts from "@alloy-js/typescript";
|
|
|
2
2
|
import { Type } from "@typespec/compiler";
|
|
3
3
|
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
4
4
|
import { HasName, TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
5
|
-
import {
|
|
5
|
+
import { HttpOperation } from "@typespec/http";
|
|
6
6
|
import { reportDiagnostic } from "../../lib.js";
|
|
7
7
|
import { ContentTypeEncodingProvider } from "./content-type-encoding-provider.jsx";
|
|
8
8
|
import { JsonTransform } from "./json/json-transform.jsx";
|
|
@@ -10,11 +10,11 @@ import { MultipartTransform } from "./multipart/multipart-transform.jsx";
|
|
|
10
10
|
import { defaultTransportNameGetter } from "./transform-name-policy.js";
|
|
11
11
|
|
|
12
12
|
export interface OperationTransformToTransportExpression {
|
|
13
|
-
|
|
13
|
+
httpOperation: HttpOperation;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function OperationTransformExpression(props: OperationTransformToTransportExpression) {
|
|
17
|
-
const body = props.
|
|
17
|
+
const body = props.httpOperation.parameters.body;
|
|
18
18
|
|
|
19
19
|
if (!body) {
|
|
20
20
|
return;
|
package/src/emitter.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { Output } from "./components/output.jsx";
|
|
|
9
9
|
import { ModelSerializers } from "./components/serializers.js";
|
|
10
10
|
import { Interfaces } from "./components/static-helpers/interfaces.jsx";
|
|
11
11
|
import { MultipartHelpers } from "./components/static-helpers/multipart-helpers.jsx";
|
|
12
|
+
import { PagingHelpers } from "./components/static-helpers/paging-helper.jsx";
|
|
12
13
|
import { RestError } from "./components/static-helpers/rest-error.jsx";
|
|
13
14
|
import { JsClientEmitterOptions } from "./lib.js";
|
|
14
15
|
|
|
@@ -41,6 +42,7 @@ export async function $onEmit(context: EmitContext<JsClientEmitterOptions>) {
|
|
|
41
42
|
<OperationsDirectory />
|
|
42
43
|
</ay.SourceDirectory>
|
|
43
44
|
<ay.SourceDirectory path="helpers">
|
|
45
|
+
<PagingHelpers />
|
|
44
46
|
<Interfaces />
|
|
45
47
|
<MultipartHelpers />
|
|
46
48
|
<ts.SourceFile path="error.ts">
|
package/src/lib.ts
CHANGED
|
@@ -107,6 +107,12 @@ export const $lib = createTypeSpecLibrary({
|
|
|
107
107
|
default: "Unexpected non-scalar type when trying to extract Scalar data",
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
|
+
"client-not-found": {
|
|
111
|
+
severity: "error",
|
|
112
|
+
messages: {
|
|
113
|
+
default: "Client for operation not found",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
110
116
|
},
|
|
111
117
|
});
|
|
112
118
|
|
|
@@ -18,11 +18,6 @@ describe("Parameters.CollectionFormat", () => {
|
|
|
18
18
|
// Assert successful request
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it.skip("should test sending a tsv collection format array query parameters", async () => {
|
|
22
|
-
await client.tsv(["blue", "red", "green"]);
|
|
23
|
-
// Assert successful request
|
|
24
|
-
});
|
|
25
|
-
|
|
26
21
|
it.skip("should test sending a pipes collection format array query parameters", async () => {
|
|
27
22
|
await client.pipes(["blue", "red", "green"]);
|
|
28
23
|
// Assert successful request
|
|
@@ -1,24 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
Pet,
|
|
4
|
+
ServerDrivenPaginationClient,
|
|
5
|
+
} from "../../../generated/payload/pageable/src/index.js";
|
|
4
6
|
|
|
5
|
-
describe
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
describe("Payload.Pageable", () => {
|
|
8
|
+
describe("list", () => {
|
|
9
|
+
const client = new ServerDrivenPaginationClient({
|
|
10
|
+
allowInsecureConnection: true,
|
|
11
|
+
});
|
|
12
|
+
const pets = [
|
|
13
|
+
{ id: "1", name: "dog" },
|
|
14
|
+
{ id: "2", name: "cat" },
|
|
15
|
+
{ id: "3", name: "bird" },
|
|
16
|
+
{ id: "4", name: "fish" },
|
|
17
|
+
];
|
|
18
|
+
it("Payload Pageable ServerDriven Pagination link", async () => {
|
|
19
|
+
const iter = client.link();
|
|
20
|
+
const items: Array<Pet> = [];
|
|
21
|
+
for await (const user of iter) {
|
|
22
|
+
items.push(user);
|
|
23
|
+
}
|
|
24
|
+
expect(items.length).toEqual(4);
|
|
25
|
+
expect(items).toStrictEqual(pets);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("continuation token for requestHeaderResponseBody", async () => {
|
|
29
|
+
const iter = client.continuationTokenClient.requestHeaderResponseBody({
|
|
30
|
+
bar: "bar",
|
|
31
|
+
foo: "foo",
|
|
32
|
+
});
|
|
33
|
+
const items: Array<Pet> = [];
|
|
34
|
+
for await (const user of iter) {
|
|
35
|
+
items.push(user);
|
|
36
|
+
}
|
|
37
|
+
expect(items.length).toEqual(4);
|
|
38
|
+
expect(items).toStrictEqual(pets);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("continuation token for requestQueryResponseBody", async () => {
|
|
42
|
+
const iter = client.continuationTokenClient.requestQueryResponseBody({
|
|
43
|
+
bar: "bar",
|
|
44
|
+
foo: "foo",
|
|
45
|
+
});
|
|
46
|
+
const items: Array<Pet> = [];
|
|
47
|
+
for await (const user of iter) {
|
|
48
|
+
items.push(user);
|
|
49
|
+
}
|
|
50
|
+
expect(items.length).toEqual(4);
|
|
51
|
+
expect(items).toStrictEqual(pets);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("continuation token for requestHeaderResponseHeader", async () => {
|
|
55
|
+
const iter = client.continuationTokenClient.requestHeaderResponseHeader({
|
|
56
|
+
bar: "bar",
|
|
57
|
+
foo: "foo",
|
|
58
|
+
});
|
|
59
|
+
const items: Array<Pet> = [];
|
|
60
|
+
for await (const user of iter) {
|
|
61
|
+
items.push(user);
|
|
62
|
+
}
|
|
63
|
+
expect(items.length).toEqual(4);
|
|
64
|
+
expect(items).toStrictEqual(pets);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("continuation token for requestQueryResponseHeader", async () => {
|
|
68
|
+
const iter = client.continuationTokenClient.requestQueryResponseHeader({
|
|
69
|
+
bar: "bar",
|
|
70
|
+
foo: "foo",
|
|
71
|
+
});
|
|
72
|
+
const items: Array<Pet> = [];
|
|
73
|
+
for await (const user of iter) {
|
|
74
|
+
items.push(user);
|
|
75
|
+
}
|
|
76
|
+
expect(items.length).toEqual(4);
|
|
77
|
+
expect(items).toStrictEqual(pets);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
24
80
|
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Should emit a paging operation if it is continuationToken paging pattern
|
|
2
|
+
|
|
3
|
+
```tsp
|
|
4
|
+
@service
|
|
5
|
+
namespace Test;
|
|
6
|
+
model Pet {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@route("/link")
|
|
12
|
+
@list
|
|
13
|
+
op link(@query filter: string, @continuationToken @query nextToken?: string): {
|
|
14
|
+
@pageItems
|
|
15
|
+
pets: Pet[];
|
|
16
|
+
|
|
17
|
+
@continuationToken @header nextToken?: string;
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Operation
|
|
22
|
+
|
|
23
|
+
```ts src/api/testClientOperations.ts function link
|
|
24
|
+
export function link(
|
|
25
|
+
client: TestClientContext,
|
|
26
|
+
filter: string,
|
|
27
|
+
options?: LinkOptions,
|
|
28
|
+
): PagedAsyncIterableIterator<Pet, LinkPageResponse, LinkPageSettings> {
|
|
29
|
+
function getElements(response: LinkPageResponse) {
|
|
30
|
+
return response.pets;
|
|
31
|
+
}
|
|
32
|
+
async function getPagedResponse(nextToken?: string, settings?: LinkPageSettings) {
|
|
33
|
+
const combinedOptions = { ...options, ...settings };
|
|
34
|
+
|
|
35
|
+
if (nextToken) {
|
|
36
|
+
combinedOptions.nextToken = nextToken;
|
|
37
|
+
}
|
|
38
|
+
const response = await linkSend(client, filter, combinedOptions);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
pagedResponse: await linkDeserialize(response, options),
|
|
42
|
+
nextToken: response.headers["next-token"],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return buildPagedAsyncIterator<Pet, LinkPageResponse, LinkPageSettings>({
|
|
46
|
+
getElements,
|
|
47
|
+
getPagedResponse,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts src/api/testClientOperations.ts function linkSend
|
|
53
|
+
async function linkSend(client: TestClientContext, filter: string, options?: Record<string, any>) {
|
|
54
|
+
const path = parse("/link{?filter,nextToken}").expand({
|
|
55
|
+
filter: filter,
|
|
56
|
+
...(options?.nextToken && { nextToken: options.nextToken }),
|
|
57
|
+
});
|
|
58
|
+
const httpRequestOptions = {
|
|
59
|
+
headers: {},
|
|
60
|
+
};
|
|
61
|
+
return await client.pathUnchecked(path).get(httpRequestOptions);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```ts src/api/testClientOperations.ts function linkDeserialize
|
|
66
|
+
function linkDeserialize(response: PathUncheckedResponse, options?: LinkOptions) {
|
|
67
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
68
|
+
options?.operationOptions?.onResponse(response);
|
|
69
|
+
}
|
|
70
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
71
|
+
return {
|
|
72
|
+
pets: jsonArrayPetToApplicationTransform(response.body.pets),
|
|
73
|
+
}!;
|
|
74
|
+
}
|
|
75
|
+
throw createRestError(response);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Options
|
|
80
|
+
|
|
81
|
+
The options bag should like all the optional parameters of the operation
|
|
82
|
+
|
|
83
|
+
```ts src/api/testClientOperations.ts interface LinkOptions
|
|
84
|
+
export interface LinkOptions extends OperationOptions {}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## PageSettings
|
|
88
|
+
|
|
89
|
+
Page settings and will be used as input for byPage function.
|
|
90
|
+
|
|
91
|
+
```ts src/api/testClientOperations.ts interface LinkPageSettings
|
|
92
|
+
export interface LinkPageSettings {
|
|
93
|
+
nextToken?: string;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## LinkPageResponse
|
|
98
|
+
|
|
99
|
+
Page responses and will be used as output for byPage function.
|
|
100
|
+
|
|
101
|
+
```ts src/api/testClientOperations.ts interface LinkPageResponse
|
|
102
|
+
export interface LinkPageResponse {
|
|
103
|
+
pets: Array<Pet>;
|
|
104
|
+
nextToken?: string;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Client
|
|
109
|
+
|
|
110
|
+
```ts src/testClient.ts class TestClient
|
|
111
|
+
export class TestClient {
|
|
112
|
+
#context: TestClientContext;
|
|
113
|
+
|
|
114
|
+
constructor(endpoint: string, options?: TestClientOptions) {
|
|
115
|
+
this.#context = createTestClientContext(endpoint, options);
|
|
116
|
+
}
|
|
117
|
+
link(filter: string, options?: LinkOptions) {
|
|
118
|
+
return link(this.#context, filter, options);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
# Should emit a paging operation if it is nextLink paging pattern
|
|
124
|
+
|
|
125
|
+
```tsp
|
|
126
|
+
@service
|
|
127
|
+
namespace Test;
|
|
128
|
+
model Pet {
|
|
129
|
+
id: string;
|
|
130
|
+
name: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@route("/link")
|
|
134
|
+
@list
|
|
135
|
+
op link(@query filter: string, @pageSize @query maxPageSize?: int32): {
|
|
136
|
+
@pageItems
|
|
137
|
+
pets: Pet[];
|
|
138
|
+
|
|
139
|
+
@nextLink link?: string;
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Operation
|
|
144
|
+
|
|
145
|
+
```ts src/api/testClientOperations.ts function link
|
|
146
|
+
export function link(
|
|
147
|
+
client: TestClientContext,
|
|
148
|
+
filter: string,
|
|
149
|
+
options?: LinkOptions,
|
|
150
|
+
): PagedAsyncIterableIterator<Pet, LinkPageResponse, LinkPageSettings> {
|
|
151
|
+
function getElements(response: LinkPageResponse) {
|
|
152
|
+
return response.pets;
|
|
153
|
+
}
|
|
154
|
+
async function getPagedResponse(nextToken?: string, settings?: LinkPageSettings) {
|
|
155
|
+
let response: PathUncheckedResponse;
|
|
156
|
+
if (nextToken) {
|
|
157
|
+
response = await client.pathUnchecked(nextToken).get();
|
|
158
|
+
} else {
|
|
159
|
+
const combinedOptions = { ...options, ...settings };
|
|
160
|
+
response = await linkSend(client, filter, combinedOptions);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
pagedResponse: await linkDeserialize(response, options),
|
|
164
|
+
nextToken: response.body["link"],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return buildPagedAsyncIterator<Pet, LinkPageResponse, LinkPageSettings>({
|
|
168
|
+
getElements,
|
|
169
|
+
getPagedResponse,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```ts src/api/testClientOperations.ts function linkSend
|
|
175
|
+
async function linkSend(client: TestClientContext, filter: string, options?: Record<string, any>) {
|
|
176
|
+
const path = parse("/link{?filter,maxPageSize}").expand({
|
|
177
|
+
filter: filter,
|
|
178
|
+
...(options?.maxPageSize && { maxPageSize: options.maxPageSize }),
|
|
179
|
+
});
|
|
180
|
+
const httpRequestOptions = {
|
|
181
|
+
headers: {},
|
|
182
|
+
};
|
|
183
|
+
return await client.pathUnchecked(path).get(httpRequestOptions);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```ts src/api/testClientOperations.ts function linkDeserialize
|
|
188
|
+
function linkDeserialize(response: PathUncheckedResponse, options?: LinkOptions) {
|
|
189
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
190
|
+
options?.operationOptions?.onResponse(response);
|
|
191
|
+
}
|
|
192
|
+
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
193
|
+
return {
|
|
194
|
+
pets: jsonArrayPetToApplicationTransform(response.body.pets),
|
|
195
|
+
link: response.body.link,
|
|
196
|
+
}!;
|
|
197
|
+
}
|
|
198
|
+
throw createRestError(response);
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Options
|
|
203
|
+
|
|
204
|
+
The options bag should like all the optional parameters of the operation
|
|
205
|
+
|
|
206
|
+
```ts src/api/testClientOperations.ts interface LinkOptions
|
|
207
|
+
export interface LinkOptions extends OperationOptions {}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## PageSettings
|
|
211
|
+
|
|
212
|
+
Page settings and will be used as input for byPage function.
|
|
213
|
+
|
|
214
|
+
```ts src/api/testClientOperations.ts interface LinkPageSettings
|
|
215
|
+
export interface LinkPageSettings {
|
|
216
|
+
maxPageSize?: number;
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## LinkPageResponse
|
|
221
|
+
|
|
222
|
+
Page responses and will be used as output for byPage function.
|
|
223
|
+
|
|
224
|
+
```ts src/api/testClientOperations.ts interface LinkPageResponse
|
|
225
|
+
export interface LinkPageResponse {
|
|
226
|
+
pets: Array<Pet>;
|
|
227
|
+
link?: string;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Client
|
|
232
|
+
|
|
233
|
+
```ts src/testClient.ts class TestClient
|
|
234
|
+
export class TestClient {
|
|
235
|
+
#context: TestClientContext;
|
|
236
|
+
|
|
237
|
+
constructor(endpoint: string, options?: TestClientOptions) {
|
|
238
|
+
this.#context = createTestClientContext(endpoint, options);
|
|
239
|
+
}
|
|
240
|
+
link(filter: string, options?: LinkOptions) {
|
|
241
|
+
return link(this.#context, filter, options);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
@@ -75,3 +75,18 @@ export function jsonFileSpecificContentTypeToApplicationTransform(
|
|
|
75
75
|
}!;
|
|
76
76
|
}
|
|
77
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
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Should handle File Parts
|
|
2
|
+
|
|
3
|
+
```tsp
|
|
4
|
+
namespace Test;
|
|
5
|
+
|
|
6
|
+
model FileSpecificContentType extends File {
|
|
7
|
+
filename: string;
|
|
8
|
+
contentType: "image/jpg";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
model FileWithHttpPartSpecificContentTypeRequest {
|
|
12
|
+
profileImage: HttpPart<FileSpecificContentType>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@post
|
|
16
|
+
op imageJpegContentType(
|
|
17
|
+
@header contentType: "multipart/form-data",
|
|
18
|
+
@multipartBody body: FileWithHttpPartSpecificContentTypeRequest,
|
|
19
|
+
): NoContentResponse;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Serializers
|
|
23
|
+
|
|
24
|
+
```ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform
|
|
25
|
+
export function jsonFileSpecificContentTypeToApplicationTransform(
|
|
26
|
+
input_?: any,
|
|
27
|
+
): FileSpecificContentType {
|
|
28
|
+
if (!input_) {
|
|
29
|
+
return input_ as any;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
filename: input_.filename,
|
|
33
|
+
contentType: input_.contentType,
|
|
34
|
+
contents: input_.contents,
|
|
35
|
+
}!;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts src/models/internal/serializers.ts function jsonFileSpecificContentTypeToTransportTransform
|
|
40
|
+
export function jsonFileSpecificContentTypeToTransportTransform(
|
|
41
|
+
input_?: FileSpecificContentType | null,
|
|
42
|
+
): any {
|
|
43
|
+
if (!input_) {
|
|
44
|
+
return input_ as any;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
filename: input_.filename,
|
|
48
|
+
contentType: input_.contentType,
|
|
49
|
+
contents: input_.contents,
|
|
50
|
+
}!;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
It shouldn't try to base64 encode the contents
|
|
55
|
+
|
|
56
|
+
```ts src/models/internal/serializers.ts function jsonFileToTransportTransform
|
|
57
|
+
export function jsonFileToTransportTransform(input_?: File | null): any {
|
|
58
|
+
if (!input_) {
|
|
59
|
+
return input_ as any;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
contentType: input_.contentType,
|
|
63
|
+
filename: input_.filename,
|
|
64
|
+
contents: input_.contents,
|
|
65
|
+
}!;
|
|
66
|
+
}
|
|
67
|
+
```
|