@typespec/http-client-js 0.6.0-dev.5 → 0.6.0
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/CHANGELOG.md +18 -0
- package/dist/src/components/client-context/client-context-factory.js +1 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +8 -4
- package/dist/src/components/client.js +3 -3
- package/dist/src/components/external-packages/ts-http-runtime.d.ts +2 -2
- package/dist/src/components/external-packages/ts-http-runtime.d.ts.map +1 -1
- package/dist/src/components/external-packages/uri-template.d.ts +2 -2
- package/dist/src/components/external-packages/uri-template.d.ts.map +1 -1
- package/dist/src/components/http-request-options.d.ts +3 -1
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +5 -3
- package/dist/src/components/http-request.d.ts +3 -1
- package/dist/src/components/http-request.d.ts.map +1 -1
- package/dist/src/components/http-request.js +14 -8
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/paginated-operation-handler.js +3 -2
- package/dist/src/components/operation-handlers/paging/request-send.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/request-send.js +15 -8
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts +1 -0
- package/dist/src/components/operation-handlers/paging/response-deserialize.d.ts.map +1 -1
- package/dist/src/components/operation-handlers/paging/response-deserialize.js +5 -2
- package/dist/src/components/operation-parameters.d.ts +1 -2
- package/dist/src/components/operation-parameters.d.ts.map +1 -1
- package/dist/src/components/operation-parameters.js +3 -6
- package/dist/src/components/transforms/operation-transform-declaration.d.ts +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.js +2 -5
- package/dist/src/utils/parameters.d.ts +2 -1
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +6 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/src/components/client-context/client-context-factory.tsx +1 -1
- package/src/components/client-operation.tsx +15 -3
- package/src/components/client.tsx +3 -3
- package/src/components/http-request-options.tsx +9 -5
- package/src/components/http-request.tsx +17 -9
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +7 -2
- package/src/components/operation-handlers/paging/request-send.tsx +26 -11
- package/src/components/operation-handlers/paging/response-deserialize.tsx +6 -2
- package/src/components/operation-parameters.tsx +6 -7
- package/src/components/transforms/operation-transform-declaration.tsx +2 -5
- package/src/utils/parameters.tsx +9 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://typespec.io",
|
|
6
6
|
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
|
|
@@ -30,27 +30,22 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@typespec/compiler": "^1.
|
|
34
|
-
"@typespec/http": "^1.0
|
|
35
|
-
"@typespec/rest": "^0.
|
|
33
|
+
"@typespec/compiler": "^1.1.0",
|
|
34
|
+
"@typespec/http": "^1.1.0",
|
|
35
|
+
"@typespec/rest": "^0.71.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@alloy-js/core": "^0.
|
|
39
|
-
"@alloy-js/typescript": "^0.
|
|
40
|
-
"
|
|
41
|
-
"@typespec/
|
|
42
|
-
"
|
|
38
|
+
"@alloy-js/core": "^0.17.0",
|
|
39
|
+
"@alloy-js/typescript": "^0.17.0",
|
|
40
|
+
"prettier": "~3.5.3",
|
|
41
|
+
"@typespec/emitter-framework": "^0.8.0",
|
|
42
|
+
"@typespec/http-client": "^0.7.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@alloy-js/cli": "^0.
|
|
45
|
+
"@alloy-js/cli": "^0.17.0",
|
|
46
46
|
"@alloy-js/rollup-plugin": "^0.1.0",
|
|
47
47
|
"@types/yargs": "~17.0.33",
|
|
48
|
-
"@typespec/http": "^1.0.1",
|
|
49
|
-
"@typespec/http-specs": "^0.1.0-alpha.22 || >=0.1.0-alpha.23-dev <0.1.0-alpha.23",
|
|
50
|
-
"@typespec/spector": "^0.1.0-alpha.14 || >=0.1.0-alpha.15-dev <0.1.0-alpha.15",
|
|
51
48
|
"@typespec/ts-http-runtime": "0.2.2",
|
|
52
|
-
"@typespec/tspd": "^0.70.0 || >=0.71.0-dev <0.71.0",
|
|
53
|
-
"@typespec/versioning": "^0.70.0 || >=0.71.0-dev <0.71.0",
|
|
54
49
|
"@vitest/ui": "^3.1.2",
|
|
55
50
|
"change-case": "~5.4.4",
|
|
56
51
|
"concurrently": "^9.1.2",
|
|
@@ -65,7 +60,12 @@
|
|
|
65
60
|
"typescript": "~5.8.2",
|
|
66
61
|
"uri-template": "^2.0.0",
|
|
67
62
|
"vitest": "^3.1.2",
|
|
68
|
-
"yargs": "~17.7.2"
|
|
63
|
+
"yargs": "~17.7.2",
|
|
64
|
+
"@typespec/http": "^1.1.0",
|
|
65
|
+
"@typespec/spector": "^0.1.0-alpha.15",
|
|
66
|
+
"@typespec/tspd": "^0.71.0",
|
|
67
|
+
"@typespec/http-specs": "^0.1.0-alpha.23",
|
|
68
|
+
"@typespec/versioning": "^0.71.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "alloy build",
|
|
@@ -27,7 +27,7 @@ export function ClientContextFactoryDeclaration(props: ClientContextFactoryProps
|
|
|
27
27
|
const factoryFunctionName = namePolicy.getName(`create_${props.client.name}Context`, "function");
|
|
28
28
|
|
|
29
29
|
const clientConstructor = $.client.getConstructor(props.client);
|
|
30
|
-
const parameters = buildClientParameters(props.client);
|
|
30
|
+
const parameters = buildClientParameters(props.client, ay.refkey());
|
|
31
31
|
const urlTemplate = $.client.getUrlTemplate(props.client);
|
|
32
32
|
const endpointRef = ay.refkey();
|
|
33
33
|
const resolvedEndpoint = (
|
|
@@ -46,8 +46,13 @@ export interface ClientOperationProps {
|
|
|
46
46
|
internal?: boolean;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
function getClientOperationOptionsParamRef(httpOperation: HttpOperation): ay.Refkey {
|
|
50
|
+
return ay.refkey(httpOperation, "client-operation-options-parameter");
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
export function ClientOperation(props: ClientOperationProps) {
|
|
50
54
|
const { $ } = useTsp();
|
|
55
|
+
const optionsRefkey = getClientOperationOptionsParamRef(props.httpOperation);
|
|
51
56
|
const clientLibrary = cl.useClientLibrary();
|
|
52
57
|
const client = clientLibrary.getClientForOperation(props.httpOperation);
|
|
53
58
|
|
|
@@ -63,8 +68,11 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
63
68
|
const responseRefkey = ay.refkey(props.httpOperation, "http-response");
|
|
64
69
|
const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
|
|
65
70
|
const signatureParams: ts.ParameterDescriptor[] = [
|
|
66
|
-
{
|
|
67
|
-
|
|
71
|
+
{
|
|
72
|
+
name: "client",
|
|
73
|
+
type: clientContextInterfaceRef,
|
|
74
|
+
},
|
|
75
|
+
...getOperationParameters(props.httpOperation, optionsRefkey),
|
|
68
76
|
];
|
|
69
77
|
return (
|
|
70
78
|
<ay.List hardline>
|
|
@@ -79,7 +87,11 @@ export function ClientOperation(props: ClientOperationProps) {
|
|
|
79
87
|
refkey={props.refkey}
|
|
80
88
|
>
|
|
81
89
|
<ay.List hardline>
|
|
82
|
-
<HttpRequest
|
|
90
|
+
<HttpRequest
|
|
91
|
+
httpOperation={props.httpOperation}
|
|
92
|
+
responseRefkey={responseRefkey}
|
|
93
|
+
operationOptionsParamRefkey={optionsRefkey}
|
|
94
|
+
/>
|
|
83
95
|
<HttpResponse httpOperation={props.httpOperation} responseRefkey={responseRefkey} />
|
|
84
96
|
</ay.List>
|
|
85
97
|
</FunctionDeclaration>
|
|
@@ -69,7 +69,7 @@ export function ClientClass(props: ClientClassProps) {
|
|
|
69
69
|
<ClientConstructor client={props.client} />
|
|
70
70
|
<ay.For each={operations} hardline semicolon>
|
|
71
71
|
{(op) => {
|
|
72
|
-
const parameters = getOperationParameters(op.httpOperation);
|
|
72
|
+
const parameters = getOperationParameters(op.httpOperation, ay.refkey());
|
|
73
73
|
const args = parameters.flatMap((p) => p.refkey);
|
|
74
74
|
const isPaging = Boolean($.operation.getPagingMetadata(op.httpOperation.operation));
|
|
75
75
|
|
|
@@ -131,7 +131,7 @@ function ClientConstructor(props: ClientConstructorProps) {
|
|
|
131
131
|
);
|
|
132
132
|
const clientContextFieldRef = getClientContextFieldRef(props.client);
|
|
133
133
|
const clientContextFactoryRef = getClientContextFactoryRef(props.client);
|
|
134
|
-
const constructorParameters = buildClientParameters(props.client);
|
|
134
|
+
const constructorParameters = buildClientParameters(props.client, ay.refkey());
|
|
135
135
|
const args = Object.values(constructorParameters).map((p) => p.refkey);
|
|
136
136
|
|
|
137
137
|
return (
|
|
@@ -154,7 +154,7 @@ function ClientConstructor(props: ClientConstructorProps) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
function calculateSubClientArgs(subClient: cl.Client, parentParams: ts.ParameterDescriptor[]) {
|
|
157
|
-
const subClientParams = buildClientParameters(subClient).map((p) => p.name);
|
|
157
|
+
const subClientParams = buildClientParameters(subClient, ay.refkey()).map((p) => p.name);
|
|
158
158
|
return parentParams
|
|
159
159
|
.filter(({ name }) => subClientParams.includes(name))
|
|
160
160
|
.flatMap((p) => (p.refkey ? p.refkey : []));
|
|
@@ -3,20 +3,23 @@ import * as ts from "@alloy-js/typescript";
|
|
|
3
3
|
import { HttpOperation } from "@typespec/http";
|
|
4
4
|
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
5
5
|
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.jsx";
|
|
6
|
-
import { getOperationOptionsParameterRefkey } from "./operation-parameters.jsx";
|
|
7
6
|
import { OperationTransformExpression } from "./transforms/operation-transform-expression.jsx";
|
|
8
7
|
|
|
9
8
|
export interface HttpRequestOptionsProps {
|
|
10
9
|
httpOperation: HttpOperation;
|
|
11
|
-
|
|
10
|
+
requestOptionsParamRefkey: Refkey;
|
|
11
|
+
requestOptionsVarRefkey: Refkey;
|
|
12
12
|
children?: Children;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function HttpRequestOptions(props: HttpRequestOptionsProps) {
|
|
16
16
|
return (
|
|
17
|
-
<ts.VarDeclaration name="httpRequestOptions" refkey={props.
|
|
17
|
+
<ts.VarDeclaration name="httpRequestOptions" refkey={props.requestOptionsVarRefkey}>
|
|
18
18
|
<ts.ObjectExpression>
|
|
19
|
-
<HttpRequestOptions.Headers
|
|
19
|
+
<HttpRequestOptions.Headers
|
|
20
|
+
httpOperation={props.httpOperation}
|
|
21
|
+
requestOptionsParamRefkey={props.requestOptionsParamRefkey}
|
|
22
|
+
/>
|
|
20
23
|
<HttpRequestOptions.Body httpOperation={props.httpOperation} />
|
|
21
24
|
</ts.ObjectExpression>
|
|
22
25
|
</ts.VarDeclaration>
|
|
@@ -25,6 +28,7 @@ export function HttpRequestOptions(props: HttpRequestOptionsProps) {
|
|
|
25
28
|
|
|
26
29
|
export interface HttpRequestOptionsHeadersProps {
|
|
27
30
|
httpOperation: HttpOperation;
|
|
31
|
+
requestOptionsParamRefkey: Refkey;
|
|
28
32
|
children?: Children;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -37,7 +41,7 @@ HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
|
|
|
37
41
|
(p) => p.kind === "header" || p.kind === "contentType",
|
|
38
42
|
);
|
|
39
43
|
|
|
40
|
-
const optionsParam =
|
|
44
|
+
const optionsParam = props.requestOptionsParamRefkey;
|
|
41
45
|
return (
|
|
42
46
|
<EncodingProvider defaults={{ bytes: "base64", datetime: "rfc7231" }}>
|
|
43
47
|
<ts.ObjectProperty name="headers">
|
|
@@ -6,28 +6,36 @@ import { EncodingProvider } from "./encoding-provider.jsx";
|
|
|
6
6
|
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
7
7
|
import { HttpRequestOptions } from "./http-request-options.js";
|
|
8
8
|
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.js";
|
|
9
|
-
import { getOperationOptionsParameterRefkey } from "./operation-parameters.jsx";
|
|
10
9
|
|
|
11
10
|
export interface HttpRequestProps {
|
|
12
11
|
httpOperation: HttpOperation;
|
|
12
|
+
operationOptionsParamRefkey: Refkey;
|
|
13
13
|
responseRefkey?: Refkey;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function HttpRequest(props: HttpRequestProps) {
|
|
17
17
|
const operationUrlRefkey = refkey();
|
|
18
|
-
const
|
|
18
|
+
const requestOptionsVarRefkey = refkey();
|
|
19
19
|
const httpResponseRefkey = props.responseRefkey ?? refkey();
|
|
20
20
|
const verb = props.httpOperation.verb;
|
|
21
21
|
return (
|
|
22
22
|
<List>
|
|
23
23
|
<StatementList>
|
|
24
|
-
<HttpRequest.Url
|
|
24
|
+
<HttpRequest.Url
|
|
25
|
+
httpOperation={props.httpOperation}
|
|
26
|
+
pathVarRefkey={operationUrlRefkey}
|
|
27
|
+
requestOptionsParamRefkey={props.operationOptionsParamRefkey}
|
|
28
|
+
/>
|
|
25
29
|
|
|
26
|
-
<HttpRequestOptions
|
|
30
|
+
<HttpRequestOptions
|
|
31
|
+
httpOperation={props.httpOperation}
|
|
32
|
+
requestOptionsParamRefkey={props.operationOptionsParamRefkey}
|
|
33
|
+
requestOptionsVarRefkey={requestOptionsVarRefkey}
|
|
34
|
+
/>
|
|
27
35
|
|
|
28
36
|
<ts.VarDeclaration name="response" refkey={httpResponseRefkey}>
|
|
29
37
|
{code`
|
|
30
|
-
await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={
|
|
38
|
+
await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={requestOptionsVarRefkey} />)})
|
|
31
39
|
`}
|
|
32
40
|
</ts.VarDeclaration>
|
|
33
41
|
<hbr />
|
|
@@ -42,7 +50,8 @@ export function HttpRequest(props: HttpRequestProps) {
|
|
|
42
50
|
|
|
43
51
|
export interface HttpUrlProps {
|
|
44
52
|
httpOperation: HttpOperation;
|
|
45
|
-
|
|
53
|
+
requestOptionsParamRefkey: Refkey;
|
|
54
|
+
pathVarRefkey?: Refkey;
|
|
46
55
|
children?: Children;
|
|
47
56
|
}
|
|
48
57
|
|
|
@@ -51,15 +60,14 @@ HttpRequest.Url = function HttpUrlDeclaration(props: HttpUrlProps) {
|
|
|
51
60
|
const urlParameters = props.httpOperation.parameters.properties.filter(
|
|
52
61
|
(p) => p.kind === "path" || p.kind === "query",
|
|
53
62
|
);
|
|
54
|
-
const optionsParameter = getOperationOptionsParameterRefkey(props.httpOperation);
|
|
55
63
|
return (
|
|
56
64
|
<EncodingProvider defaults={{ bytes: "base64url" }}>
|
|
57
|
-
<ts.VarDeclaration name="path" refkey={props.
|
|
65
|
+
<ts.VarDeclaration name="path" refkey={props.pathVarRefkey}>
|
|
58
66
|
{uriTemplateLib.parse}({JSON.stringify(urlTemplate)}).expand(
|
|
59
67
|
{
|
|
60
68
|
<HttpRequestParametersExpression
|
|
61
69
|
httpOperation={props.httpOperation}
|
|
62
|
-
optionsParameter={
|
|
70
|
+
optionsParameter={props.requestOptionsParamRefkey}
|
|
63
71
|
parameters={urlParameters}
|
|
64
72
|
/>
|
|
65
73
|
}
|
|
@@ -51,9 +51,14 @@ export const PaginatedOperationHandler: OperationHandler = {
|
|
|
51
51
|
const operationRefkey = ay.refkey(httpOperation.operation);
|
|
52
52
|
const returnType = ay.code`${getPagedAsyncIterableIteratorRefkey()}<${getPageItemTypeName(pagingOperation)},${getPageResponseTypeRefkey(httpOperation)},${getPageSettingsTypeRefkey(httpOperation)}>`;
|
|
53
53
|
const clientContextInterfaceRef = getClientcontextDeclarationRef(client);
|
|
54
|
+
const optionsRefkey = ay.refkey();
|
|
54
55
|
const signatureParams: ts.ParameterDescriptor[] = [
|
|
55
|
-
{
|
|
56
|
-
|
|
56
|
+
{
|
|
57
|
+
name: "client",
|
|
58
|
+
type: clientContextInterfaceRef,
|
|
59
|
+
refkey: ay.refkey(client, "paging-operation-client-param"),
|
|
60
|
+
},
|
|
61
|
+
...getOperationParameters(httpOperation, optionsRefkey),
|
|
57
62
|
];
|
|
58
63
|
const pagingDetail = extractPagingDetail(httpOperation, pagingOperation);
|
|
59
64
|
// Exclude from operation options and include them into PageSettings
|
|
@@ -8,10 +8,7 @@ import * as cl from "@typespec/http-client";
|
|
|
8
8
|
import { getClientcontextDeclarationRef } from "../../client-context/client-context-declaration.jsx";
|
|
9
9
|
import { HttpRequestOptions } from "../../http-request-options.jsx";
|
|
10
10
|
import { HttpRequest } from "../../http-request.jsx";
|
|
11
|
-
import {
|
|
12
|
-
getOperationOptionsParameterRefkey,
|
|
13
|
-
getOperationParameters,
|
|
14
|
-
} from "../../operation-parameters.jsx";
|
|
11
|
+
import { getOperationParameters } from "../../operation-parameters.jsx";
|
|
15
12
|
|
|
16
13
|
export interface HttpRequestSendProps {
|
|
17
14
|
httpOperation: HttpOperation;
|
|
@@ -22,20 +19,29 @@ export function getHttpRequestSendRefkey(httpOperation: HttpOperation) {
|
|
|
22
19
|
return refkey(httpOperation, "http-request-send");
|
|
23
20
|
}
|
|
24
21
|
|
|
22
|
+
function getPagingOperationOptionsParameterRefkey(httpOperation: HttpOperation): Refkey {
|
|
23
|
+
return refkey(httpOperation, "paging-operation-options-parameter");
|
|
24
|
+
}
|
|
25
|
+
|
|
25
26
|
export function getHttpRequestSendParams(httpOperation: HttpOperation) {
|
|
27
|
+
const optionsRefkey = getPagingOperationOptionsParameterRefkey(httpOperation);
|
|
26
28
|
const clientLibrary = cl.useClientLibrary();
|
|
27
29
|
const client = clientLibrary.getClientForOperation(httpOperation);
|
|
28
30
|
const clientContextInterfaceRef = getClientcontextDeclarationRef(client!);
|
|
29
31
|
const signatureParams: ts.ParameterDescriptor[] = [
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
+
{
|
|
33
|
+
name: "client",
|
|
34
|
+
type: clientContextInterfaceRef,
|
|
35
|
+
refkey: ay.refkey(client, "send-client-param"),
|
|
36
|
+
},
|
|
37
|
+
...getOperationParameters(httpOperation, optionsRefkey),
|
|
32
38
|
];
|
|
33
39
|
const parameters: ts.ParameterDescriptor[] = [...signatureParams];
|
|
34
40
|
// re-correct the `options` parameter to Record<string, any> to accept both paging and non-paging options
|
|
35
41
|
parameters[parameters.length - 1] = {
|
|
36
42
|
name: "options",
|
|
37
43
|
type: "Record<string, any>",
|
|
38
|
-
refkey:
|
|
44
|
+
refkey: optionsRefkey,
|
|
39
45
|
optional: true,
|
|
40
46
|
};
|
|
41
47
|
return parameters;
|
|
@@ -43,8 +49,9 @@ export function getHttpRequestSendParams(httpOperation: HttpOperation) {
|
|
|
43
49
|
|
|
44
50
|
export function HttpRequestSend(props: HttpRequestSendProps) {
|
|
45
51
|
const httpOperation = props.httpOperation;
|
|
52
|
+
const optionsRefkey = getPagingOperationOptionsParameterRefkey(httpOperation);
|
|
46
53
|
const operationUrlRefkey = refkey();
|
|
47
|
-
const
|
|
54
|
+
const requestOptionsVarRefkey = refkey();
|
|
48
55
|
const verb = props.httpOperation.verb;
|
|
49
56
|
const namePolicy = ts.useTSNamePolicy();
|
|
50
57
|
const functionName = namePolicy.getName(httpOperation.operation.name + "Send", "function");
|
|
@@ -59,10 +66,18 @@ export function HttpRequestSend(props: HttpRequestSendProps) {
|
|
|
59
66
|
>
|
|
60
67
|
<List>
|
|
61
68
|
<StatementList>
|
|
62
|
-
<HttpRequest.Url
|
|
69
|
+
<HttpRequest.Url
|
|
70
|
+
httpOperation={props.httpOperation}
|
|
71
|
+
pathVarRefkey={operationUrlRefkey}
|
|
72
|
+
requestOptionsParamRefkey={optionsRefkey}
|
|
73
|
+
/>
|
|
63
74
|
|
|
64
|
-
<HttpRequestOptions
|
|
65
|
-
|
|
75
|
+
<HttpRequestOptions
|
|
76
|
+
httpOperation={props.httpOperation}
|
|
77
|
+
requestOptionsVarRefkey={requestOptionsVarRefkey}
|
|
78
|
+
requestOptionsParamRefkey={optionsRefkey}
|
|
79
|
+
/>
|
|
80
|
+
{code`return await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={requestOptionsVarRefkey} />)});`}
|
|
66
81
|
</StatementList>
|
|
67
82
|
</List>
|
|
68
83
|
</FunctionDeclaration>
|
|
@@ -5,7 +5,6 @@ import { HttpOperation } from "@typespec/http";
|
|
|
5
5
|
import { httpRuntimeTemplateLib } from "../../external-packages/ts-http-runtime.js";
|
|
6
6
|
import { HttpResponseProps, HttpResponses } from "../../http-response.jsx";
|
|
7
7
|
import { getOperationOptionsTypeRefkey } from "../../operation-options.jsx";
|
|
8
|
-
import { getOperationOptionsParameterRefkey } from "../../operation-parameters.jsx";
|
|
9
8
|
import { getCreateRestErrorRefkey } from "../../static-helpers/rest-error.jsx";
|
|
10
9
|
|
|
11
10
|
export function getHttpRequestDeserializeRefkey(httpOperation: HttpOperation) {
|
|
@@ -18,8 +17,13 @@ export interface HttpResponseDeserializeProps {
|
|
|
18
17
|
children?: Children;
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
export function getPagingDeserializationOptionsParamRef(httpOperation: HttpOperation): Refkey {
|
|
21
|
+
return refkey(httpOperation, "paging-deserialization-options-parameter");
|
|
22
|
+
}
|
|
23
|
+
|
|
21
24
|
export function HttpResponseDeserialize(props: HttpResponseProps) {
|
|
22
25
|
const httpOperation = props.httpOperation;
|
|
26
|
+
const httpRequestOptionsRefkey = getPagingDeserializationOptionsParamRef(httpOperation);
|
|
23
27
|
const namePolicy = ts.useTSNamePolicy();
|
|
24
28
|
const functionName = namePolicy.getName(httpOperation.operation.name + "Deserialize", "function");
|
|
25
29
|
const params = [
|
|
@@ -29,7 +33,7 @@ export function HttpResponseDeserialize(props: HttpResponseProps) {
|
|
|
29
33
|
},
|
|
30
34
|
{
|
|
31
35
|
name: "options",
|
|
32
|
-
refkey:
|
|
36
|
+
refkey: httpRequestOptionsRefkey,
|
|
33
37
|
type: getOperationOptionsTypeRefkey(httpOperation),
|
|
34
38
|
optional: true,
|
|
35
39
|
},
|
|
@@ -10,11 +10,10 @@ export interface OperationParametersProps {
|
|
|
10
10
|
operation: HttpOperation;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export function getOperationParameters(operation: HttpOperation): ts.ParameterDescriptor[] {
|
|
13
|
+
export function getOperationParameters(
|
|
14
|
+
operation: HttpOperation,
|
|
15
|
+
optionsRefkey: ay.Refkey,
|
|
16
|
+
): ts.ParameterDescriptor[] {
|
|
18
17
|
const transformNamer = useTransformNamePolicy();
|
|
19
18
|
const requiredParameters = operation.parameters.properties
|
|
20
19
|
.filter((p) => !p.property.optional && !hasDefaultValue(p))
|
|
@@ -26,7 +25,7 @@ export function getOperationParameters(operation: HttpOperation): ts.ParameterDe
|
|
|
26
25
|
const name = transformNamer.getApplicationName(parameter.property);
|
|
27
26
|
const parameterDescriptor: ts.ParameterDescriptor = {
|
|
28
27
|
name,
|
|
29
|
-
refkey: ay.refkey(
|
|
28
|
+
refkey: ay.refkey(),
|
|
30
29
|
type: <ef.TypeExpression type={parameter.property.type} />,
|
|
31
30
|
};
|
|
32
31
|
|
|
@@ -35,7 +34,7 @@ export function getOperationParameters(operation: HttpOperation): ts.ParameterDe
|
|
|
35
34
|
|
|
36
35
|
parameters.push({
|
|
37
36
|
name: "options",
|
|
38
|
-
refkey:
|
|
37
|
+
refkey: optionsRefkey,
|
|
39
38
|
type: getOperationOptionsTypeRefkey(operation),
|
|
40
39
|
optional: true,
|
|
41
40
|
});
|
|
@@ -9,11 +9,8 @@ export interface TransformDeclarationProps {
|
|
|
9
9
|
refkey?: ay.Refkey;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function getTransformDeclarationRef(
|
|
13
|
-
|
|
14
|
-
return ef.getTypeTransformerRefkey(operaion.httpOperation.parameters.body.type, "transport");
|
|
15
|
-
}
|
|
16
|
-
return ay.refkey(operaion, "transform");
|
|
12
|
+
export function getTransformDeclarationRef(operation: ClientOperation) {
|
|
13
|
+
return ay.refkey(operation, "transform");
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
export function TransformDeclaration(props: TransformDeclarationProps) {
|
package/src/utils/parameters.tsx
CHANGED
|
@@ -8,13 +8,16 @@ import * as cl from "@typespec/http-client";
|
|
|
8
8
|
import { getClientContextOptionsRef } from "../components/client-context/client-context-options.jsx";
|
|
9
9
|
import { httpRuntimeTemplateLib } from "../components/external-packages/ts-http-runtime.js";
|
|
10
10
|
|
|
11
|
-
export function buildClientParameters(
|
|
11
|
+
export function buildClientParameters(
|
|
12
|
+
client: cl.Client,
|
|
13
|
+
suffixRefkey: ay.Refkey,
|
|
14
|
+
): ts.ParameterDescriptor[] {
|
|
12
15
|
const { $ } = useTsp();
|
|
13
16
|
const clientConstructor = $.client.getConstructor(client);
|
|
14
17
|
const parameters = $.operation.getClientSignature(client, clientConstructor);
|
|
15
18
|
const params = parameters.flatMap(
|
|
16
19
|
(param) => {
|
|
17
|
-
const descriptor = buildClientParameterDescriptor(param);
|
|
20
|
+
const descriptor = buildClientParameterDescriptor(param, suffixRefkey);
|
|
18
21
|
if (!descriptor) {
|
|
19
22
|
return [];
|
|
20
23
|
}
|
|
@@ -31,7 +34,7 @@ export function buildClientParameters(client: cl.Client): ts.ParameterDescriptor
|
|
|
31
34
|
if (!params.some((p) => p.name === "options")) {
|
|
32
35
|
params.push({
|
|
33
36
|
name: "options",
|
|
34
|
-
refkey: ay.refkey(),
|
|
37
|
+
refkey: ay.refkey("client-options", suffixRefkey),
|
|
35
38
|
optional: true,
|
|
36
39
|
type: getClientContextOptionsRef(client),
|
|
37
40
|
});
|
|
@@ -42,6 +45,7 @@ export function buildClientParameters(client: cl.Client): ts.ParameterDescriptor
|
|
|
42
45
|
|
|
43
46
|
function buildClientParameterDescriptor(
|
|
44
47
|
modelProperty: ModelProperty,
|
|
48
|
+
suffixRefkey: ay.Refkey,
|
|
45
49
|
): ts.ParameterDescriptor | undefined {
|
|
46
50
|
const { $ } = useTsp();
|
|
47
51
|
const authSchemes = $.modelProperty.getCredentialAuth(modelProperty);
|
|
@@ -56,7 +60,7 @@ function buildClientParameterDescriptor(
|
|
|
56
60
|
);
|
|
57
61
|
return {
|
|
58
62
|
name: "credential",
|
|
59
|
-
refkey: ay.refkey(modelProperty),
|
|
63
|
+
refkey: ay.refkey(modelProperty, suffixRefkey),
|
|
60
64
|
optional: modelProperty.optional,
|
|
61
65
|
type: ay.mapJoin(
|
|
62
66
|
() => credentialType,
|
|
@@ -66,7 +70,7 @@ function buildClientParameterDescriptor(
|
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
return buildParameterDescriptor(modelProperty);
|
|
73
|
+
return buildParameterDescriptor(modelProperty, suffixRefkey);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
const oauth2FlowRefs: Record<OAuth2FlowType, ay.Refkey> = {
|