@typespec/http-client-js 0.16.2-dev.1 → 0.16.2-dev.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 +13 -9
- 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,33 +0,0 @@
|
|
|
1
|
-
# Should handle when provided a constant header
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
@service
|
|
5
|
-
namespace Test;
|
|
6
|
-
model Foo {
|
|
7
|
-
name: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
@get op foo(@header accept: "application/xml"): Foo;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Operation
|
|
14
|
-
|
|
15
|
-
```ts src/api/testClientOperations.ts function foo
|
|
16
|
-
export async function foo(client: TestClientContext, options?: FooOptions): Promise<Foo> {
|
|
17
|
-
const path = parse("/").expand({});
|
|
18
|
-
const httpRequestOptions = {
|
|
19
|
-
headers: {
|
|
20
|
-
accept: options?.accept ?? "application/xml",
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
24
|
-
|
|
25
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
26
|
-
options?.operationOptions?.onResponse(response);
|
|
27
|
-
}
|
|
28
|
-
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
29
|
-
return jsonFooToApplicationTransform(response.body)!;
|
|
30
|
-
}
|
|
31
|
-
throw createRestError(response);
|
|
32
|
-
}
|
|
33
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Should generate a basic create http operation
|
|
2
|
-
|
|
3
|
-
This is a simple get operation with no request payload or parameters and a simple model return.
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service
|
|
9
|
-
namespace Test;
|
|
10
|
-
model Widget {
|
|
11
|
-
id: string;
|
|
12
|
-
total_weight: int32;
|
|
13
|
-
color: "red" | "blue";
|
|
14
|
-
is_required?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@post op foo(...Widget): void;
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## TypeScript
|
|
21
|
-
|
|
22
|
-
### Operation
|
|
23
|
-
|
|
24
|
-
Generates the operation function which prepares the request options. In this case it has not query, path or header parameters. No body either so headers is empty.
|
|
25
|
-
|
|
26
|
-
The response body is of type Widget so the right transform should be imported to transform the widget from its wire format to the application form.
|
|
27
|
-
|
|
28
|
-
It should throw an exception if an unexpected status code is received
|
|
29
|
-
|
|
30
|
-
```ts src/api/testClientOperations.ts function foo
|
|
31
|
-
export async function foo(
|
|
32
|
-
client: TestClientContext,
|
|
33
|
-
id: string,
|
|
34
|
-
totalWeight: number,
|
|
35
|
-
color: "red" | "blue",
|
|
36
|
-
options?: FooOptions,
|
|
37
|
-
): Promise<void> {
|
|
38
|
-
const path = parse("/").expand({});
|
|
39
|
-
const httpRequestOptions = {
|
|
40
|
-
headers: {},
|
|
41
|
-
body: {
|
|
42
|
-
id: id,
|
|
43
|
-
total_weight: totalWeight,
|
|
44
|
-
color: color,
|
|
45
|
-
is_required: options?.isRequired,
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
49
|
-
|
|
50
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
51
|
-
options?.operationOptions?.onResponse(response);
|
|
52
|
-
}
|
|
53
|
-
if (+response.status === 204 && !response.body) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
throw createRestError(response);
|
|
57
|
-
}
|
|
58
|
-
```
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Should call on response after receiving the response from the service.
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service
|
|
7
|
-
namespace Test;
|
|
8
|
-
model Widget {
|
|
9
|
-
id: string;
|
|
10
|
-
total_weight: int32;
|
|
11
|
-
color: "red" | "blue";
|
|
12
|
-
is_required?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@post op foo(...Widget): void;
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## TypeScript
|
|
19
|
-
|
|
20
|
-
### Operation
|
|
21
|
-
|
|
22
|
-
Generates a function that call the onResponse callback
|
|
23
|
-
|
|
24
|
-
```ts src/api/testClientOperations.ts function foo
|
|
25
|
-
export async function foo(
|
|
26
|
-
client: TestClientContext,
|
|
27
|
-
id: string,
|
|
28
|
-
totalWeight: number,
|
|
29
|
-
color: "red" | "blue",
|
|
30
|
-
options?: FooOptions,
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
const path = parse("/").expand({});
|
|
33
|
-
const httpRequestOptions = {
|
|
34
|
-
headers: {},
|
|
35
|
-
body: {
|
|
36
|
-
id: id,
|
|
37
|
-
total_weight: totalWeight,
|
|
38
|
-
color: color,
|
|
39
|
-
is_required: options?.isRequired,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
43
|
-
|
|
44
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
45
|
-
options?.operationOptions?.onResponse(response);
|
|
46
|
-
}
|
|
47
|
-
if (+response.status === 204 && !response.body) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
throw createRestError(response);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Should handle a request with an optional body
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
namespace Test;
|
|
5
|
-
model BodyModel {
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@route("/set")
|
|
10
|
-
@post
|
|
11
|
-
op set(@body body?: BodyModel): NoContentResponse;
|
|
12
|
-
|
|
13
|
-
@route("/omit")
|
|
14
|
-
@post
|
|
15
|
-
op omit(@body body?: BodyModel): NoContentResponse;
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Operations
|
|
19
|
-
|
|
20
|
-
```ts src/api/testClientOperations.ts function set
|
|
21
|
-
export async function set(client: TestClientContext, options?: SetOptions): Promise<void> {
|
|
22
|
-
const path = parse("/set").expand({});
|
|
23
|
-
const httpRequestOptions = {
|
|
24
|
-
headers: {},
|
|
25
|
-
body: jsonBodyModelToTransportTransform(options?.body),
|
|
26
|
-
};
|
|
27
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
28
|
-
|
|
29
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
30
|
-
options?.operationOptions?.onResponse(response);
|
|
31
|
-
}
|
|
32
|
-
if (+response.status === 204 && !response.body) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
throw createRestError(response);
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Transform
|
|
40
|
-
|
|
41
|
-
```ts src/models/internal/serializers.ts function jsonBodyModelToTransportTransform
|
|
42
|
-
export function jsonBodyModelToTransportTransform(input_?: BodyModel | null): any {
|
|
43
|
-
if (!input_) {
|
|
44
|
-
return input_ as any;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
name: input_.name,
|
|
48
|
-
}!;
|
|
49
|
-
}
|
|
50
|
-
```
|
|
@@ -1,242 +0,0 @@
|
|
|
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: getPagedResponse as any,
|
|
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
|
-
constructor(endpoint: string, options?: TestClientOptions) {
|
|
114
|
-
this.#context = createTestClientContext(endpoint, options);
|
|
115
|
-
}
|
|
116
|
-
link(filter: string, options?: LinkOptions) {
|
|
117
|
-
return link(this.#context, filter, options);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
# Should emit a paging operation if it is nextLink paging pattern
|
|
123
|
-
|
|
124
|
-
```tsp
|
|
125
|
-
@service
|
|
126
|
-
namespace Test;
|
|
127
|
-
model Pet {
|
|
128
|
-
id: string;
|
|
129
|
-
name: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
@route("/link")
|
|
133
|
-
@list
|
|
134
|
-
op link(@query filter: string, @pageSize @query maxPageSize?: int32): {
|
|
135
|
-
@pageItems
|
|
136
|
-
pets: Pet[];
|
|
137
|
-
|
|
138
|
-
@nextLink link?: string;
|
|
139
|
-
};
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Operation
|
|
143
|
-
|
|
144
|
-
```ts src/api/testClientOperations.ts function link
|
|
145
|
-
export function link(
|
|
146
|
-
client: TestClientContext,
|
|
147
|
-
filter: string,
|
|
148
|
-
options?: LinkOptions,
|
|
149
|
-
): PagedAsyncIterableIterator<Pet, LinkPageResponse, LinkPageSettings> {
|
|
150
|
-
function getElements(response: LinkPageResponse) {
|
|
151
|
-
return response.pets;
|
|
152
|
-
}
|
|
153
|
-
async function getPagedResponse(nextToken?: string, settings?: LinkPageSettings) {
|
|
154
|
-
let response: PathUncheckedResponse;
|
|
155
|
-
if (nextToken) {
|
|
156
|
-
response = await client.pathUnchecked(nextToken).get();
|
|
157
|
-
} else {
|
|
158
|
-
const combinedOptions = { ...options, ...settings };
|
|
159
|
-
response = await linkSend(client, filter, combinedOptions);
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
pagedResponse: await linkDeserialize(response, options),
|
|
163
|
-
nextToken: response.body["link"],
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
return buildPagedAsyncIterator<Pet, LinkPageResponse, LinkPageSettings>({
|
|
167
|
-
getElements,
|
|
168
|
-
getPagedResponse: getPagedResponse as any,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
```ts src/api/testClientOperations.ts function linkSend
|
|
174
|
-
async function linkSend(client: TestClientContext, filter: string, options?: Record<string, any>) {
|
|
175
|
-
const path = parse("/link{?filter,maxPageSize}").expand({
|
|
176
|
-
filter: filter,
|
|
177
|
-
...(options?.maxPageSize && { maxPageSize: options.maxPageSize }),
|
|
178
|
-
});
|
|
179
|
-
const httpRequestOptions = {
|
|
180
|
-
headers: {},
|
|
181
|
-
};
|
|
182
|
-
return await client.pathUnchecked(path).get(httpRequestOptions);
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
```ts src/api/testClientOperations.ts function linkDeserialize
|
|
187
|
-
function linkDeserialize(response: PathUncheckedResponse, options?: LinkOptions) {
|
|
188
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
189
|
-
options?.operationOptions?.onResponse(response);
|
|
190
|
-
}
|
|
191
|
-
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
192
|
-
return {
|
|
193
|
-
pets: jsonArrayPetToApplicationTransform(response.body.pets),
|
|
194
|
-
link: response.body.link,
|
|
195
|
-
}!;
|
|
196
|
-
}
|
|
197
|
-
throw createRestError(response);
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## Options
|
|
202
|
-
|
|
203
|
-
The options bag should like all the optional parameters of the operation
|
|
204
|
-
|
|
205
|
-
```ts src/api/testClientOperations.ts interface LinkOptions
|
|
206
|
-
export interface LinkOptions extends OperationOptions {}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## PageSettings
|
|
210
|
-
|
|
211
|
-
Page settings and will be used as input for byPage function.
|
|
212
|
-
|
|
213
|
-
```ts src/api/testClientOperations.ts interface LinkPageSettings
|
|
214
|
-
export interface LinkPageSettings {
|
|
215
|
-
maxPageSize?: number;
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## LinkPageResponse
|
|
220
|
-
|
|
221
|
-
Page responses and will be used as output for byPage function.
|
|
222
|
-
|
|
223
|
-
```ts src/api/testClientOperations.ts interface LinkPageResponse
|
|
224
|
-
export interface LinkPageResponse {
|
|
225
|
-
pets: Array<Pet>;
|
|
226
|
-
link?: string;
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Client
|
|
231
|
-
|
|
232
|
-
```ts src/testClient.ts class TestClient
|
|
233
|
-
export class TestClient {
|
|
234
|
-
#context: TestClientContext;
|
|
235
|
-
constructor(endpoint: string, options?: TestClientOptions) {
|
|
236
|
-
this.#context = createTestClientContext(endpoint, options);
|
|
237
|
-
}
|
|
238
|
-
link(filter: string, options?: LinkOptions) {
|
|
239
|
-
return link(this.#context, filter, options);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
```
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Request with that has a path parameter directly on the operation
|
|
2
|
-
|
|
3
|
-
A request that sends a request with a path parameter as a property of the input model
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
The path parameter is a property of a spread model input in the operation signature
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Widget Service" })
|
|
11
|
-
namespace DemoService;
|
|
12
|
-
|
|
13
|
-
model ReadParams {
|
|
14
|
-
@path
|
|
15
|
-
id: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@route("/widgets")
|
|
19
|
-
@tag("Widgets")
|
|
20
|
-
interface Widgets {
|
|
21
|
-
@test @get read(...ReadParams): void;
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## TyeScript
|
|
26
|
-
|
|
27
|
-
### Operations
|
|
28
|
-
|
|
29
|
-
It should generate an operation that places the path parameter in the url template.
|
|
30
|
-
|
|
31
|
-
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
32
|
-
export async function read(
|
|
33
|
-
client: WidgetsClientContext,
|
|
34
|
-
id: string,
|
|
35
|
-
options?: ReadOptions,
|
|
36
|
-
): Promise<void> {
|
|
37
|
-
const path = parse("/widgets/{id}").expand({
|
|
38
|
-
id: id,
|
|
39
|
-
});
|
|
40
|
-
const httpRequestOptions = {
|
|
41
|
-
headers: {},
|
|
42
|
-
};
|
|
43
|
-
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
44
|
-
|
|
45
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
46
|
-
options?.operationOptions?.onResponse(response);
|
|
47
|
-
}
|
|
48
|
-
if (+response.status === 204 && !response.body) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
throw createRestError(response);
|
|
52
|
-
}
|
|
53
|
-
```
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Request with that has a path parameter directly on the operation
|
|
2
|
-
|
|
3
|
-
A request that sends a request with a path parameter directly on the operation signature
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
The path parameter is a positional parameter in the operation signature
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Widget Service" })
|
|
11
|
-
namespace DemoService;
|
|
12
|
-
|
|
13
|
-
@route("/widgets")
|
|
14
|
-
@tag("Widgets")
|
|
15
|
-
interface Widgets {
|
|
16
|
-
@test @get read(@path id: string): void;
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## TyeScript
|
|
21
|
-
|
|
22
|
-
### Operations
|
|
23
|
-
|
|
24
|
-
It should generate an operation that places the path parameter in the url template.
|
|
25
|
-
|
|
26
|
-
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
27
|
-
export async function read(
|
|
28
|
-
client: WidgetsClientContext,
|
|
29
|
-
id: string,
|
|
30
|
-
options?: ReadOptions,
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
const path = parse("/widgets/{id}").expand({
|
|
33
|
-
id: id,
|
|
34
|
-
});
|
|
35
|
-
const httpRequestOptions = {
|
|
36
|
-
headers: {},
|
|
37
|
-
};
|
|
38
|
-
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
39
|
-
|
|
40
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
41
|
-
options?.operationOptions?.onResponse(response);
|
|
42
|
-
}
|
|
43
|
-
if (+response.status === 204 && !response.body) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
throw createRestError(response);
|
|
47
|
-
}
|
|
48
|
-
```
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Should handle a header parameter within @bodyRoot
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
namespace Test;
|
|
5
|
-
|
|
6
|
-
model VisibilityModel {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
age?: string;
|
|
10
|
-
@header foo?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@head op headModel(@bodyRoot input: VisibilityModel): OkResponse;
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Operation
|
|
17
|
-
|
|
18
|
-
```ts src/api/testClientOperations.ts function headModel
|
|
19
|
-
export async function headModel(
|
|
20
|
-
client: TestClientContext,
|
|
21
|
-
input: VisibilityModel,
|
|
22
|
-
options?: HeadModelOptions,
|
|
23
|
-
): Promise<void> {
|
|
24
|
-
const path = parse("/").expand({});
|
|
25
|
-
const httpRequestOptions = {
|
|
26
|
-
headers: {
|
|
27
|
-
...(input.foo && { foo: input.foo }),
|
|
28
|
-
},
|
|
29
|
-
body: jsonVisibilityModelToTransportTransform(input),
|
|
30
|
-
};
|
|
31
|
-
const response = await client.pathUnchecked(path).head(httpRequestOptions);
|
|
32
|
-
|
|
33
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
34
|
-
options?.operationOptions?.onResponse(response);
|
|
35
|
-
}
|
|
36
|
-
if (+response.status === 200 && !response.body) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
throw createRestError(response);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Request with a scalar body
|
|
2
|
-
|
|
3
|
-
A request that sends a body payload of scalar type
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
The body is modeled as an explicit body property of type int32
|
|
8
|
-
|
|
9
|
-
```tsp
|
|
10
|
-
@service(#{ title: "Widget Service" })
|
|
11
|
-
namespace DemoService;
|
|
12
|
-
|
|
13
|
-
@route("/widgets")
|
|
14
|
-
@tag("Widgets")
|
|
15
|
-
interface Widgets {
|
|
16
|
-
@test @post create(@body count: int32): void;
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## TyeScript
|
|
21
|
-
|
|
22
|
-
### Operations
|
|
23
|
-
|
|
24
|
-
It should generate an operation that sends the body as number. Since the body is an explicit property, a serializer function for the operation is created
|
|
25
|
-
|
|
26
|
-
```ts src/api/widgetsClient/widgetsClientOperations.ts function create
|
|
27
|
-
export async function create(
|
|
28
|
-
client: WidgetsClientContext,
|
|
29
|
-
count: number,
|
|
30
|
-
options?: CreateOptions,
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
const path = parse("/widgets").expand({});
|
|
33
|
-
const httpRequestOptions = {
|
|
34
|
-
headers: {},
|
|
35
|
-
body: count,
|
|
36
|
-
};
|
|
37
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
38
|
-
|
|
39
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
40
|
-
options?.operationOptions?.onResponse(response);
|
|
41
|
-
}
|
|
42
|
-
if (+response.status === 204 && !response.body) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
throw createRestError(response);
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Serializers
|
|
50
|
-
|
|
51
|
-
The correct serializer function is created, since this is a number payload, no additional serialization is needed.
|
|
52
|
-
|
|
53
|
-
```ts src/models/internal/serializers.ts function createPayloadToTransport
|
|
54
|
-
export function createPayloadToTransport(payload: number) {
|
|
55
|
-
return payload!;
|
|
56
|
-
}
|
|
57
|
-
```
|