@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,29 +0,0 @@
|
|
|
1
|
-
# Should generate inline models
|
|
2
|
-
|
|
3
|
-
When a model property's type is defined as an anonymous model, the TypeScript emitter should generate the model definition inline, matching the spec closely.
|
|
4
|
-
|
|
5
|
-
## Typespec
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
namespace Test;
|
|
9
|
-
model Widget {
|
|
10
|
-
name: string;
|
|
11
|
-
subWidget: {
|
|
12
|
-
location: string;
|
|
13
|
-
age?: int32;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
op foo(): Widget;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Typescript
|
|
20
|
-
|
|
21
|
-
```ts src/models/models.ts interface Widget
|
|
22
|
-
export interface Widget {
|
|
23
|
-
name: string;
|
|
24
|
-
subWidget: {
|
|
25
|
-
location: string;
|
|
26
|
-
age?: number;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
```
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Should generate a model that spreads a Record
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service
|
|
7
|
-
namespace Test;
|
|
8
|
-
model ExtraFeature {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
value: int32;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
model Dog {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
color: "black" | "brown";
|
|
18
|
-
...Record<ExtraFeature>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
op foo(): Dog;
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Models
|
|
25
|
-
|
|
26
|
-
```ts src/models/models.ts interface ExtraFeature
|
|
27
|
-
export interface ExtraFeature {
|
|
28
|
-
id: string;
|
|
29
|
-
name: string;
|
|
30
|
-
value: number;
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
```ts src/models/models.ts interface Dog
|
|
35
|
-
export interface Dog {
|
|
36
|
-
id: string;
|
|
37
|
-
name: string;
|
|
38
|
-
color: "black" | "brown";
|
|
39
|
-
additionalProperties?: Record<string, ExtraFeature>;
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Serializer
|
|
44
|
-
|
|
45
|
-
```ts src/models/internal/serializers.ts function jsonDogToTransportTransform
|
|
46
|
-
export function jsonDogToTransportTransform(input_?: Dog | null): any {
|
|
47
|
-
if (!input_) {
|
|
48
|
-
return input_ as any;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
...jsonRecordExtraFeatureToTransportTransform(input_.additionalProperties),
|
|
52
|
-
id: input_.id,
|
|
53
|
-
name: input_.name,
|
|
54
|
-
color: input_.color,
|
|
55
|
-
}!;
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Deserializer
|
|
60
|
-
|
|
61
|
-
```ts src/models/internal/serializers.ts function jsonDogToApplicationTransform
|
|
62
|
-
export function jsonDogToApplicationTransform(input_?: any): Dog {
|
|
63
|
-
if (!input_) {
|
|
64
|
-
return input_ as any;
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
additionalProperties: jsonRecordExtraFeatureToApplicationTransform(
|
|
68
|
-
(({ id, name, color, ...rest }) => rest)(input_),
|
|
69
|
-
),
|
|
70
|
-
id: input_.id,
|
|
71
|
-
name: input_.name,
|
|
72
|
-
color: input_.color,
|
|
73
|
-
}!;
|
|
74
|
-
}
|
|
75
|
-
```
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# Should generate a model that extends another model
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service
|
|
7
|
-
namespace Test;
|
|
8
|
-
model Pet {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
model Dog extends Pet {
|
|
14
|
-
color: "black" | "brown";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
op foo(): Dog;
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Models
|
|
21
|
-
|
|
22
|
-
Should generate an interface for the base model and an interface for Dog that extends Pet
|
|
23
|
-
|
|
24
|
-
```ts src/models/models.ts interface Pet
|
|
25
|
-
export interface Pet {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string;
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
```ts src/models/models.ts interface Dog
|
|
32
|
-
export interface Dog extends Pet {
|
|
33
|
-
color: "black" | "brown";
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Serializers
|
|
38
|
-
|
|
39
|
-
Should generate a serializer for Pet. Also a serializer for Dog that calls the Pet serializer
|
|
40
|
-
|
|
41
|
-
### Pet Serializer
|
|
42
|
-
|
|
43
|
-
```ts src/models/internal/serializers.ts function jsonPetToTransportTransform
|
|
44
|
-
export function jsonPetToTransportTransform(input_?: Pet | null): any {
|
|
45
|
-
if (!input_) {
|
|
46
|
-
return input_ as any;
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
id: input_.id,
|
|
50
|
-
name: input_.name,
|
|
51
|
-
}!;
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Pet deserializer
|
|
56
|
-
|
|
57
|
-
```ts src/models/internal/serializers.ts function jsonPetToApplicationTransform
|
|
58
|
-
export function jsonPetToApplicationTransform(input_?: any): Pet {
|
|
59
|
-
if (!input_) {
|
|
60
|
-
return input_ as any;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
id: input_.id,
|
|
64
|
-
name: input_.name,
|
|
65
|
-
}!;
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Dog Serializer
|
|
70
|
-
|
|
71
|
-
```ts src/models/internal/serializers.ts function jsonDogToTransportTransform
|
|
72
|
-
export function jsonDogToTransportTransform(input_?: Dog | null): any {
|
|
73
|
-
if (!input_) {
|
|
74
|
-
return input_ as any;
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
color: input_.color,
|
|
78
|
-
id: input_.id,
|
|
79
|
-
name: input_.name,
|
|
80
|
-
}!;
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Dog deserializer
|
|
85
|
-
|
|
86
|
-
```ts src/models/internal/serializers.ts function jsonDogToApplicationTransform
|
|
87
|
-
export function jsonDogToApplicationTransform(input_?: any): Dog {
|
|
88
|
-
if (!input_) {
|
|
89
|
-
return input_ as any;
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
color: input_.color,
|
|
93
|
-
id: input_.id,
|
|
94
|
-
name: input_.name,
|
|
95
|
-
}!;
|
|
96
|
-
}
|
|
97
|
-
```
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Should generate a model that spreads another model
|
|
2
|
-
|
|
3
|
-
## TypeSpec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service
|
|
7
|
-
namespace Test;
|
|
8
|
-
model Pet {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
model Dog {
|
|
14
|
-
...Pet;
|
|
15
|
-
color: "black" | "brown";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
op foo(): Dog;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Models
|
|
22
|
-
|
|
23
|
-
Should generate an interface for the Dog that contains all properties from Pet
|
|
24
|
-
|
|
25
|
-
```ts src/models/models.ts interface Dog
|
|
26
|
-
export interface Dog {
|
|
27
|
-
id: string;
|
|
28
|
-
name: string;
|
|
29
|
-
color: "black" | "brown";
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Serializers
|
|
34
|
-
|
|
35
|
-
### Dog Serializer
|
|
36
|
-
|
|
37
|
-
```ts src/models/internal/serializers.ts function jsonDogToTransportTransform
|
|
38
|
-
export function jsonDogToTransportTransform(input_?: Dog | null): any {
|
|
39
|
-
if (!input_) {
|
|
40
|
-
return input_ as any;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
id: input_.id,
|
|
44
|
-
name: input_.name,
|
|
45
|
-
color: input_.color,
|
|
46
|
-
}!;
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Dog deserializer
|
|
51
|
-
|
|
52
|
-
```ts src/models/internal/serializers.ts function jsonDogToApplicationTransform
|
|
53
|
-
export function jsonDogToApplicationTransform(input_?: any): Dog {
|
|
54
|
-
if (!input_) {
|
|
55
|
-
return input_ as any;
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
id: input_.id,
|
|
59
|
-
name: input_.name,
|
|
60
|
-
color: input_.color,
|
|
61
|
-
}!;
|
|
62
|
-
}
|
|
63
|
-
```
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Should handle a model that has a property of type ModelProperty
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
@service
|
|
5
|
-
namespace Test;
|
|
6
|
-
model Request {
|
|
7
|
-
id: string;
|
|
8
|
-
profileImage: bytes;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@post
|
|
12
|
-
@route("/foo")
|
|
13
|
-
op foo(profileImage: Request.profileImage): NoContentResponse;
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Operation
|
|
17
|
-
|
|
18
|
-
```ts src/api/testClientOperations.ts function foo
|
|
19
|
-
export async function foo(
|
|
20
|
-
client: TestClientContext,
|
|
21
|
-
profileImage: Uint8Array,
|
|
22
|
-
options?: FooOptions,
|
|
23
|
-
): Promise<void> {
|
|
24
|
-
const path = parse("/foo").expand({});
|
|
25
|
-
const httpRequestOptions = {
|
|
26
|
-
headers: {},
|
|
27
|
-
body: {
|
|
28
|
-
profileImage: encodeUint8Array(profileImage, "base64")!,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
32
|
-
|
|
33
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
34
|
-
options?.operationOptions?.onResponse(response);
|
|
35
|
-
}
|
|
36
|
-
if (+response.status === 204 && !response.body) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
throw createRestError(response);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Should emit a model property which type is a reference to another Model Property
|
|
2
|
-
|
|
3
|
-
This way of referencing a model property ends up with a ModelProperty which type is a ModelProperty. This test makes sure we can handle that.
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
namespace Test;
|
|
7
|
-
|
|
8
|
-
model Foo {
|
|
9
|
-
name: string;
|
|
10
|
-
id: int32;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
model Bar {
|
|
14
|
-
address: string;
|
|
15
|
-
parentId: Foo.id;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
op get(...Bar): Bar;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Model
|
|
22
|
-
|
|
23
|
-
```ts src/models/models.ts interface Bar
|
|
24
|
-
export interface Bar {
|
|
25
|
-
address: string;
|
|
26
|
-
parentId: number;
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Transforms
|
|
31
|
-
|
|
32
|
-
### To Transport
|
|
33
|
-
|
|
34
|
-
Should emit a serializer for this model
|
|
35
|
-
|
|
36
|
-
```ts src/models/internal/serializers.ts function jsonBarToTransportTransform
|
|
37
|
-
export function jsonBarToTransportTransform(input_?: Bar | null): any {
|
|
38
|
-
if (!input_) {
|
|
39
|
-
return input_ as any;
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
address: input_.address,
|
|
43
|
-
parentId: input_.parentId,
|
|
44
|
-
}!;
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Should emit an operation serializer
|
|
49
|
-
|
|
50
|
-
```ts src/models/internal/serializers.ts
|
|
51
|
-
import type { Bar } from "../models.js";
|
|
52
|
-
|
|
53
|
-
export function decodeBase64(value: string): Uint8Array | undefined {
|
|
54
|
-
if (!value) {
|
|
55
|
-
return value as any;
|
|
56
|
-
}
|
|
57
|
-
// Normalize Base64URL to Base64
|
|
58
|
-
const base64 = value
|
|
59
|
-
.replace(/-/g, "+")
|
|
60
|
-
.replace(/_/g, "/")
|
|
61
|
-
.padEnd(value.length + ((4 - (value.length % 4)) % 4), "=");
|
|
62
|
-
|
|
63
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
64
|
-
}
|
|
65
|
-
export function encodeUint8Array(
|
|
66
|
-
value: Uint8Array | undefined | null,
|
|
67
|
-
encoding: BufferEncoding,
|
|
68
|
-
): string | undefined {
|
|
69
|
-
if (!value) {
|
|
70
|
-
return value as any;
|
|
71
|
-
}
|
|
72
|
-
return Buffer.from(value).toString(encoding);
|
|
73
|
-
}
|
|
74
|
-
export function dateDeserializer(date?: string | null): Date {
|
|
75
|
-
if (!date) {
|
|
76
|
-
return date as any;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return new Date(date);
|
|
80
|
-
}
|
|
81
|
-
export function dateRfc7231Deserializer(date?: string | null): Date {
|
|
82
|
-
if (!date) {
|
|
83
|
-
return date as any;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return new Date(date);
|
|
87
|
-
}
|
|
88
|
-
export function dateRfc3339Serializer(date?: Date | null): string {
|
|
89
|
-
if (!date) {
|
|
90
|
-
return date as any;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return date.toISOString();
|
|
94
|
-
}
|
|
95
|
-
export function dateRfc7231Serializer(date?: Date | null): string {
|
|
96
|
-
if (!date) {
|
|
97
|
-
return date as any;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return date.toUTCString();
|
|
101
|
-
}
|
|
102
|
-
export function dateUnixTimestampSerializer(date?: Date | null): number {
|
|
103
|
-
if (!date) {
|
|
104
|
-
return date as any;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return Math.floor(date.getTime() / 1000);
|
|
108
|
-
}
|
|
109
|
-
export function dateUnixTimestampDeserializer(date?: number | null): Date {
|
|
110
|
-
if (!date) {
|
|
111
|
-
return date as any;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return new Date(date * 1000);
|
|
115
|
-
}
|
|
116
|
-
export function jsonBarToTransportTransform(input_?: Bar | null): any {
|
|
117
|
-
if (!input_) {
|
|
118
|
-
return input_ as any;
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
address: input_.address,
|
|
122
|
-
parentId: input_.parentId,
|
|
123
|
-
}!;
|
|
124
|
-
}
|
|
125
|
-
export function jsonBarToApplicationTransform(input_?: any): Bar {
|
|
126
|
-
if (!input_) {
|
|
127
|
-
return input_ as any;
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
address: input_.address,
|
|
131
|
-
parentId: input_.parentId,
|
|
132
|
-
}!;
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### To Application
|
|
137
|
-
|
|
138
|
-
Should emit a serializer for this model
|
|
139
|
-
|
|
140
|
-
```ts src/models/internal/serializers.ts function jsonBarToApplicationTransform
|
|
141
|
-
export function jsonBarToApplicationTransform(input_?: any): Bar {
|
|
142
|
-
if (!input_) {
|
|
143
|
-
return input_ as any;
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
address: input_.address,
|
|
147
|
-
parentId: input_.parentId,
|
|
148
|
-
}!;
|
|
149
|
-
}
|
|
150
|
-
```
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Should handle an http part with anonymous model
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
@service
|
|
5
|
-
namespace Test;
|
|
6
|
-
|
|
7
|
-
op foo(
|
|
8
|
-
@header contentType: "multipart/form-data",
|
|
9
|
-
@multipartBody body: {
|
|
10
|
-
temperature: HttpPart<{
|
|
11
|
-
@body body: float64;
|
|
12
|
-
@header contentType: "text/plain";
|
|
13
|
-
}>;
|
|
14
|
-
},
|
|
15
|
-
): NoContentResponse;
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Operation
|
|
19
|
-
|
|
20
|
-
```ts src/api/testClientOperations.ts function foo
|
|
21
|
-
export async function foo(
|
|
22
|
-
client: TestClientContext,
|
|
23
|
-
body: {
|
|
24
|
-
temperature: {
|
|
25
|
-
body: number;
|
|
26
|
-
contentType: "text/plain";
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
options?: FooOptions,
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
const path = parse("/").expand({});
|
|
32
|
-
const httpRequestOptions = {
|
|
33
|
-
headers: {
|
|
34
|
-
"content-type": options?.contentType ?? "multipart/form-data",
|
|
35
|
-
},
|
|
36
|
-
body: [
|
|
37
|
-
{
|
|
38
|
-
name: "temperature",
|
|
39
|
-
body: body.temperature.body,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
const response = await client.pathUnchecked(path).post(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,154 +0,0 @@
|
|
|
1
|
-
# Basic file part
|
|
2
|
-
|
|
3
|
-
```tsp
|
|
4
|
-
namespace Test;
|
|
5
|
-
|
|
6
|
-
model RequestBody {
|
|
7
|
-
basicFile: HttpPart<File>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
op doThing(@header contentType: "multipart/form-data", @multipartBody bodyParam: RequestBody): void;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Models
|
|
14
|
-
|
|
15
|
-
This basic case uses TypeSpec's `Http.File`, which specifies an optional `filename` and `contentType`.
|
|
16
|
-
|
|
17
|
-
```ts src/models/models.ts interface RequestBody
|
|
18
|
-
export interface RequestBody {
|
|
19
|
-
basicFile: File;
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Operations
|
|
24
|
-
|
|
25
|
-
```ts src/api/testClientOperations.ts function doThing
|
|
26
|
-
export async function doThing(
|
|
27
|
-
client: TestClientContext,
|
|
28
|
-
bodyParam: RequestBody,
|
|
29
|
-
options?: DoThingOptions,
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
const path = parse("/").expand({});
|
|
32
|
-
const httpRequestOptions = {
|
|
33
|
-
headers: {
|
|
34
|
-
"content-type": options?.contentType ?? "multipart/form-data",
|
|
35
|
-
},
|
|
36
|
-
body: [createFilePartDescriptor("basicFile", bodyParam.basicFile)],
|
|
37
|
-
};
|
|
38
|
-
const response = await client.pathUnchecked(path).post(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
|
-
```
|
|
49
|
-
|
|
50
|
-
# With part content type
|
|
51
|
-
|
|
52
|
-
```tsp
|
|
53
|
-
namespace Test;
|
|
54
|
-
|
|
55
|
-
model PngFile extends File {
|
|
56
|
-
contentType: "image/png";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
model RequestBody {
|
|
60
|
-
image: HttpPart<PngFile>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
op doThing(@header contentType: "multipart/form-data", @multipartBody bodyParam: RequestBody): void;
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Models
|
|
67
|
-
|
|
68
|
-
```ts src/models/models.ts interface PngFile
|
|
69
|
-
export interface PngFile extends File {
|
|
70
|
-
contentType: "image/png";
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
```ts src/models/models.ts interface RequestBody
|
|
75
|
-
export interface RequestBody {
|
|
76
|
-
image: PngFile;
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Operation
|
|
81
|
-
|
|
82
|
-
```ts src/api/testClientOperations.ts function doThing
|
|
83
|
-
export async function doThing(
|
|
84
|
-
client: TestClientContext,
|
|
85
|
-
bodyParam: RequestBody,
|
|
86
|
-
options?: DoThingOptions,
|
|
87
|
-
): Promise<void> {
|
|
88
|
-
const path = parse("/").expand({});
|
|
89
|
-
const httpRequestOptions = {
|
|
90
|
-
headers: {
|
|
91
|
-
"content-type": options?.contentType ?? "multipart/form-data",
|
|
92
|
-
},
|
|
93
|
-
body: [createFilePartDescriptor("image", bodyParam.image, "image/png")],
|
|
94
|
-
};
|
|
95
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
96
|
-
|
|
97
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
98
|
-
options?.operationOptions?.onResponse(response);
|
|
99
|
-
}
|
|
100
|
-
if (+response.status === 204 && !response.body) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
throw createRestError(response);
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
# Multiple files
|
|
108
|
-
|
|
109
|
-
```tsp
|
|
110
|
-
namespace Test;
|
|
111
|
-
|
|
112
|
-
model RequestBody {
|
|
113
|
-
files: HttpPart<File>[];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
op doThing(@header contentType: "multipart/form-data", @multipartBody bodyParam: RequestBody): void;
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Models
|
|
120
|
-
|
|
121
|
-
Each provided file in the input corresponds to one part in the multipart request.
|
|
122
|
-
|
|
123
|
-
```ts src/models/models.ts interface RequestBody
|
|
124
|
-
export interface RequestBody {
|
|
125
|
-
files: Array<File>;
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Operation
|
|
130
|
-
|
|
131
|
-
```ts src/api/testClientOperations.ts function doThing
|
|
132
|
-
export async function doThing(
|
|
133
|
-
client: TestClientContext,
|
|
134
|
-
bodyParam: RequestBody,
|
|
135
|
-
options?: DoThingOptions,
|
|
136
|
-
): Promise<void> {
|
|
137
|
-
const path = parse("/").expand({});
|
|
138
|
-
const httpRequestOptions = {
|
|
139
|
-
headers: {
|
|
140
|
-
"content-type": options?.contentType ?? "multipart/form-data",
|
|
141
|
-
},
|
|
142
|
-
body: [...bodyParam.files.map((files: any) => createFilePartDescriptor("files", files))],
|
|
143
|
-
};
|
|
144
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
145
|
-
|
|
146
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
147
|
-
options?.operationOptions?.onResponse(response);
|
|
148
|
-
}
|
|
149
|
-
if (+response.status === 204 && !response.body) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
throw createRestError(response);
|
|
153
|
-
}
|
|
154
|
-
```
|