@typespec/http-client-js 0.16.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 +17 -13
- 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,78 +0,0 @@
|
|
|
1
|
-
# Request with headers, body and query parameters
|
|
2
|
-
|
|
3
|
-
A typical request with path, query header and body parameters. The body is modeled as a spread model to the operation
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service(#{ title: "Widget Service" })
|
|
9
|
-
namespace DemoService;
|
|
10
|
-
|
|
11
|
-
@test
|
|
12
|
-
model Widget {
|
|
13
|
-
@path id: string;
|
|
14
|
-
@header etag: string;
|
|
15
|
-
@query foo: string;
|
|
16
|
-
name: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@route("/widgets")
|
|
20
|
-
interface Widgets {
|
|
21
|
-
@post read(...Widget): void;
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## TyeScript
|
|
26
|
-
|
|
27
|
-
### Operations
|
|
28
|
-
|
|
29
|
-
It should generate an operation placing the parameters in the right place. The path and query parameters as part of the url template, the headers in the request options and correctly place the body payload into the body within the http request options
|
|
30
|
-
|
|
31
|
-
```ts src/api/widgetsClient/widgetsClientOperations.ts function read
|
|
32
|
-
export async function read(
|
|
33
|
-
client: WidgetsClientContext,
|
|
34
|
-
id: string,
|
|
35
|
-
etag: string,
|
|
36
|
-
foo: string,
|
|
37
|
-
name: string,
|
|
38
|
-
options?: ReadOptions,
|
|
39
|
-
): Promise<void> {
|
|
40
|
-
const path = parse("/widgets/{id}{?foo}").expand({
|
|
41
|
-
id: id,
|
|
42
|
-
foo: foo,
|
|
43
|
-
});
|
|
44
|
-
const httpRequestOptions = {
|
|
45
|
-
headers: {
|
|
46
|
-
etag: etag,
|
|
47
|
-
},
|
|
48
|
-
body: {
|
|
49
|
-
name: name,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
53
|
-
|
|
54
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
55
|
-
options?.operationOptions?.onResponse(response);
|
|
56
|
-
}
|
|
57
|
-
if (+response.status === 204 && !response.body) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
throw createRestError(response);
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Client Class
|
|
65
|
-
|
|
66
|
-
It should generate the client class with the read operation that calls the operation under api
|
|
67
|
-
|
|
68
|
-
```ts src/demoServiceClient.ts class WidgetsClient
|
|
69
|
-
export class WidgetsClient {
|
|
70
|
-
#context: WidgetsClientContext;
|
|
71
|
-
constructor(endpoint: string, options?: WidgetsClientOptions) {
|
|
72
|
-
this.#context = createWidgetsClientContext(endpoint, options);
|
|
73
|
-
}
|
|
74
|
-
async read(id: string, etag: string, foo: string, name: string, options?: ReadOptions) {
|
|
75
|
-
return read(this.#context, id, etag, foo, name, options);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Should generate a model with a property with array
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
namespace Test;
|
|
7
|
-
model Widget {
|
|
8
|
-
id: string[];
|
|
9
|
-
weight: int32[];
|
|
10
|
-
color: ("red" | "blue")[];
|
|
11
|
-
}
|
|
12
|
-
op foo(): Widget;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## TypeScript
|
|
16
|
-
|
|
17
|
-
Should generate a model with name `Widget` that contains array properties
|
|
18
|
-
|
|
19
|
-
```ts src/models/models.ts interface Widget
|
|
20
|
-
export interface Widget {
|
|
21
|
-
id: Array<string>;
|
|
22
|
-
weight: Array<number>;
|
|
23
|
-
color: Array<"red" | "blue">;
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
# Should generate a model with a property with array of record
|
|
28
|
-
|
|
29
|
-
## TypeSpec
|
|
30
|
-
|
|
31
|
-
```tsp
|
|
32
|
-
namespace Test;
|
|
33
|
-
model Widget {
|
|
34
|
-
id: Record<int32>[];
|
|
35
|
-
}
|
|
36
|
-
op foo(): Widget;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## TypeScript
|
|
40
|
-
|
|
41
|
-
Should generate a model with name `Widget` that contains array properties of record type
|
|
42
|
-
|
|
43
|
-
```ts src/models/models.ts interface Widget
|
|
44
|
-
export interface Widget {
|
|
45
|
-
id: Array<Record<string, number>>;
|
|
46
|
-
}
|
|
47
|
-
```
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# Should generate a model from the global namespace
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
model Widget {
|
|
7
|
-
id: string;
|
|
8
|
-
weight: int32;
|
|
9
|
-
color: "red" | "blue";
|
|
10
|
-
}
|
|
11
|
-
op foo(): Widget;
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## TypeScript
|
|
15
|
-
|
|
16
|
-
Should generate a model with name `Widget`
|
|
17
|
-
|
|
18
|
-
```ts src/models/models.ts interface Widget
|
|
19
|
-
export interface Widget {
|
|
20
|
-
id: string;
|
|
21
|
-
weight: number;
|
|
22
|
-
color: "red" | "blue";
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
# Should generate a model from a namespace
|
|
27
|
-
|
|
28
|
-
```tsp
|
|
29
|
-
namespace Test {
|
|
30
|
-
model TestWidget {
|
|
31
|
-
id: string;
|
|
32
|
-
weight: int32;
|
|
33
|
-
color: "red" | "blue";
|
|
34
|
-
}
|
|
35
|
-
op foo(): TestWidget;
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## TypeScript
|
|
40
|
-
|
|
41
|
-
```ts src/models/models.ts interface TestWidget
|
|
42
|
-
export interface TestWidget {
|
|
43
|
-
id: string;
|
|
44
|
-
weight: number;
|
|
45
|
-
color: "red" | "blue";
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
# Should generate a model from a nested namespace
|
|
50
|
-
|
|
51
|
-
```tsp
|
|
52
|
-
namespace Test {
|
|
53
|
-
namespace Foo {
|
|
54
|
-
model TestFooWidget {
|
|
55
|
-
id: string;
|
|
56
|
-
weight: int32;
|
|
57
|
-
color: "red" | "blue";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
op foo(): Foo.TestFooWidget;
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## TypeScript
|
|
65
|
-
|
|
66
|
-
```ts src/models/models.ts interface TestFooWidget
|
|
67
|
-
export interface TestFooWidget {
|
|
68
|
-
id: string;
|
|
69
|
-
weight: number;
|
|
70
|
-
color: "red" | "blue";
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
# Should generate a models with the same name in different namespaces
|
|
75
|
-
|
|
76
|
-
```tsp
|
|
77
|
-
namespace Test {
|
|
78
|
-
namespace Foo {
|
|
79
|
-
model Widget {
|
|
80
|
-
id: string;
|
|
81
|
-
kind: "2";
|
|
82
|
-
weight: int32;
|
|
83
|
-
color: "red" | "blue";
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
model Widget {
|
|
88
|
-
id: string;
|
|
89
|
-
kind: "1";
|
|
90
|
-
weight: int32;
|
|
91
|
-
color: "red" | "blue";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
op foo(): Widget | Foo.Widget;
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## TypeScript
|
|
99
|
-
|
|
100
|
-
```ts src/models/models.ts interface Widget
|
|
101
|
-
export interface Widget {
|
|
102
|
-
id: string;
|
|
103
|
-
kind: "1";
|
|
104
|
-
weight: number;
|
|
105
|
-
color: "red" | "blue";
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
The framework automatically resolves the name conflict.
|
|
110
|
-
|
|
111
|
-
```ts src/models/models.ts interface Widget_2
|
|
112
|
-
export interface Widget_2 {
|
|
113
|
-
id: string;
|
|
114
|
-
kind: "2";
|
|
115
|
-
weight: number;
|
|
116
|
-
color: "red" | "blue";
|
|
117
|
-
}
|
|
118
|
-
```
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Should generate a model with a property which is a dictionary
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
namespace Test;
|
|
7
|
-
|
|
8
|
-
model Widget {
|
|
9
|
-
prop: Record<int32>;
|
|
10
|
-
}
|
|
11
|
-
op foo(): Widget;
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## TypeScript
|
|
15
|
-
|
|
16
|
-
Should generate a model with name `Widget` that contains dictionary properties
|
|
17
|
-
|
|
18
|
-
```ts src/models/models.ts interface Widget
|
|
19
|
-
export interface Widget {
|
|
20
|
-
prop: Record<string, number>;
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
# Should generate a model with a property which is a dictionary of an array
|
|
25
|
-
|
|
26
|
-
## TypeSpec
|
|
27
|
-
|
|
28
|
-
```tsp
|
|
29
|
-
namespace Test;
|
|
30
|
-
model Widget {
|
|
31
|
-
prop: Record<int32[]>;
|
|
32
|
-
}
|
|
33
|
-
op foo(): Widget;
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## TypeScript
|
|
37
|
-
|
|
38
|
-
Should generate a model with name `Widget` that contains dictionary properties with array
|
|
39
|
-
|
|
40
|
-
```ts src/models/models.ts interface Widget
|
|
41
|
-
export interface Widget {
|
|
42
|
-
prop: Record<string, Array<number>>;
|
|
43
|
-
}
|
|
44
|
-
```
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
# Should handle a polymorphic Model with 2 discriminators
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
@service
|
|
5
|
-
namespace Test;
|
|
6
|
-
|
|
7
|
-
@discriminator("kind")
|
|
8
|
-
model Fish {
|
|
9
|
-
age: int32;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@discriminator("sharktype")
|
|
13
|
-
model Shark extends Fish {
|
|
14
|
-
kind: "shark";
|
|
15
|
-
sharktype: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
model Salmon extends Fish {
|
|
19
|
-
kind: "salmon";
|
|
20
|
-
friends?: Fish[];
|
|
21
|
-
hate?: Record<Fish>;
|
|
22
|
-
partner?: Fish;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
model SawShark extends Shark {
|
|
26
|
-
sharktype: "saw";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
model GoblinShark extends Shark {
|
|
30
|
-
sharktype: "goblin";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@get
|
|
34
|
-
op getModel(): Fish;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Operation
|
|
38
|
-
|
|
39
|
-
```ts src/api/testClientOperations.ts function getModel
|
|
40
|
-
export async function getModel(
|
|
41
|
-
client: TestClientContext,
|
|
42
|
-
options?: GetModelOptions,
|
|
43
|
-
): Promise<Fish> {
|
|
44
|
-
const path = parse("/").expand({});
|
|
45
|
-
const httpRequestOptions = {
|
|
46
|
-
headers: {},
|
|
47
|
-
};
|
|
48
|
-
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
49
|
-
|
|
50
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
51
|
-
options?.operationOptions?.onResponse(response);
|
|
52
|
-
}
|
|
53
|
-
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
54
|
-
return jsonFishToApplicationTransform(response.body)!;
|
|
55
|
-
}
|
|
56
|
-
throw createRestError(response);
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```ts src/models/internal/serializers.ts
|
|
61
|
-
import type { Fish, GoblinShark, Salmon, SawShark, Shark } from "../models.js";
|
|
62
|
-
|
|
63
|
-
export function decodeBase64(value: string): Uint8Array | undefined {
|
|
64
|
-
if (!value) {
|
|
65
|
-
return value as any;
|
|
66
|
-
}
|
|
67
|
-
// Normalize Base64URL to Base64
|
|
68
|
-
const base64 = value
|
|
69
|
-
.replace(/-/g, "+")
|
|
70
|
-
.replace(/_/g, "/")
|
|
71
|
-
.padEnd(value.length + ((4 - (value.length % 4)) % 4), "=");
|
|
72
|
-
|
|
73
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
74
|
-
}
|
|
75
|
-
export function encodeUint8Array(
|
|
76
|
-
value: Uint8Array | undefined | null,
|
|
77
|
-
encoding: BufferEncoding,
|
|
78
|
-
): string | undefined {
|
|
79
|
-
if (!value) {
|
|
80
|
-
return value as any;
|
|
81
|
-
}
|
|
82
|
-
return Buffer.from(value).toString(encoding);
|
|
83
|
-
}
|
|
84
|
-
export function dateDeserializer(date?: string | null): Date {
|
|
85
|
-
if (!date) {
|
|
86
|
-
return date as any;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return new Date(date);
|
|
90
|
-
}
|
|
91
|
-
export function dateRfc7231Deserializer(date?: string | null): Date {
|
|
92
|
-
if (!date) {
|
|
93
|
-
return date as any;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return new Date(date);
|
|
97
|
-
}
|
|
98
|
-
export function dateRfc3339Serializer(date?: Date | null): string {
|
|
99
|
-
if (!date) {
|
|
100
|
-
return date as any;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return date.toISOString();
|
|
104
|
-
}
|
|
105
|
-
export function dateRfc7231Serializer(date?: Date | null): string {
|
|
106
|
-
if (!date) {
|
|
107
|
-
return date as any;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return date.toUTCString();
|
|
111
|
-
}
|
|
112
|
-
export function dateUnixTimestampSerializer(date?: Date | null): number {
|
|
113
|
-
if (!date) {
|
|
114
|
-
return date as any;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return Math.floor(date.getTime() / 1000);
|
|
118
|
-
}
|
|
119
|
-
export function dateUnixTimestampDeserializer(date?: number | null): Date {
|
|
120
|
-
if (!date) {
|
|
121
|
-
return date as any;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return new Date(date * 1000);
|
|
125
|
-
}
|
|
126
|
-
export function jsonFishToTransportDiscriminator(input_?: Fish): any {
|
|
127
|
-
if (!input_) {
|
|
128
|
-
return input_ as any;
|
|
129
|
-
}
|
|
130
|
-
const discriminatorValue = input_.kind;
|
|
131
|
-
if (discriminatorValue === "shark") {
|
|
132
|
-
return jsonSharkToTransportTransform(input_ as any)!;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (discriminatorValue === "salmon") {
|
|
136
|
-
return jsonSalmonToTransportTransform(input_ as any)!;
|
|
137
|
-
}
|
|
138
|
-
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
139
|
-
return input_ as any;
|
|
140
|
-
}
|
|
141
|
-
export function jsonFishToTransportTransform(input_?: Fish | null): any {
|
|
142
|
-
if (!input_) {
|
|
143
|
-
return input_ as any;
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
...jsonFishToTransportDiscriminator(input_),
|
|
147
|
-
age: input_.age,
|
|
148
|
-
kind: input_.kind,
|
|
149
|
-
}!;
|
|
150
|
-
}
|
|
151
|
-
export function jsonFishToApplicationDiscriminator(input_?: any): Fish {
|
|
152
|
-
if (!input_) {
|
|
153
|
-
return input_ as any;
|
|
154
|
-
}
|
|
155
|
-
const discriminatorValue = input_.kind;
|
|
156
|
-
if (discriminatorValue === "shark") {
|
|
157
|
-
return jsonSharkToApplicationTransform(input_ as any)!;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (discriminatorValue === "salmon") {
|
|
161
|
-
return jsonSalmonToApplicationTransform(input_ as any)!;
|
|
162
|
-
}
|
|
163
|
-
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
164
|
-
return input_ as any;
|
|
165
|
-
}
|
|
166
|
-
export function jsonFishToApplicationTransform(input_?: any): Fish {
|
|
167
|
-
if (!input_) {
|
|
168
|
-
return input_ as any;
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
...jsonFishToApplicationDiscriminator(input_),
|
|
172
|
-
age: input_.age,
|
|
173
|
-
kind: input_.kind,
|
|
174
|
-
}!;
|
|
175
|
-
}
|
|
176
|
-
export function jsonSharkToTransportDiscriminator(input_?: Shark): any {
|
|
177
|
-
if (!input_) {
|
|
178
|
-
return input_ as any;
|
|
179
|
-
}
|
|
180
|
-
const discriminatorValue = input_.sharktype;
|
|
181
|
-
if (discriminatorValue === "saw") {
|
|
182
|
-
return jsonSawSharkToTransportTransform(input_ as any)!;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (discriminatorValue === "goblin") {
|
|
186
|
-
return jsonGoblinSharkToTransportTransform(input_ as any)!;
|
|
187
|
-
}
|
|
188
|
-
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
189
|
-
return input_ as any;
|
|
190
|
-
}
|
|
191
|
-
export function jsonSharkToTransportTransform(input_?: Shark | null): any {
|
|
192
|
-
if (!input_) {
|
|
193
|
-
return input_ as any;
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
...jsonSharkToTransportDiscriminator(input_),
|
|
197
|
-
kind: input_.kind,
|
|
198
|
-
sharktype: input_.sharktype,
|
|
199
|
-
age: input_.age,
|
|
200
|
-
}!;
|
|
201
|
-
}
|
|
202
|
-
export function jsonSharkToApplicationDiscriminator(input_?: any): Shark {
|
|
203
|
-
if (!input_) {
|
|
204
|
-
return input_ as any;
|
|
205
|
-
}
|
|
206
|
-
const discriminatorValue = input_.sharktype;
|
|
207
|
-
if (discriminatorValue === "saw") {
|
|
208
|
-
return jsonSawSharkToApplicationTransform(input_ as any)!;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (discriminatorValue === "goblin") {
|
|
212
|
-
return jsonGoblinSharkToApplicationTransform(input_ as any)!;
|
|
213
|
-
}
|
|
214
|
-
console.warn(`Received unknown kind: ` + discriminatorValue);
|
|
215
|
-
return input_ as any;
|
|
216
|
-
}
|
|
217
|
-
export function jsonSharkToApplicationTransform(input_?: any): Shark {
|
|
218
|
-
if (!input_) {
|
|
219
|
-
return input_ as any;
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
...jsonSharkToApplicationDiscriminator(input_),
|
|
223
|
-
kind: input_.kind,
|
|
224
|
-
sharktype: input_.sharktype,
|
|
225
|
-
age: input_.age,
|
|
226
|
-
}!;
|
|
227
|
-
}
|
|
228
|
-
export function jsonSawSharkToTransportTransform(input_?: SawShark | null): any {
|
|
229
|
-
if (!input_) {
|
|
230
|
-
return input_ as any;
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
sharktype: input_.sharktype,
|
|
234
|
-
kind: input_.kind,
|
|
235
|
-
age: input_.age,
|
|
236
|
-
}!;
|
|
237
|
-
}
|
|
238
|
-
export function jsonSawSharkToApplicationTransform(input_?: any): SawShark {
|
|
239
|
-
if (!input_) {
|
|
240
|
-
return input_ as any;
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
sharktype: input_.sharktype,
|
|
244
|
-
kind: input_.kind,
|
|
245
|
-
age: input_.age,
|
|
246
|
-
}!;
|
|
247
|
-
}
|
|
248
|
-
export function jsonGoblinSharkToTransportTransform(input_?: GoblinShark | null): any {
|
|
249
|
-
if (!input_) {
|
|
250
|
-
return input_ as any;
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
sharktype: input_.sharktype,
|
|
254
|
-
kind: input_.kind,
|
|
255
|
-
age: input_.age,
|
|
256
|
-
}!;
|
|
257
|
-
}
|
|
258
|
-
export function jsonGoblinSharkToApplicationTransform(input_?: any): GoblinShark {
|
|
259
|
-
if (!input_) {
|
|
260
|
-
return input_ as any;
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
sharktype: input_.sharktype,
|
|
264
|
-
kind: input_.kind,
|
|
265
|
-
age: input_.age,
|
|
266
|
-
}!;
|
|
267
|
-
}
|
|
268
|
-
export function jsonSalmonToTransportTransform(input_?: Salmon | null): any {
|
|
269
|
-
if (!input_) {
|
|
270
|
-
return input_ as any;
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
kind: input_.kind,
|
|
274
|
-
friends: jsonArrayFishToTransportTransform(input_.friends),
|
|
275
|
-
hate: jsonRecordFishToTransportTransform(input_.hate),
|
|
276
|
-
partner: jsonFishToTransportTransform(input_.partner),
|
|
277
|
-
age: input_.age,
|
|
278
|
-
}!;
|
|
279
|
-
}
|
|
280
|
-
export function jsonSalmonToApplicationTransform(input_?: any): Salmon {
|
|
281
|
-
if (!input_) {
|
|
282
|
-
return input_ as any;
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
kind: input_.kind,
|
|
286
|
-
friends: jsonArrayFishToApplicationTransform(input_.friends),
|
|
287
|
-
hate: jsonRecordFishToApplicationTransform(input_.hate),
|
|
288
|
-
partner: jsonFishToApplicationTransform(input_.partner),
|
|
289
|
-
age: input_.age,
|
|
290
|
-
}!;
|
|
291
|
-
}
|
|
292
|
-
export function jsonArrayFishToTransportTransform(items_?: Array<Fish> | null): any {
|
|
293
|
-
if (!items_) {
|
|
294
|
-
return items_ as any;
|
|
295
|
-
}
|
|
296
|
-
const _transformedArray = [];
|
|
297
|
-
|
|
298
|
-
for (const item of items_ ?? []) {
|
|
299
|
-
const transformedItem = jsonFishToTransportTransform(item as any);
|
|
300
|
-
_transformedArray.push(transformedItem);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return _transformedArray as any;
|
|
304
|
-
}
|
|
305
|
-
export function jsonArrayFishToApplicationTransform(items_?: any): Array<Fish> {
|
|
306
|
-
if (!items_) {
|
|
307
|
-
return items_ as any;
|
|
308
|
-
}
|
|
309
|
-
const _transformedArray = [];
|
|
310
|
-
|
|
311
|
-
for (const item of items_ ?? []) {
|
|
312
|
-
const transformedItem = jsonFishToApplicationTransform(item as any);
|
|
313
|
-
_transformedArray.push(transformedItem);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return _transformedArray as any;
|
|
317
|
-
}
|
|
318
|
-
export function jsonRecordFishToTransportTransform(items_?: Record<string, any> | null): any {
|
|
319
|
-
if (!items_) {
|
|
320
|
-
return items_ as any;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const _transformedRecord: any = {};
|
|
324
|
-
|
|
325
|
-
for (const [key, value] of Object.entries(items_ ?? {})) {
|
|
326
|
-
const transformedItem = jsonFishToTransportTransform(value as any);
|
|
327
|
-
_transformedRecord[key] = transformedItem;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return _transformedRecord;
|
|
331
|
-
}
|
|
332
|
-
export function jsonRecordFishToApplicationTransform(items_?: any): Record<string, any> {
|
|
333
|
-
if (!items_) {
|
|
334
|
-
return items_ as any;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const _transformedRecord: any = {};
|
|
338
|
-
|
|
339
|
-
for (const [key, value] of Object.entries(items_ ?? {})) {
|
|
340
|
-
const transformedItem = jsonFishToApplicationTransform(value as any);
|
|
341
|
-
_transformedRecord[key] = transformedItem;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return _transformedRecord;
|
|
345
|
-
}
|
|
346
|
-
```
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# Should model correctly a discriminated type by inheritance
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
@service
|
|
5
|
-
namespace Test;
|
|
6
|
-
@doc("Define a base class in the legacy way. Discriminator property is not explicitly defined in the model.")
|
|
7
|
-
@discriminator("kind")
|
|
8
|
-
model Dinosaur {
|
|
9
|
-
size: int32;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@doc("The second level legacy model in polymorphic single level inheritance.")
|
|
13
|
-
model TRex extends Dinosaur {
|
|
14
|
-
kind: "t-rex";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@get
|
|
18
|
-
op getLegacyModel(): Dinosaur;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Models
|
|
22
|
-
|
|
23
|
-
```ts src/models/models.ts interface Dinosaur
|
|
24
|
-
export interface Dinosaur {
|
|
25
|
-
size: number;
|
|
26
|
-
kind: string;
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```ts src/models/models.ts interface TRex
|
|
31
|
-
export interface TRex extends Dinosaur {
|
|
32
|
-
kind: "t-rex";
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Serializer
|
|
37
|
-
|
|
38
|
-
```ts src/models/internal/serializers.ts function jsonDinosaurToTransportTransform
|
|
39
|
-
export function jsonDinosaurToTransportTransform(input_?: Dinosaur | null): any {
|
|
40
|
-
if (!input_) {
|
|
41
|
-
return input_ as any;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
...jsonDinosaurToTransportDiscriminator(input_),
|
|
45
|
-
size: input_.size,
|
|
46
|
-
kind: input_.kind,
|
|
47
|
-
}!;
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
```ts src/models/internal/serializers.ts function jsonTRexToTransportTransform
|
|
52
|
-
export function jsonTRexToTransportTransform(input_?: TRex | null): any {
|
|
53
|
-
if (!input_) {
|
|
54
|
-
return input_ as any;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
kind: input_.kind,
|
|
58
|
-
size: input_.size,
|
|
59
|
-
}!;
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Deserializer
|
|
64
|
-
|
|
65
|
-
```ts src/models/internal/serializers.ts function jsonDinosaurToApplicationTransform
|
|
66
|
-
export function jsonDinosaurToApplicationTransform(input_?: any): Dinosaur {
|
|
67
|
-
if (!input_) {
|
|
68
|
-
return input_ as any;
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
...jsonDinosaurToApplicationDiscriminator(input_),
|
|
72
|
-
size: input_.size,
|
|
73
|
-
kind: input_.kind,
|
|
74
|
-
}!;
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
```ts src/models/internal/serializers.ts function jsonTRexToApplicationTransform
|
|
79
|
-
export function jsonTRexToApplicationTransform(input_?: any): TRex {
|
|
80
|
-
if (!input_) {
|
|
81
|
-
return input_ as any;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
kind: input_.kind,
|
|
85
|
-
size: input_.size,
|
|
86
|
-
}!;
|
|
87
|
-
}
|
|
88
|
-
```
|