@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.
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -20
- package/.github/copilot-instructions.md +0 -180
- package/.testignore +0 -19
- package/.turbo/turbo-build.log +0 -3
- package/CHANGELOG.md +0 -159
- package/eng/scripts/calculate-coverage.ts +0 -33
- package/eng/scripts/emit-e2e.ts +0 -317
- package/eng/scripts/run-e2e-tests.ts +0 -166
- package/eng/scripts/tspconfig.yaml +0 -6
- package/eng/scripts/upload-spector-results.ts +0 -139
- package/src/components/client-context/client-context-declaration.tsx +0 -26
- package/src/components/client-context/client-context-factory.tsx +0 -218
- package/src/components/client-context/client-context-options.tsx +0 -36
- package/src/components/client-context/client-context.tsx +0 -23
- package/src/components/client-context/parametrized-endpoint.tsx +0 -51
- package/src/components/client-directory.tsx +0 -51
- package/src/components/client-operation.tsx +0 -102
- package/src/components/client.tsx +0 -177
- package/src/components/encoding-provider.tsx +0 -17
- package/src/components/external-packages/ts-http-runtime.ts +0 -28
- package/src/components/external-packages/uri-template.ts +0 -11
- package/src/components/http-request-options.tsx +0 -88
- package/src/components/http-request-parameters-expression.tsx +0 -191
- package/src/components/http-request.tsx +0 -80
- package/src/components/http-response.tsx +0 -74
- package/src/components/index.ts +0 -12
- package/src/components/models.tsx +0 -26
- package/src/components/operation-handlers/index.tsx +0 -2
- package/src/components/operation-handlers/operation-pipeline.tsx +0 -33
- package/src/components/operation-handlers/paging/page-item.tsx +0 -14
- package/src/components/operation-handlers/paging/page-response.tsx +0 -57
- package/src/components/operation-handlers/paging/page-settings.tsx +0 -53
- package/src/components/operation-handlers/paging/paginated-operation-handler.tsx +0 -200
- package/src/components/operation-handlers/paging/request-send.tsx +0 -85
- package/src/components/operation-handlers/paging/response-deserialize.tsx +0 -60
- package/src/components/operation-handlers/paging/util.ts +0 -70
- package/src/components/operation-handlers/types.tsx +0 -18
- package/src/components/operation-options.tsx +0 -42
- package/src/components/operation-parameters.tsx +0 -44
- package/src/components/output.tsx +0 -32
- package/src/components/serializers.tsx +0 -74
- package/src/components/static-helpers/bytes-encoding.tsx +0 -61
- package/src/components/static-helpers/interfaces.tsx +0 -31
- package/src/components/static-helpers/multipart-helpers.tsx +0 -80
- package/src/components/static-helpers/paging-helper.tsx +0 -202
- package/src/components/static-helpers/rest-error.tsx +0 -102
- package/src/components/testing/client-options.tsx +0 -30
- package/src/components/transforms/content-type-encoding-provider.tsx +0 -26
- package/src/components/transforms/data-transform.tsx +0 -40
- package/src/components/transforms/json/json-array-transform.tsx +0 -87
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +0 -54
- package/src/components/transforms/json/json-model-base-transform.tsx +0 -24
- package/src/components/transforms/json/json-model-property-transform.tsx +0 -53
- package/src/components/transforms/json/json-model-transform.tsx +0 -115
- package/src/components/transforms/json/json-record-transform.tsx +0 -88
- package/src/components/transforms/json/json-transform-discriminator.tsx +0 -111
- package/src/components/transforms/json/json-transform.tsx +0 -120
- package/src/components/transforms/json/union-transform.tsx +0 -87
- package/src/components/transforms/json/utils/transport-namer.ts +0 -12
- package/src/components/transforms/multipart/array-part-transform.tsx +0 -44
- package/src/components/transforms/multipart/file-part-transform.tsx +0 -45
- package/src/components/transforms/multipart/multipart-transform.tsx +0 -30
- package/src/components/transforms/multipart/part-transform.tsx +0 -22
- package/src/components/transforms/multipart/simple-part-transform.tsx +0 -42
- package/src/components/transforms/operation-transform-declaration.tsx +0 -83
- package/src/components/transforms/operation-transform-expression.tsx +0 -62
- package/src/components/transforms/scalar-transform.tsx +0 -301
- package/src/components/transforms/transform-name-policy.ts +0 -134
- package/src/components/utils/unpack-model-property.ts +0 -44
- package/src/components/utils/url-template.tsx +0 -25
- package/src/context/encoding/encoding-context.tsx +0 -28
- package/src/context/encoding/types.ts +0 -6
- package/src/emitter.tsx +0 -85
- package/src/index.ts +0 -5
- package/src/lib.ts +0 -120
- package/src/testing/index.ts +0 -11
- package/src/utils/client-discovery.ts +0 -28
- package/src/utils/multipart.ts +0 -29
- package/src/utils/operations.ts +0 -112
- package/src/utils/parameters.tsx +0 -155
- package/test/e2e/assets/image.jpg +0 -0
- package/test/e2e/assets/image.png +0 -0
- package/test/e2e/http/authentication/api-key/main.test.ts +0 -38
- package/test/e2e/http/authentication/oauth2/main.test.ts +0 -31
- package/test/e2e/http/authentication/union/main.test.ts +0 -26
- package/test/e2e/http/encode/bytes/main.test.ts +0 -191
- package/test/e2e/http/encode/datetime/main.test.ts +0 -176
- package/test/e2e/http/encode/duration/main.test.ts +0 -126
- package/test/e2e/http/encode/numeric/main.test.ts +0 -26
- package/test/e2e/http/parameters/basic/main.test.ts +0 -35
- package/test/e2e/http/parameters/body-optionality/main.test.ts +0 -43
- package/test/e2e/http/parameters/collection-format/main.test.ts +0 -40
- package/test/e2e/http/parameters/spread/main.test.ts +0 -56
- package/test/e2e/http/payload/content-negotiation/main.test.ts +0 -40
- package/test/e2e/http/payload/json-merge-patch/main.test.ts +0 -122
- package/test/e2e/http/payload/media-type/main.test.ts +0 -28
- package/test/e2e/http/payload/multipart/main.test.ts +0 -200
- package/test/e2e/http/payload/pageable/main.test.ts +0 -78
- package/test/e2e/http/payload/xml/main.test.ts +0 -287
- package/test/e2e/http/routes/main.test.ts +0 -284
- package/test/e2e/http/serialization/encoded-name/json/main.test.ts +0 -20
- package/test/e2e/http/server/endpoint/not-defined/main.test.ts +0 -11
- package/test/e2e/http/server/path/multiple/main.test.ts +0 -22
- package/test/e2e/http/server/path/single/main.test.ts +0 -11
- package/test/e2e/http/server/versions/not-versioned/main.test.ts +0 -22
- package/test/e2e/http/server/versions/versioned/main.test.ts +0 -28
- package/test/e2e/http/special-headers/conditional-request/main.test.ts +0 -35
- package/test/e2e/http/special-headers/repeatability/main.test.ts +0 -18
- package/test/e2e/http/special-words/main.test.ts +0 -434
- package/test/e2e/http/type/array/array.test.ts +0 -256
- package/test/e2e/http/type/dictionary/main.test.ts +0 -229
- package/test/e2e/http/type/enum/extensible/main.test.ts +0 -34
- package/test/e2e/http/type/enum/fixed/main.test.ts +0 -29
- package/test/e2e/http/type/model/empty/main.test.ts +0 -21
- package/test/e2e/http/type/model/inheritance/enum-discriminator/main.test.ts +0 -51
- package/test/e2e/http/type/model/inheritance/nested-discriminator/main.test.ts +0 -168
- package/test/e2e/http/type/model/inheritance/not-discriminated/main.test.ts +0 -42
- package/test/e2e/http/type/model/inheritance/recursive/main.test.ts +0 -46
- package/test/e2e/http/type/model/inheritance/single-discriminator/main.test.ts +0 -99
- package/test/e2e/http/type/model/visibility/main.test.ts +0 -64
- package/test/e2e/http/type/property/additional-properties/main.test.ts +0 -185
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -448
- package/test/e2e/http/type/property/nullable/main.test.ts +0 -275
- package/test/e2e/http/type/property/optionality/main.test.ts +0 -256
- package/test/e2e/http/type/property/value-types/main.test.ts +0 -193
- package/test/e2e/http/type/scalar/main.test.ts +0 -133
- package/test/e2e/http/type/scalar/scalar.test.ts +0 -95
- package/test/e2e/http/type/union/main.test.ts +0 -207
- package/test/e2e/http/versioning/added/main.test.ts +0 -60
- package/test/e2e/http/versioning/madeOptional/main.test.ts +0 -34
- package/test/e2e/http/versioning/removed/main.test.ts +0 -75
- package/test/e2e/http/versioning/renamedFrom/main.test.ts +0 -52
- package/test/e2e/http/versioning/returnTypeChangedFrom/main.test.ts +0 -22
- package/test/e2e/http/versioning/typeChangedFrom/main.test.ts +0 -31
- package/test/scenarios/additional-properties/extends.md +0 -67
- package/test/scenarios/additional-properties/is.md +0 -42
- package/test/scenarios/additional-properties/spread.md +0 -68
- package/test/scenarios/auth/basic_auth.md +0 -68
- package/test/scenarios/auth/bearer.md +0 -68
- package/test/scenarios/auth/client_parameters.md +0 -78
- package/test/scenarios/auth/client_structure.md +0 -36
- package/test/scenarios/auth/key_credential.md +0 -69
- package/test/scenarios/auth/oauth2.md +0 -90
- package/test/scenarios/auth/sub_client_override.md +0 -114
- package/test/scenarios/client/client_context.md +0 -34
- package/test/scenarios/client/dotted_namespace.md +0 -27
- package/test/scenarios/client/global_namespace.md +0 -69
- package/test/scenarios/client/multiple_top_level_clients.md +0 -72
- package/test/scenarios/client/nested_client.md +0 -102
- package/test/scenarios/client/wrapping_namespace.md +0 -41
- package/test/scenarios/encoding/bytes_body.md +0 -44
- package/test/scenarios/encoding/bytes_json_property.md +0 -55
- package/test/scenarios/encoding/bytes_nullable.md +0 -139
- package/test/scenarios/encoding/header_bytes.md +0 -130
- package/test/scenarios/encoding/header_date.md +0 -216
- package/test/scenarios/encoding/model_with_bytes_property.md +0 -45
- package/test/scenarios/encoding/query_bytes.md +0 -42
- package/test/scenarios/encoding/query_date.md +0 -216
- package/test/scenarios/http-operations/basic-request.md +0 -144
- package/test/scenarios/http-operations/basic-response.md +0 -219
- package/test/scenarios/http-operations/basic.md +0 -128
- package/test/scenarios/http-operations/constant-header.md +0 -33
- package/test/scenarios/http-operations/create-operation.md +0 -58
- package/test/scenarios/http-operations/on_response.md +0 -52
- package/test/scenarios/http-operations/optional-request-body.md +0 -50
- package/test/scenarios/http-operations/paging.md +0 -242
- package/test/scenarios/http-operations/path-parameter-in-model.md +0 -53
- package/test/scenarios/http-operations/path-parameter.md +0 -48
- package/test/scenarios/http-operations/query-parameter.md +0 -41
- package/test/scenarios/http-operations/scalar-payload.md +0 -57
- package/test/scenarios/http-operations/with-parameters.md +0 -78
- package/test/scenarios/models/array-properties.md +0 -47
- package/test/scenarios/models/basic.md +0 -118
- package/test/scenarios/models/dictionary-properties.md +0 -44
- package/test/scenarios/models/inheritance_2_discriminators.md +0 -346
- package/test/scenarios/models/inheritance_discriminator.md +0 -88
- package/test/scenarios/models/inline-models.md +0 -29
- package/test/scenarios/models/model_additional_properties.md +0 -75
- package/test/scenarios/models/model_extends.md +0 -97
- package/test/scenarios/models/model_spread.md +0 -63
- package/test/scenarios/models/nested_property.md +0 -41
- package/test/scenarios/models/property_references_property.md +0 -150
- package/test/scenarios/multipart/anonymous_part.md +0 -53
- package/test/scenarios/multipart/file.md +0 -154
- package/test/scenarios/multipart/file_content_type.md +0 -92
- package/test/scenarios/multipart/non-string-float.md +0 -55
- package/test/scenarios/multipart/simple_part.md +0 -65
- package/test/scenarios/operation-parameters/body_root_anonymous.md +0 -87
- package/test/scenarios/operation-parameters/constant_as_optional.md +0 -54
- package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -54
- package/test/scenarios/operation-parameters/no_content_type.md +0 -62
- package/test/scenarios/operation-parameters/no_parameters.md +0 -50
- package/test/scenarios/operation-parameters/only_optional.md +0 -62
- package/test/scenarios/operation-parameters/only_required.md +0 -58
- package/test/scenarios/operation-parameters/reserved_names.md +0 -60
- package/test/scenarios/operation-parameters/spread_body.md +0 -70
- package/test/scenarios/operation-parameters/spread_with_nested.md +0 -82
- package/test/scenarios/operation-parameters/union_body.md +0 -86
- package/test/scenarios/operation-parameters/with_body_property.md +0 -67
- package/test/scenarios/operation-parameters/with_body_root.md +0 -69
- package/test/scenarios/serializers/arrays.md +0 -191
- package/test/scenarios/serializers/basic_model.md +0 -111
- package/test/scenarios/serializers/basic_model_wire_name.md +0 -48
- package/test/scenarios/serializers/discriminated_union.md +0 -86
- package/test/scenarios/serializers/discriminated_union_spread.md +0 -115
- package/test/scenarios/serializers/file.md +0 -67
- package/test/scenarios/serializers/model_date_time.md +0 -65
- package/test/scenarios/serializers/multipart.md +0 -62
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +0 -157
- package/test/scenarios/serializers/property_references_property.md +0 -72
- package/test/scenarios/serializers/record.md +0 -97
- package/test/scenarios/serializers/scalars.md +0 -34
- package/test/scenarios/serializers/spread.md +0 -69
- package/test/scenarios/serializers/string_union.md +0 -55
- package/test/scenarios/server/default_url.md +0 -45
- package/test/scenarios/server/multiple-parameters.md +0 -55
- package/test/scenarios/server/no-server.md +0 -37
- package/test/scenarios/server/parametrized-endpoint.md +0 -51
- package/test/scenarios.test.ts +0 -24
- package/test/test-host.ts +0 -22
- package/tsconfig.json +0 -16
- package/tsconfig.test.json +0 -9
- package/vitest.config.e2e.ts +0 -16
- package/vitest.config.ts +0 -15
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createPackage } from "@alloy-js/typescript";
|
|
2
|
-
|
|
3
|
-
export const httpRuntimeTemplateLib = createPackage({
|
|
4
|
-
name: "@typespec/ts-http-runtime",
|
|
5
|
-
version: "0.2.1",
|
|
6
|
-
descriptor: {
|
|
7
|
-
".": {
|
|
8
|
-
named: [
|
|
9
|
-
"Client",
|
|
10
|
-
"ClientOptions",
|
|
11
|
-
"getClient",
|
|
12
|
-
"ApiKeyCredential",
|
|
13
|
-
"BasicCredential",
|
|
14
|
-
"BearerTokenCredential",
|
|
15
|
-
"OAuth2TokenCredential",
|
|
16
|
-
"AuthorizationCodeFlow",
|
|
17
|
-
"ClientCredentialsFlow",
|
|
18
|
-
"ImplicitFlow",
|
|
19
|
-
"PasswordFlow",
|
|
20
|
-
"PathUncheckedResponse",
|
|
21
|
-
"PipelineRequest",
|
|
22
|
-
"HttpResponse",
|
|
23
|
-
"RawHttpHeaders",
|
|
24
|
-
"RestError",
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { code } from "@alloy-js/core";
|
|
3
|
-
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import type { HttpOperation } from "@typespec/http";
|
|
5
|
-
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
6
|
-
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.jsx";
|
|
7
|
-
import { OperationTransformExpression } from "./transforms/operation-transform-expression.jsx";
|
|
8
|
-
|
|
9
|
-
export interface HttpRequestOptionsProps {
|
|
10
|
-
httpOperation: HttpOperation;
|
|
11
|
-
requestOptionsParamRefkey: Refkey;
|
|
12
|
-
requestOptionsVarRefkey: Refkey;
|
|
13
|
-
children?: Children;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function HttpRequestOptions(props: HttpRequestOptionsProps) {
|
|
17
|
-
return (
|
|
18
|
-
<ts.VarDeclaration name="httpRequestOptions" refkey={props.requestOptionsVarRefkey}>
|
|
19
|
-
<ts.ObjectExpression>
|
|
20
|
-
<HttpRequestOptions.Headers
|
|
21
|
-
httpOperation={props.httpOperation}
|
|
22
|
-
requestOptionsParamRefkey={props.requestOptionsParamRefkey}
|
|
23
|
-
/>
|
|
24
|
-
<HttpRequestOptions.Body httpOperation={props.httpOperation} />
|
|
25
|
-
</ts.ObjectExpression>
|
|
26
|
-
</ts.VarDeclaration>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface HttpRequestOptionsHeadersProps {
|
|
31
|
-
httpOperation: HttpOperation;
|
|
32
|
-
requestOptionsParamRefkey: Refkey;
|
|
33
|
-
children?: Children;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
HttpRequestOptions.Headers = function HttpRequestOptionsHeaders(
|
|
37
|
-
props: HttpRequestOptionsHeadersProps,
|
|
38
|
-
) {
|
|
39
|
-
// Extract the header request parameters from the operation
|
|
40
|
-
const httpOperation = props.httpOperation;
|
|
41
|
-
const headers = props.httpOperation.parameters.properties.filter(
|
|
42
|
-
(p) => p.kind === "header" || p.kind === "contentType",
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const optionsParam = props.requestOptionsParamRefkey;
|
|
46
|
-
return (
|
|
47
|
-
<EncodingProvider defaults={{ bytes: "base64", datetime: "rfc7231" }}>
|
|
48
|
-
<ts.ObjectProperty name="headers">
|
|
49
|
-
<HttpRequestParametersExpression
|
|
50
|
-
parameters={headers}
|
|
51
|
-
optionsParameter={optionsParam}
|
|
52
|
-
httpOperation={httpOperation}
|
|
53
|
-
/>
|
|
54
|
-
,
|
|
55
|
-
</ts.ObjectProperty>
|
|
56
|
-
</EncodingProvider>
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export interface HttpRequestOptionsBodyProps {
|
|
61
|
-
httpOperation: HttpOperation;
|
|
62
|
-
itemName?: string;
|
|
63
|
-
children?: Children;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
HttpRequestOptions.Body = function HttpRequestOptionsBody(props: HttpRequestOptionsBodyProps) {
|
|
67
|
-
const body = props.httpOperation.parameters.body;
|
|
68
|
-
|
|
69
|
-
if (!body) {
|
|
70
|
-
return <></>;
|
|
71
|
-
}
|
|
72
|
-
// The transformer to apply to the body.
|
|
73
|
-
const bodyTransform = (
|
|
74
|
-
<>
|
|
75
|
-
<OperationTransformExpression httpOperation={props.httpOperation} />
|
|
76
|
-
</>
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<>
|
|
81
|
-
<ts.ObjectProperty name="body" value={bodyTransform} />,
|
|
82
|
-
</>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export function JSONSerializer(props: { children?: Children }) {
|
|
87
|
-
return code`JSON.stringify(${props.children})`;
|
|
88
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import type { Children } from "@alloy-js/core";
|
|
2
|
-
import { code, For, List, NamePolicyContext, useNamePolicy } from "@alloy-js/core";
|
|
3
|
-
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import { useTransformNamePolicy } from "@typespec/emitter-framework";
|
|
5
|
-
import type { HttpOperation, HttpProperty } from "@typespec/http";
|
|
6
|
-
import { getDefaultValue, hasDefaultValue } from "../utils/parameters.jsx";
|
|
7
|
-
import { JsonTransform } from "./transforms/json/json-transform.jsx";
|
|
8
|
-
export interface HttpRequestParametersExpressionProps {
|
|
9
|
-
httpOperation: HttpOperation;
|
|
10
|
-
optionsParameter: Children;
|
|
11
|
-
parameters?: HttpProperty[];
|
|
12
|
-
children?: Children;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function HttpRequestParametersExpression(props: HttpRequestParametersExpressionProps) {
|
|
16
|
-
const parameters: Children[] = [];
|
|
17
|
-
const transformNamer = useTransformNamePolicy();
|
|
18
|
-
|
|
19
|
-
if (props.children || (Array.isArray(props.children) && props.children.length)) {
|
|
20
|
-
parameters.push(<>{props.children},</>);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!props.parameters && parameters.length) {
|
|
24
|
-
return <ts.ObjectExpression>{parameters}</ts.ObjectExpression>;
|
|
25
|
-
} else if (!props.parameters) {
|
|
26
|
-
return <ts.ObjectExpression />;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const optionsParamRef = props.optionsParameter ?? "options";
|
|
30
|
-
const members = (
|
|
31
|
-
<For each={props.parameters} line comma>
|
|
32
|
-
{(httpProperty) => {
|
|
33
|
-
const defaultValue = getDefaultValue(httpProperty);
|
|
34
|
-
const propertyExpression = buildMemberChainExpression(
|
|
35
|
-
props.httpOperation,
|
|
36
|
-
httpProperty,
|
|
37
|
-
optionsParamRef,
|
|
38
|
-
);
|
|
39
|
-
const transportParamName = transformNamer.getTransportName(httpProperty.property);
|
|
40
|
-
|
|
41
|
-
if (defaultValue) {
|
|
42
|
-
const paramValue = (
|
|
43
|
-
<>
|
|
44
|
-
{propertyExpression.fullExpression}
|
|
45
|
-
{` ?? ${defaultValue}`}
|
|
46
|
-
</>
|
|
47
|
-
);
|
|
48
|
-
return (
|
|
49
|
-
<NamePolicyContext.Provider value={{ getName: (n) => n, for: () => (n) => n }}>
|
|
50
|
-
<ts.ObjectProperty name={transportParamName} value={paramValue} />
|
|
51
|
-
</NamePolicyContext.Provider>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (propertyExpression.isNullish) {
|
|
56
|
-
return code`
|
|
57
|
-
...(${propertyExpression.fullExpression} && {${(<JsonTransform itemRef={propertyExpression.leadingExpression} type={httpProperty.property} target="transport" />)}})
|
|
58
|
-
`;
|
|
59
|
-
} else {
|
|
60
|
-
return (
|
|
61
|
-
<JsonTransform
|
|
62
|
-
itemRef={propertyExpression.leadingExpression}
|
|
63
|
-
type={httpProperty.property}
|
|
64
|
-
target="transport"
|
|
65
|
-
/>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}}
|
|
69
|
-
</For>
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
parameters.push(members);
|
|
73
|
-
|
|
74
|
-
return <ts.ObjectExpression>{parameters}</ts.ObjectExpression>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
interface MemberChainExpression {
|
|
78
|
-
propertyName: string;
|
|
79
|
-
isNullish: boolean;
|
|
80
|
-
fullExpression: Children;
|
|
81
|
-
leadingExpression?: Children;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Builds the member chain expression for potentially nested HTTP parameters.
|
|
86
|
-
* This logic will be simplified and made more robust once a couple of changes land in Alloy.
|
|
87
|
-
* - Support refkeys on interface members
|
|
88
|
-
* - Support for conditional chaining on ts.MemberChainExpression
|
|
89
|
-
* - Eventually we'll have an API like:
|
|
90
|
-
* @example
|
|
91
|
-
* ```tsx
|
|
92
|
-
* <InstancePropertyExpression
|
|
93
|
-
* instance={refkey(parameter)}
|
|
94
|
-
* staticMember={refkey(property)}
|
|
95
|
-
* />
|
|
96
|
-
* ```
|
|
97
|
-
* @param httpOperation - The HttpOperation containing parameters.
|
|
98
|
-
* @param httpProperty - The current HttpProperty to build an access path for.
|
|
99
|
-
* @param optionsParamRef - Reference to the user's main options parameter.
|
|
100
|
-
* @returns The full nested expression, leading expression, nullish flag, and final property name.
|
|
101
|
-
*/
|
|
102
|
-
function buildMemberChainExpression(
|
|
103
|
-
httpOperation: HttpOperation,
|
|
104
|
-
httpProperty: HttpProperty,
|
|
105
|
-
optionsParamRef?: Children,
|
|
106
|
-
): MemberChainExpression {
|
|
107
|
-
const segments: Children[] = [];
|
|
108
|
-
let isNullish = httpProperty.property.optional === true;
|
|
109
|
-
const namePolicy = useNamePolicy();
|
|
110
|
-
const propertyApplicationName = namePolicy.getName(httpProperty.property.name, "property");
|
|
111
|
-
|
|
112
|
-
// If the property is at the top level, return early
|
|
113
|
-
if (httpProperty.path.length === 1) {
|
|
114
|
-
if (httpProperty.property.optional || hasDefaultValue(httpProperty)) {
|
|
115
|
-
return {
|
|
116
|
-
propertyName: propertyApplicationName,
|
|
117
|
-
isNullish,
|
|
118
|
-
fullExpression: code`${optionsParamRef}?.${propertyApplicationName}`,
|
|
119
|
-
leadingExpression: code`${optionsParamRef}`,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
propertyName: propertyApplicationName,
|
|
124
|
-
isNullish,
|
|
125
|
-
fullExpression: propertyApplicationName,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Build access segments for nested properties.
|
|
130
|
-
let currentPath = httpProperty.path.slice(0, -1);
|
|
131
|
-
while (currentPath.length > 0) {
|
|
132
|
-
const parentProperty = findHttpPropertyByPath(httpOperation, currentPath);
|
|
133
|
-
if (!parentProperty) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Use optional chaining if the parent is optional.
|
|
138
|
-
const joiner = parentProperty.property.optional ? "?." : ".";
|
|
139
|
-
if (parentProperty.property.optional) {
|
|
140
|
-
isNullish = true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const parentName = namePolicy.getName(parentProperty.property.name, "property");
|
|
144
|
-
|
|
145
|
-
// Unshift the joiner first
|
|
146
|
-
segments.unshift(joiner);
|
|
147
|
-
|
|
148
|
-
// Use direct property access if possible.
|
|
149
|
-
if (isValidIdentifier(parentName)) {
|
|
150
|
-
segments.unshift(code`${parentName}`);
|
|
151
|
-
} else {
|
|
152
|
-
// For non-valid identifiers, use bracket notation.
|
|
153
|
-
segments.unshift(`[${JSON.stringify(parentName)}]`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Remove the last element to move one level up.
|
|
157
|
-
currentPath = currentPath.slice(0, -1);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const fullExpression = (
|
|
161
|
-
<>
|
|
162
|
-
<List children={segments} />
|
|
163
|
-
{propertyApplicationName}
|
|
164
|
-
</>
|
|
165
|
-
);
|
|
166
|
-
const leadingExpression = <List children={segments.slice(0, -1)} />;
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
propertyName: propertyApplicationName,
|
|
170
|
-
isNullish,
|
|
171
|
-
fullExpression,
|
|
172
|
-
leadingExpression,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isValidIdentifier(name: string): boolean {
|
|
177
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function findHttpPropertyByPath(
|
|
181
|
-
httpOperation: HttpOperation,
|
|
182
|
-
path: (string | number)[],
|
|
183
|
-
): HttpProperty | undefined {
|
|
184
|
-
for (const property of httpOperation.parameters.properties) {
|
|
185
|
-
// Check if the property path matches the given path
|
|
186
|
-
if (JSON.stringify(property.path) === JSON.stringify(path)) {
|
|
187
|
-
return property;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { code, List, refkey, StatementList } from "@alloy-js/core";
|
|
3
|
-
import * as ts from "@alloy-js/typescript";
|
|
4
|
-
import { Reference } from "@alloy-js/typescript";
|
|
5
|
-
import type { HttpOperation } from "@typespec/http";
|
|
6
|
-
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
7
|
-
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
8
|
-
import { HttpRequestOptions } from "./http-request-options.js";
|
|
9
|
-
import { HttpRequestParametersExpression } from "./http-request-parameters-expression.js";
|
|
10
|
-
|
|
11
|
-
export interface HttpRequestProps {
|
|
12
|
-
httpOperation: HttpOperation;
|
|
13
|
-
operationOptionsParamRefkey: Refkey;
|
|
14
|
-
responseRefkey?: Refkey;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function HttpRequest(props: HttpRequestProps) {
|
|
18
|
-
const operationUrlRefkey = refkey();
|
|
19
|
-
const requestOptionsVarRefkey = refkey();
|
|
20
|
-
const httpResponseRefkey = props.responseRefkey ?? refkey();
|
|
21
|
-
const verb = props.httpOperation.verb;
|
|
22
|
-
return (
|
|
23
|
-
<List>
|
|
24
|
-
<StatementList>
|
|
25
|
-
<HttpRequest.Url
|
|
26
|
-
httpOperation={props.httpOperation}
|
|
27
|
-
pathVarRefkey={operationUrlRefkey}
|
|
28
|
-
requestOptionsParamRefkey={props.operationOptionsParamRefkey}
|
|
29
|
-
/>
|
|
30
|
-
|
|
31
|
-
<HttpRequestOptions
|
|
32
|
-
httpOperation={props.httpOperation}
|
|
33
|
-
requestOptionsParamRefkey={props.operationOptionsParamRefkey}
|
|
34
|
-
requestOptionsVarRefkey={requestOptionsVarRefkey}
|
|
35
|
-
/>
|
|
36
|
-
|
|
37
|
-
<ts.VarDeclaration name="response" refkey={httpResponseRefkey}>
|
|
38
|
-
{code`
|
|
39
|
-
await client.pathUnchecked(${(<Reference refkey={operationUrlRefkey} />)}).${verb}(${(<Reference refkey={requestOptionsVarRefkey} />)})
|
|
40
|
-
`}
|
|
41
|
-
</ts.VarDeclaration>
|
|
42
|
-
</StatementList>
|
|
43
|
-
<hbr />
|
|
44
|
-
<hbr />
|
|
45
|
-
{code`
|
|
46
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
47
|
-
options?.operationOptions?.onResponse(response);
|
|
48
|
-
}`}
|
|
49
|
-
</List>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface HttpUrlProps {
|
|
54
|
-
httpOperation: HttpOperation;
|
|
55
|
-
requestOptionsParamRefkey: Refkey;
|
|
56
|
-
pathVarRefkey?: Refkey;
|
|
57
|
-
children?: Children;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
HttpRequest.Url = function HttpUrlDeclaration(props: HttpUrlProps) {
|
|
61
|
-
const urlTemplate = props.httpOperation.uriTemplate;
|
|
62
|
-
const urlParameters = props.httpOperation.parameters.properties.filter(
|
|
63
|
-
(p) => p.kind === "path" || p.kind === "query",
|
|
64
|
-
);
|
|
65
|
-
return (
|
|
66
|
-
<EncodingProvider defaults={{ bytes: "base64url" }}>
|
|
67
|
-
<ts.VarDeclaration name="path" refkey={props.pathVarRefkey}>
|
|
68
|
-
{uriTemplateLib.parse}({JSON.stringify(urlTemplate)}).expand(
|
|
69
|
-
{
|
|
70
|
-
<HttpRequestParametersExpression
|
|
71
|
-
httpOperation={props.httpOperation}
|
|
72
|
-
optionsParameter={props.requestOptionsParamRefkey}
|
|
73
|
-
parameters={urlParameters}
|
|
74
|
-
/>
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
</ts.VarDeclaration>
|
|
78
|
-
</EncodingProvider>
|
|
79
|
-
);
|
|
80
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { Children, Refkey } from "@alloy-js/core";
|
|
2
|
-
import { code, For, List } from "@alloy-js/core";
|
|
3
|
-
import { isVoidType } from "@typespec/compiler";
|
|
4
|
-
import { useTsp } from "@typespec/emitter-framework";
|
|
5
|
-
import type { HttpOperation } from "@typespec/http";
|
|
6
|
-
import { getCreateRestErrorRefkey } from "./static-helpers/rest-error.jsx";
|
|
7
|
-
import { ContentTypeEncodingProvider } from "./transforms/content-type-encoding-provider.jsx";
|
|
8
|
-
import { JsonTransform } from "./transforms/json/json-transform.jsx";
|
|
9
|
-
export interface HttpResponseProps {
|
|
10
|
-
httpOperation: HttpOperation;
|
|
11
|
-
responseRefkey: Refkey;
|
|
12
|
-
children?: Children;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function HttpResponse(props: HttpResponseProps) {
|
|
16
|
-
return (
|
|
17
|
-
<List hardline>
|
|
18
|
-
<HttpResponses httpOperation={props.httpOperation} />
|
|
19
|
-
{code`throw ${getCreateRestErrorRefkey()}(response);`}
|
|
20
|
-
</List>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface HttpResponsesProps {
|
|
25
|
-
httpOperation: HttpOperation;
|
|
26
|
-
children?: Children;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function HttpResponses(props: HttpResponsesProps) {
|
|
30
|
-
const { $ } = useTsp();
|
|
31
|
-
// Handle response by status code and content type
|
|
32
|
-
const responses = $.httpOperation.flattenResponses(props.httpOperation);
|
|
33
|
-
return (
|
|
34
|
-
<For each={responses.filter((r) => !$.httpResponse.isErrorResponse(r))}>
|
|
35
|
-
{({ statusCode, contentType, responseContent, type }) => {
|
|
36
|
-
const body = responseContent.body;
|
|
37
|
-
|
|
38
|
-
let expression: Children = code`return;`;
|
|
39
|
-
|
|
40
|
-
const contentTypeCheck = body
|
|
41
|
-
? ` && response.headers["content-type"]?.includes("${contentType}")`
|
|
42
|
-
: " && !response.body";
|
|
43
|
-
|
|
44
|
-
if (body && (body.bodyKind === "single" || (type && !isVoidType(type)))) {
|
|
45
|
-
expression = (
|
|
46
|
-
<ContentTypeEncodingProvider contentType={contentType}>
|
|
47
|
-
return{" "}
|
|
48
|
-
<JsonTransform itemRef={"response.body"} target="application" type={body.type} />
|
|
49
|
-
!;
|
|
50
|
-
</ContentTypeEncodingProvider>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if ($.httpResponse.statusCode.isSingle(statusCode)) {
|
|
55
|
-
return code`
|
|
56
|
-
if (+response.status === ${statusCode}${contentTypeCheck}) {
|
|
57
|
-
${expression}
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if ($.httpResponse.statusCode.isRange(statusCode)) {
|
|
63
|
-
return code`
|
|
64
|
-
if (+response.status >= ${statusCode.start} && +response.status <= ${statusCode.end} ${contentTypeCheck}) {
|
|
65
|
-
${expression}
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
}}
|
|
72
|
-
</For>
|
|
73
|
-
);
|
|
74
|
-
}
|
package/src/components/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { OperationsDirectory } from "./client-directory.jsx";
|
|
2
|
-
export { Client } from "./client.jsx";
|
|
3
|
-
export { EncodingProvider } from "./encoding-provider.jsx";
|
|
4
|
-
export { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
|
|
5
|
-
export { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
6
|
-
export { Models } from "./models.js";
|
|
7
|
-
export { ModelSerializers } from "./serializers.js";
|
|
8
|
-
export { Interfaces } from "./static-helpers/interfaces.jsx";
|
|
9
|
-
export { MultipartHelpers } from "./static-helpers/multipart-helpers.jsx";
|
|
10
|
-
export { PagingHelpers } from "./static-helpers/paging-helper.jsx";
|
|
11
|
-
export { RestError } from "./static-helpers/rest-error.jsx";
|
|
12
|
-
export { createTransformNamePolicy } from "./transforms/transform-name-policy.js";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { For, refkey } from "@alloy-js/core";
|
|
2
|
-
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import { useTsp } from "@typespec/emitter-framework";
|
|
4
|
-
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
-
import { useClientLibrary } from "@typespec/http-client";
|
|
6
|
-
|
|
7
|
-
export interface ModelsProps {
|
|
8
|
-
path?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function Models(props: ModelsProps) {
|
|
12
|
-
const { $ } = useTsp();
|
|
13
|
-
const clientLibrary = useClientLibrary();
|
|
14
|
-
const dataTypes = clientLibrary.dataTypes;
|
|
15
|
-
return (
|
|
16
|
-
<ts.SourceFile path={props.path ?? "models.ts"}>
|
|
17
|
-
<For each={dataTypes} hardline>
|
|
18
|
-
{(type) => {
|
|
19
|
-
return $.array.is(type) || $.record.is(type) ? null : (
|
|
20
|
-
<ef.TypeDeclaration export type={type} refkey={refkey(type)} />
|
|
21
|
-
);
|
|
22
|
-
}}
|
|
23
|
-
</For>
|
|
24
|
-
</ts.SourceFile>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { refkey } from "@alloy-js/core";
|
|
2
|
-
import type { HttpOperation } from "@typespec/http";
|
|
3
|
-
import { ClientOperation as DefaultOperationComponent } from "../client-operation.jsx";
|
|
4
|
-
import type { OperationHandlerPipeline } from "./types.jsx";
|
|
5
|
-
|
|
6
|
-
export interface OperationPipelineProps {
|
|
7
|
-
httpOperation: HttpOperation;
|
|
8
|
-
pipeline: OperationHandlerPipeline;
|
|
9
|
-
internal?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Component that manages the operation handler pipeline.
|
|
14
|
-
* It will try each handler in order until it finds one that can handle the operation.
|
|
15
|
-
* If no handler is found, it will use the default ClientOperation component.
|
|
16
|
-
*/
|
|
17
|
-
export function OperationPipeline({ httpOperation, pipeline, internal }: OperationPipelineProps) {
|
|
18
|
-
for (const handler of pipeline.handlers) {
|
|
19
|
-
if (handler.canHandle(httpOperation)) {
|
|
20
|
-
return handler.handle(httpOperation);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Default to standard client operation if no handler matched
|
|
25
|
-
const defaultOperationRefkey = refkey(httpOperation.operation);
|
|
26
|
-
return (
|
|
27
|
-
<DefaultOperationComponent
|
|
28
|
-
httpOperation={httpOperation}
|
|
29
|
-
internal={internal}
|
|
30
|
-
refkey={defaultOperationRefkey}
|
|
31
|
-
/>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { PagingOperation } from "@typespec/compiler";
|
|
2
|
-
import { useTsp } from "@typespec/emitter-framework";
|
|
3
|
-
import { TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
4
|
-
|
|
5
|
-
export function getPageItemTypeName(pagingOperation: PagingOperation) {
|
|
6
|
-
const { $ } = useTsp();
|
|
7
|
-
const type = pagingOperation.output.pageItems.property.type;
|
|
8
|
-
// only accept array type
|
|
9
|
-
if (type.kind === "Model" && $.array.is(type)) {
|
|
10
|
-
return <TypeExpression type={$.array.getElementType(type)} />;
|
|
11
|
-
}
|
|
12
|
-
// not supported and throw exceptions
|
|
13
|
-
throw new Error("Not supported");
|
|
14
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { For, refkey } from "@alloy-js/core";
|
|
2
|
-
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import type { PagingOperation, PagingProperty } from "@typespec/compiler";
|
|
4
|
-
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
-
import type { HttpOperation } from "@typespec/http";
|
|
6
|
-
export interface PageResponseProps {
|
|
7
|
-
operation: HttpOperation;
|
|
8
|
-
pagingOperation: PagingOperation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getPageResponseTypeRefkey(operation: HttpOperation) {
|
|
12
|
-
return refkey(operation, "page-response");
|
|
13
|
-
}
|
|
14
|
-
export function PageResponseDeclaration(props: PageResponseProps) {
|
|
15
|
-
const namePolicy = ts.useTSNamePolicy();
|
|
16
|
-
const interfaceName = namePolicy.getName(
|
|
17
|
-
props.operation.operation.name + "PageResponse",
|
|
18
|
-
"interface",
|
|
19
|
-
);
|
|
20
|
-
const definedResponses = props.pagingOperation.output;
|
|
21
|
-
// Only accept these respose items
|
|
22
|
-
const acceptedColumns = [
|
|
23
|
-
"continuationToken",
|
|
24
|
-
"pageItems",
|
|
25
|
-
"nextLink",
|
|
26
|
-
"prevLink",
|
|
27
|
-
"firstLink",
|
|
28
|
-
"lastLink",
|
|
29
|
-
];
|
|
30
|
-
// TODO: consider the nested response
|
|
31
|
-
// https://github.com/microsoft/typespec/issues/7787
|
|
32
|
-
const responseProperties: PagingProperty[] = [];
|
|
33
|
-
for (const key in definedResponses) {
|
|
34
|
-
const property = definedResponses[key as keyof typeof definedResponses];
|
|
35
|
-
if (acceptedColumns.includes(key) && !!property) {
|
|
36
|
-
responseProperties.push(property);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<ts.InterfaceDeclaration
|
|
42
|
-
export
|
|
43
|
-
name={interfaceName}
|
|
44
|
-
refkey={getPageResponseTypeRefkey(props.operation)}
|
|
45
|
-
>
|
|
46
|
-
<For each={responseProperties} line>
|
|
47
|
-
{(parameter) => (
|
|
48
|
-
<ts.InterfaceMember
|
|
49
|
-
name={parameter.property.name}
|
|
50
|
-
optional={parameter.property.optional}
|
|
51
|
-
type={<ef.TypeExpression type={parameter.property.type} />}
|
|
52
|
-
/>
|
|
53
|
-
)}
|
|
54
|
-
</For>
|
|
55
|
-
</ts.InterfaceDeclaration>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { For, refkey } from "@alloy-js/core";
|
|
2
|
-
import * as ts from "@alloy-js/typescript";
|
|
3
|
-
import type { PagingOperation, PagingProperty } from "@typespec/compiler";
|
|
4
|
-
import * as ef from "@typespec/emitter-framework/typescript";
|
|
5
|
-
import type { HttpOperation } from "@typespec/http";
|
|
6
|
-
export interface PageSettingsProps {
|
|
7
|
-
operation: HttpOperation;
|
|
8
|
-
pagingOperation: PagingOperation;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getPageSettingsTypeRefkey(operation: HttpOperation) {
|
|
12
|
-
return refkey(operation, "page-settings");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getPageSettingProperties(pagingOperation: PagingOperation) {
|
|
16
|
-
const definedSettings = pagingOperation.input;
|
|
17
|
-
// Only accept these page settings
|
|
18
|
-
const acceptedSettings = ["continuationToken", "offset", "pageSize", "pageIndex"];
|
|
19
|
-
const settingProperties: PagingProperty[] = [];
|
|
20
|
-
for (const key in definedSettings) {
|
|
21
|
-
const property = definedSettings[key as keyof typeof definedSettings];
|
|
22
|
-
if (acceptedSettings.includes(key) && !!property) {
|
|
23
|
-
settingProperties.push(property);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return settingProperties;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function PageSettingsDeclaration(props: PageSettingsProps) {
|
|
30
|
-
const namePolicy = ts.useTSNamePolicy();
|
|
31
|
-
const interfaceName = namePolicy.getName(
|
|
32
|
-
props.operation.operation.name + "PageSettings",
|
|
33
|
-
"interface",
|
|
34
|
-
);
|
|
35
|
-
const settingProperties = getPageSettingProperties(props.pagingOperation);
|
|
36
|
-
return (
|
|
37
|
-
<ts.InterfaceDeclaration
|
|
38
|
-
export
|
|
39
|
-
name={interfaceName}
|
|
40
|
-
refkey={getPageSettingsTypeRefkey(props.operation)}
|
|
41
|
-
>
|
|
42
|
-
<For each={settingProperties} line>
|
|
43
|
-
{(parameter) => (
|
|
44
|
-
<ts.InterfaceMember
|
|
45
|
-
name={parameter.property.name}
|
|
46
|
-
optional
|
|
47
|
-
type={<ef.TypeExpression type={parameter.property.type} />}
|
|
48
|
-
/>
|
|
49
|
-
)}
|
|
50
|
-
</For>
|
|
51
|
-
</ts.InterfaceDeclaration>
|
|
52
|
-
);
|
|
53
|
-
}
|