@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,97 +0,0 @@
|
|
|
1
|
-
# Should emit serializer and deserializer correctly for properties with primitive Record type
|
|
2
|
-
|
|
3
|
-
## Typespec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
model Foo {
|
|
7
|
-
my_values: Record<int32>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
op foo(): Foo;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## TypeScript
|
|
14
|
-
|
|
15
|
-
Should generate a model `Foo` and also a `jsonFooToTransportTransform` and `jsonFooToApplicationTransform` functions that call the `recordSerializer` internally.
|
|
16
|
-
|
|
17
|
-
```ts src/models/models.ts interface Foo
|
|
18
|
-
export interface Foo {
|
|
19
|
-
myValues: Record<string, number>;
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
24
|
-
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
25
|
-
if (!input_) {
|
|
26
|
-
return input_ as any;
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
my_values: jsonRecordInt32ToTransportTransform(input_.myValues),
|
|
30
|
-
}!;
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
35
|
-
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
36
|
-
if (!input_) {
|
|
37
|
-
return input_ as any;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
myValues: jsonRecordInt32ToApplicationTransform(input_.my_values),
|
|
41
|
-
}!;
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
# Should emit serializer and deserializer correctly for properties with complex array type
|
|
46
|
-
|
|
47
|
-
## Typespec
|
|
48
|
-
|
|
49
|
-
```tsp
|
|
50
|
-
model Bar {
|
|
51
|
-
bar_value: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
model Foo {
|
|
55
|
-
my_values: Record<Bar>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
op foo(): Foo | Bar;
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## TypeScript
|
|
62
|
-
|
|
63
|
-
Should generate models `Foo` and `Bar` and also a `jsonFooToTransportTransform`, `jsonFooToApplicationTransform`, `barToTransport` and `barToApplication` functions that call the `recordSerializer` passing `barToTransport` or `barDeserialize` as the serialization callback.
|
|
64
|
-
|
|
65
|
-
```ts src/models/models.ts interface Foo
|
|
66
|
-
export interface Foo {
|
|
67
|
-
myValues: Record<string, Bar>;
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```ts src/models/models.ts interface Bar
|
|
72
|
-
export interface Bar {
|
|
73
|
-
barValue: string;
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
78
|
-
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
79
|
-
if (!input_) {
|
|
80
|
-
return input_ as any;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
my_values: jsonRecordBarToTransportTransform(input_.myValues),
|
|
84
|
-
}!;
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
89
|
-
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
90
|
-
if (!input_) {
|
|
91
|
-
return input_ as any;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
myValues: jsonRecordBarToApplicationTransform(input_.my_values),
|
|
95
|
-
}!;
|
|
96
|
-
}
|
|
97
|
-
```
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# Should generate a serializer for a declared utcDateTime scalar
|
|
2
|
-
|
|
3
|
-
Should generate a Type Alias for each of the utcDateTime taking into account the encoding. All should generate
|
|
4
|
-
|
|
5
|
-
## TypeSpec
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
scalar MyDate extends utcDateTime;
|
|
9
|
-
@encode("rfc3339")
|
|
10
|
-
scalar MyUtcDate extends utcDateTime;
|
|
11
|
-
@encode("rfc7231")
|
|
12
|
-
scalar MyIsoDate extends utcDateTime;
|
|
13
|
-
@encode("unixTimestamp", int32)
|
|
14
|
-
scalar MyUnixDate extends utcDateTime;
|
|
15
|
-
|
|
16
|
-
op foo(a: MyDate, b: MyUtcDate, c: MyIsoDate, d: MyUnixDate): void;
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## TypeScript
|
|
20
|
-
|
|
21
|
-
```ts src/models/models.ts
|
|
22
|
-
/**
|
|
23
|
-
* A sequence of textual characters.
|
|
24
|
-
*/
|
|
25
|
-
export type String = string;
|
|
26
|
-
export type MyDate = Date;
|
|
27
|
-
/**
|
|
28
|
-
* An instant in coordinated universal time (UTC)"
|
|
29
|
-
*/
|
|
30
|
-
export type UtcDateTime = Date;
|
|
31
|
-
export type MyUtcDate = Date;
|
|
32
|
-
export type MyIsoDate = Date;
|
|
33
|
-
export type MyUnixDate = Date;
|
|
34
|
-
```
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Should handle spread with multiple parameters
|
|
2
|
-
|
|
3
|
-
## Typespec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service(#{ title: "Test Service" })
|
|
7
|
-
namespace Test;
|
|
8
|
-
alias MultipleRequestParameters = {
|
|
9
|
-
@path
|
|
10
|
-
id: string;
|
|
11
|
-
|
|
12
|
-
@header
|
|
13
|
-
`x-ms-test-header`: string;
|
|
14
|
-
|
|
15
|
-
/** required string */
|
|
16
|
-
requiredString: string;
|
|
17
|
-
|
|
18
|
-
/** optional int */
|
|
19
|
-
optionalInt?: int32;
|
|
20
|
-
|
|
21
|
-
/** required int */
|
|
22
|
-
requiredIntList: int32[];
|
|
23
|
-
|
|
24
|
-
/** optional string */
|
|
25
|
-
optionalStringList?: string[];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
@put
|
|
29
|
-
op spreadWithMultipleParameters(...MultipleRequestParameters): NoContentResponse;
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Typescript
|
|
33
|
-
|
|
34
|
-
When spreading a model an anonymous model created in the type graph, the emitted operation should have the serializer expression inline. No serializer function for this operation is expected in src/models/internal/serializers.ts
|
|
35
|
-
|
|
36
|
-
```ts src/api/testClientOperations.ts function spreadWithMultipleParameters
|
|
37
|
-
export async function spreadWithMultipleParameters(
|
|
38
|
-
client: TestClientContext,
|
|
39
|
-
id: string,
|
|
40
|
-
xMsTestHeader: string,
|
|
41
|
-
requiredString: string,
|
|
42
|
-
requiredIntList: Array<number>,
|
|
43
|
-
options?: SpreadWithMultipleParametersOptions,
|
|
44
|
-
): Promise<void> {
|
|
45
|
-
const path = parse("/{id}").expand({
|
|
46
|
-
id: id,
|
|
47
|
-
});
|
|
48
|
-
const httpRequestOptions = {
|
|
49
|
-
headers: {
|
|
50
|
-
"x-ms-test-header": xMsTestHeader,
|
|
51
|
-
},
|
|
52
|
-
body: {
|
|
53
|
-
requiredString: requiredString,
|
|
54
|
-
optionalInt: options?.optionalInt,
|
|
55
|
-
requiredIntList: jsonArrayInt32ToTransportTransform(requiredIntList),
|
|
56
|
-
optionalStringList: jsonArrayStringToTransportTransform(options?.optionalStringList),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const response = await client.pathUnchecked(path).put(httpRequestOptions);
|
|
60
|
-
|
|
61
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
62
|
-
options?.operationOptions?.onResponse(response);
|
|
63
|
-
}
|
|
64
|
-
if (+response.status === 204 && !response.body) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
throw createRestError(response);
|
|
68
|
-
}
|
|
69
|
-
```
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Should handle operations with string union input
|
|
2
|
-
|
|
3
|
-
## Typespec
|
|
4
|
-
|
|
5
|
-
```tsp
|
|
6
|
-
@service(#{ title: "Test Service" })
|
|
7
|
-
namespace Test;
|
|
8
|
-
union ServerExtensibleEnum {
|
|
9
|
-
string,
|
|
10
|
-
EnumValue1: "value1",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@post
|
|
14
|
-
op unionEnumName(@body body: ServerExtensibleEnum): NoContentResponse;
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Typescript
|
|
18
|
-
|
|
19
|
-
```ts src/models/models.ts type ServerExtensibleEnum
|
|
20
|
-
export type ServerExtensibleEnum = string | "value1";
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```ts src/api/testClientOperations.ts function unionEnumName
|
|
24
|
-
export async function unionEnumName(
|
|
25
|
-
client: TestClientContext,
|
|
26
|
-
body: ServerExtensibleEnum,
|
|
27
|
-
options?: UnionEnumNameOptions,
|
|
28
|
-
): Promise<void> {
|
|
29
|
-
const path = parse("/").expand({});
|
|
30
|
-
const httpRequestOptions = {
|
|
31
|
-
headers: {},
|
|
32
|
-
body: jsonServerExtensibleEnumToTransportTransform(body),
|
|
33
|
-
};
|
|
34
|
-
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
35
|
-
|
|
36
|
-
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
37
|
-
options?.operationOptions?.onResponse(response);
|
|
38
|
-
}
|
|
39
|
-
if (+response.status === 204 && !response.body) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
throw createRestError(response);
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
```ts src/models/internal/serializers.ts function jsonServerExtensibleEnumToTransportTransform
|
|
47
|
-
export function jsonServerExtensibleEnumToTransportTransform(
|
|
48
|
-
input_?: ServerExtensibleEnum | null,
|
|
49
|
-
): any {
|
|
50
|
-
if (!input_) {
|
|
51
|
-
return input_ as any;
|
|
52
|
-
}
|
|
53
|
-
return input_;
|
|
54
|
-
}
|
|
55
|
-
```
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# Should create a constructor with a default endpoint and an optional endpoint parameter.
|
|
2
|
-
|
|
3
|
-
## Spec
|
|
4
|
-
|
|
5
|
-
This spec defines a service with a server that has a default endpoint
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service
|
|
9
|
-
@server("https://example.org/api")
|
|
10
|
-
namespace Test;
|
|
11
|
-
|
|
12
|
-
op foo(): void;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Client
|
|
16
|
-
|
|
17
|
-
The client uses the optional endpoint if available or the default endpoint
|
|
18
|
-
|
|
19
|
-
```ts src/api/testClientContext.ts function createTestClientContext
|
|
20
|
-
export function createTestClientContext(options?: TestClientOptions): TestClientContext {
|
|
21
|
-
const params: Record<string, any> = {
|
|
22
|
-
endpoint: options?.endpoint ?? "https://example.org/api",
|
|
23
|
-
};
|
|
24
|
-
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
25
|
-
key in params
|
|
26
|
-
? String(params[key])
|
|
27
|
-
: (() => {
|
|
28
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
29
|
-
})(),
|
|
30
|
-
);
|
|
31
|
-
return getClient(resolvedEndpoint, {
|
|
32
|
-
...options,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Client options
|
|
38
|
-
|
|
39
|
-
Since there is a default url, the endpoint parameter is not required, but optional in case customers want to point to another url.
|
|
40
|
-
|
|
41
|
-
```ts src/api/testClientContext.ts interface TestClientOptions
|
|
42
|
-
export interface TestClientOptions extends ClientOptions {
|
|
43
|
-
endpoint?: string;
|
|
44
|
-
}
|
|
45
|
-
```
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Should build the server url based on the parametrized host
|
|
2
|
-
|
|
3
|
-
## Spec
|
|
4
|
-
|
|
5
|
-
This spec defines a server that has a host template and and endpoint to fill it out.
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service(#{ title: "Parametrized Endpoint" })
|
|
9
|
-
@server(
|
|
10
|
-
"{endpoint}/server/path/multiple/{apiVersion}",
|
|
11
|
-
"Test server with path parameters.",
|
|
12
|
-
{
|
|
13
|
-
endpoint: url,
|
|
14
|
-
apiVersion: string,
|
|
15
|
-
}
|
|
16
|
-
)
|
|
17
|
-
namespace Test;
|
|
18
|
-
|
|
19
|
-
op noOperationParams(): NoContentResponse;
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Client Context
|
|
23
|
-
|
|
24
|
-
The client context should use the parameters to build the baseUrl using the template.
|
|
25
|
-
|
|
26
|
-
```ts src/api/testClientContext.ts
|
|
27
|
-
import { type Client, type ClientOptions, getClient } from "@typespec/ts-http-runtime";
|
|
28
|
-
|
|
29
|
-
export interface TestClientContext extends Client {}
|
|
30
|
-
export interface TestClientOptions extends ClientOptions {
|
|
31
|
-
endpoint?: string;
|
|
32
|
-
}
|
|
33
|
-
export function createTestClientContext(
|
|
34
|
-
endpoint: string,
|
|
35
|
-
apiVersion: string,
|
|
36
|
-
options?: TestClientOptions,
|
|
37
|
-
): TestClientContext {
|
|
38
|
-
const params: Record<string, any> = {
|
|
39
|
-
endpoint: endpoint,
|
|
40
|
-
apiVersion: apiVersion,
|
|
41
|
-
};
|
|
42
|
-
const resolvedEndpoint = "{endpoint}/server/path/multiple/{apiVersion}".replace(
|
|
43
|
-
/{([^}]+)}/g,
|
|
44
|
-
(_, key) =>
|
|
45
|
-
key in params
|
|
46
|
-
? String(params[key])
|
|
47
|
-
: (() => {
|
|
48
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
49
|
-
})(),
|
|
50
|
-
);
|
|
51
|
-
return getClient(resolvedEndpoint, {
|
|
52
|
-
...options,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
```
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Should create a constructor with a default endpoint and an optional endpoint parameter.
|
|
2
|
-
|
|
3
|
-
## Spec
|
|
4
|
-
|
|
5
|
-
This spec defines a service with a server that has a default endpoint
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service
|
|
9
|
-
namespace Test;
|
|
10
|
-
|
|
11
|
-
op foo(): void;
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Client
|
|
15
|
-
|
|
16
|
-
The client has a required positional parameter for endpoint.
|
|
17
|
-
|
|
18
|
-
```ts src/api/testClientContext.ts function createTestClientContext
|
|
19
|
-
export function createTestClientContext(
|
|
20
|
-
endpoint: string,
|
|
21
|
-
options?: TestClientOptions,
|
|
22
|
-
): TestClientContext {
|
|
23
|
-
const params: Record<string, any> = {
|
|
24
|
-
endpoint: endpoint,
|
|
25
|
-
};
|
|
26
|
-
const resolvedEndpoint = "{endpoint}".replace(/{([^}]+)}/g, (_, key) =>
|
|
27
|
-
key in params
|
|
28
|
-
? String(params[key])
|
|
29
|
-
: (() => {
|
|
30
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
31
|
-
})(),
|
|
32
|
-
);
|
|
33
|
-
return getClient(resolvedEndpoint, {
|
|
34
|
-
...options,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
```
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Should build the server url based on the parametrized host
|
|
2
|
-
|
|
3
|
-
## Spec
|
|
4
|
-
|
|
5
|
-
This spec defines a server that has a host template and and endpoint to fill it out.
|
|
6
|
-
|
|
7
|
-
```tsp
|
|
8
|
-
@service(#{ title: "Parametrized Endpoint" })
|
|
9
|
-
@server(
|
|
10
|
-
"{foo}/server/path/multiple",
|
|
11
|
-
"Test server with path parameters.",
|
|
12
|
-
{
|
|
13
|
-
@doc("Pass in http://localhost:3000 for endpoint.")
|
|
14
|
-
foo: url,
|
|
15
|
-
}
|
|
16
|
-
)
|
|
17
|
-
namespace Test;
|
|
18
|
-
|
|
19
|
-
op noOperationParams(): NoContentResponse;
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Client Context
|
|
23
|
-
|
|
24
|
-
The client context should use the parameters to build the baseUrl using the template.
|
|
25
|
-
|
|
26
|
-
```ts src/api/testClientContext.ts
|
|
27
|
-
import { type Client, type ClientOptions, getClient } from "@typespec/ts-http-runtime";
|
|
28
|
-
|
|
29
|
-
export interface TestClientContext extends Client {}
|
|
30
|
-
export interface TestClientOptions extends ClientOptions {
|
|
31
|
-
endpoint?: string;
|
|
32
|
-
}
|
|
33
|
-
export function createTestClientContext(
|
|
34
|
-
foo: string,
|
|
35
|
-
options?: TestClientOptions,
|
|
36
|
-
): TestClientContext {
|
|
37
|
-
const params: Record<string, any> = {
|
|
38
|
-
foo: foo,
|
|
39
|
-
};
|
|
40
|
-
const resolvedEndpoint = "{foo}/server/path/multiple".replace(/{([^}]+)}/g, (_, key) =>
|
|
41
|
-
key in params
|
|
42
|
-
? String(params[key])
|
|
43
|
-
: (() => {
|
|
44
|
-
throw new Error(`Missing parameter: ${key}`);
|
|
45
|
-
})(),
|
|
46
|
-
);
|
|
47
|
-
return getClient(resolvedEndpoint, {
|
|
48
|
-
...options,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
```
|
package/test/scenarios.test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createSnippetExtractor,
|
|
3
|
-
createTypeScriptExtractorConfig,
|
|
4
|
-
executeScenarios,
|
|
5
|
-
} from "@typespec/emitter-framework/testing";
|
|
6
|
-
import { dirname, join } from "path";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
import { Tester } from "./test-host.js";
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = dirname(__filename);
|
|
12
|
-
|
|
13
|
-
const tsExtractorConfig = await createTypeScriptExtractorConfig();
|
|
14
|
-
const snipperExtractor = createSnippetExtractor(tsExtractorConfig);
|
|
15
|
-
|
|
16
|
-
// Construct the test path relative to this file.
|
|
17
|
-
const scenarioPath = join(__dirname, "scenarios");
|
|
18
|
-
|
|
19
|
-
await executeScenarios(
|
|
20
|
-
Tester.import("@typespec/http", "@typespec/rest").using("Http", "Rest"),
|
|
21
|
-
tsExtractorConfig,
|
|
22
|
-
scenarioPath,
|
|
23
|
-
snipperExtractor,
|
|
24
|
-
);
|
package/test/test-host.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import { resolvePath } from "@typespec/compiler";
|
|
3
|
-
import { createTester, expectDiagnosticEmpty } from "@typespec/compiler/testing";
|
|
4
|
-
|
|
5
|
-
const ApiTester = createTester(resolvePath(import.meta.dirname, ".."), {
|
|
6
|
-
libraries: ["@typespec/http", "@typespec/rest", "@typespec/http-client-js"],
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export const Tester = ApiTester.emit("@typespec/http-client-js");
|
|
10
|
-
|
|
11
|
-
export async function emitWithDiagnostics(
|
|
12
|
-
code: string,
|
|
13
|
-
): Promise<[Record<string, string>, readonly Diagnostic[]]> {
|
|
14
|
-
const [result, diagnostics] = await Tester.compileAndDiagnose(code);
|
|
15
|
-
return [result.outputs, diagnostics];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function emit(code: string): Promise<Record<string, string>> {
|
|
19
|
-
const [result, diagnostics] = await emitWithDiagnostics(code);
|
|
20
|
-
expectDiagnosticEmpty(diagnostics);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"target": "es2022",
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"isolatedModules": true,
|
|
9
|
-
"jsx": "preserve",
|
|
10
|
-
"jsxImportSource": "@alloy-js/core",
|
|
11
|
-
"emitDeclarationOnly": true,
|
|
12
|
-
"outDir": "dist"
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
15
|
-
"exclude": ["node_modules", "dist", "test/e2e/generated/**/*.ts"]
|
|
16
|
-
}
|
package/tsconfig.test.json
DELETED
package/vitest.config.e2e.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
environment: "node",
|
|
6
|
-
isolate: false,
|
|
7
|
-
coverage: {
|
|
8
|
-
reporter: ["cobertura", "json", "text"],
|
|
9
|
-
},
|
|
10
|
-
outputFile: {
|
|
11
|
-
junit: "./test-results.xml",
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
include: ["test/e2e/**/*.test.ts"],
|
|
15
|
-
},
|
|
16
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import alloyPlugin from "@alloy-js/rollup-plugin";
|
|
2
|
-
import { defineConfig, mergeConfig } from "vitest/config";
|
|
3
|
-
import { defaultTypeSpecVitestConfig } from "../../vitest.config.js";
|
|
4
|
-
|
|
5
|
-
export default mergeConfig(
|
|
6
|
-
defaultTypeSpecVitestConfig,
|
|
7
|
-
defineConfig({
|
|
8
|
-
test: {
|
|
9
|
-
include: ["test/**/*.test.ts"],
|
|
10
|
-
exclude: ["test/e2e/**/*"],
|
|
11
|
-
passWithNoTests: true,
|
|
12
|
-
},
|
|
13
|
-
plugins: [alloyPlugin()],
|
|
14
|
-
}),
|
|
15
|
-
);
|