@typespec/http-client-js 0.3.0-dev.0 → 0.3.0-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/CHANGELOG.md +0 -3
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +6 -6
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +6 -1
- package/dist/src/emitter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/run-e2e-tests.js +1 -1
- package/package.json +16 -14
- package/src/components/client.tsx +7 -8
- package/src/emitter.tsx +3 -1
- package/test/e2e/http/encode/bytes/main.test.ts +1 -1
- package/test/e2e/http/type/model/visibility/main.test.ts +2 -2
- package/test/scenarios/additional-properties/extends.md +2 -2
- package/test/scenarios/additional-properties/spread.md +2 -2
- package/test/scenarios/auth/basic_auth.md +1 -0
- package/test/scenarios/auth/bearer.md +1 -0
- package/test/scenarios/auth/client_parameters.md +1 -0
- package/test/scenarios/auth/key_credential.md +1 -0
- package/test/scenarios/auth/sub_client_override.md +2 -0
- package/test/scenarios/client/dotted_namespace.md +1 -0
- package/test/scenarios/client/global_namespace.md +1 -0
- package/test/scenarios/client/multiple_top_level_clients.md +2 -0
- package/test/scenarios/client/nested_client.md +1 -0
- package/test/scenarios/encoding/bytes_json_property.md +1 -1
- package/test/scenarios/encoding/bytes_nullable.md +2 -2
- package/test/scenarios/encoding/model_with_bytes_property.md +1 -1
- package/test/scenarios/http-operations/basic-response.md +1 -1
- package/test/scenarios/http-operations/basic.md +2 -1
- package/test/scenarios/http-operations/optional-request-body.md +1 -1
- package/test/scenarios/http-operations/query-parameter.md +41 -0
- package/test/scenarios/http-operations/scalar-payload.md +1 -1
- package/test/scenarios/http-operations/with-parameters.md +1 -0
- package/test/scenarios/models/inheritance_2_discriminators.md +2 -2
- package/test/scenarios/models/inheritance_discriminator.md +4 -4
- package/test/scenarios/models/model_additional_properties.md +2 -2
- package/test/scenarios/models/model_extends.md +4 -4
- package/test/scenarios/models/model_spread.md +2 -2
- package/test/scenarios/models/property_references_property.md +4 -4
- package/test/scenarios/multipart/file_content_type.md +2 -2
- package/test/scenarios/operation-parameters/body_root_anonymous.md +1 -0
- package/test/scenarios/operation-parameters/constant_as_optional.md +1 -0
- package/test/scenarios/operation-parameters/default_value_as_optional.md +1 -0
- package/test/scenarios/operation-parameters/no_content_type.md +1 -0
- package/test/scenarios/operation-parameters/no_parameters.md +1 -0
- package/test/scenarios/operation-parameters/only_optional.md +1 -0
- package/test/scenarios/operation-parameters/only_required.md +1 -0
- package/test/scenarios/operation-parameters/reserved_names.md +1 -0
- package/test/scenarios/operation-parameters/spread_body.md +1 -0
- package/test/scenarios/operation-parameters/spread_with_nested.md +1 -0
- package/test/scenarios/operation-parameters/union_body.md +2 -1
- package/test/scenarios/operation-parameters/with_body_property.md +1 -0
- package/test/scenarios/operation-parameters/with_body_root.md +1 -0
- package/test/scenarios/serializers/arrays.md +6 -6
- package/test/scenarios/serializers/basic_model.md +4 -4
- package/test/scenarios/serializers/basic_model_wire_name.md +3 -3
- package/test/scenarios/serializers/discriminated_union.md +4 -4
- package/test/scenarios/serializers/discriminated_union_spread.md +5 -5
- package/test/scenarios/serializers/model_date_time.md +5 -5
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +6 -6
- package/test/scenarios/serializers/property_references_property.md +2 -2
- package/test/scenarios/serializers/record.md +4 -4
- package/test/scenarios/serializers/spread.md +1 -1
- package/test/scenarios/serializers/string_union.md +1 -1
- package/test/scenarios.test.ts +11 -3
- package/vitest.config.e2e.ts +16 -0
- package/vitest.config.ts +26 -0
- package/vitest.config.js +0 -23
|
@@ -52,6 +52,7 @@ export interface GetOptions extends OperationOptions {}
|
|
|
52
52
|
```ts src/testClient.ts class TestClient
|
|
53
53
|
export class TestClient {
|
|
54
54
|
#context: TestClientContext;
|
|
55
|
+
|
|
55
56
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
56
57
|
this.#context = createTestClientContext(endpoint, options);
|
|
57
58
|
}
|
|
@@ -40,6 +40,7 @@ export interface GetOptions extends OperationOptions {}
|
|
|
40
40
|
```ts src/testClient.ts class TestClient
|
|
41
41
|
export class TestClient {
|
|
42
42
|
#context: TestClientContext;
|
|
43
|
+
|
|
43
44
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
44
45
|
this.#context = createTestClientContext(endpoint, options);
|
|
45
46
|
}
|
|
@@ -52,6 +52,7 @@ export interface GetWithParamsOptions extends OperationOptions {
|
|
|
52
52
|
```ts src/testClient.ts class TestClient
|
|
53
53
|
export class TestClient {
|
|
54
54
|
#context: TestClientContext;
|
|
55
|
+
|
|
55
56
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
56
57
|
this.#context = createTestClientContext(endpoint, options);
|
|
57
58
|
}
|
|
@@ -48,6 +48,7 @@ export interface GetWithParamsOptions extends OperationOptions {}
|
|
|
48
48
|
```ts src/testClient.ts class TestClient
|
|
49
49
|
export class TestClient {
|
|
50
50
|
#context: TestClientContext;
|
|
51
|
+
|
|
51
52
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
52
53
|
this.#context = createTestClientContext(endpoint, options);
|
|
53
54
|
}
|
|
@@ -50,6 +50,7 @@ export interface GetOptions extends OperationOptions {
|
|
|
50
50
|
```ts src/testClient.ts class TestClient
|
|
51
51
|
export class TestClient {
|
|
52
52
|
#context: TestClientContext;
|
|
53
|
+
|
|
53
54
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
54
55
|
this.#context = createTestClientContext(endpoint, options);
|
|
55
56
|
}
|
|
@@ -60,6 +60,7 @@ export interface CreateOptions extends OperationOptions {
|
|
|
60
60
|
```ts src/testClient.ts class TestClient
|
|
61
61
|
export class TestClient {
|
|
62
62
|
#context: TestClientContext;
|
|
63
|
+
|
|
63
64
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
64
65
|
this.#context = createTestClientContext(endpoint, options);
|
|
65
66
|
}
|
|
@@ -72,6 +72,7 @@ export interface CreateOptions extends OperationOptions {
|
|
|
72
72
|
```ts src/testClient.ts class TestClient
|
|
73
73
|
export class TestClient {
|
|
74
74
|
#context: TestClientContext;
|
|
75
|
+
|
|
75
76
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
76
77
|
this.#context = createTestClientContext(endpoint, options);
|
|
77
78
|
}
|
|
@@ -64,6 +64,7 @@ export interface SendOptions extends OperationOptions {}
|
|
|
64
64
|
```ts src/testClient.ts class TestClient
|
|
65
65
|
export class TestClient {
|
|
66
66
|
#context: TestClientContext;
|
|
67
|
+
|
|
67
68
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
68
69
|
this.#context = createTestClientContext(endpoint, options);
|
|
69
70
|
}
|
|
@@ -73,7 +74,7 @@ export class TestClient {
|
|
|
73
74
|
}
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
```ts src/models/serializers.ts function jsonEnumsOnlyCasesToTransportTransform
|
|
77
|
+
```ts src/models/internal/serializers.ts function jsonEnumsOnlyCasesToTransportTransform
|
|
77
78
|
export function jsonEnumsOnlyCasesToTransportTransform(input_?: EnumsOnlyCases | null): any {
|
|
78
79
|
if (!input_) {
|
|
79
80
|
return input_ as any;
|
|
@@ -57,6 +57,7 @@ export interface CreateOptions extends OperationOptions {
|
|
|
57
57
|
```ts src/testClient.ts class TestClient
|
|
58
58
|
export class TestClient {
|
|
59
59
|
#context: TestClientContext;
|
|
60
|
+
|
|
60
61
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
61
62
|
this.#context = createTestClientContext(endpoint, options);
|
|
62
63
|
}
|
|
@@ -59,6 +59,7 @@ export interface CreateOptions extends OperationOptions {
|
|
|
59
59
|
```ts src/testClient.ts class TestClient
|
|
60
60
|
export class TestClient {
|
|
61
61
|
#context: TestClientContext;
|
|
62
|
+
|
|
62
63
|
constructor(endpoint: string, options?: TestClientOptions) {
|
|
63
64
|
this.#context = createTestClientContext(endpoint, options);
|
|
64
65
|
}
|
|
@@ -35,7 +35,7 @@ export interface Foo {
|
|
|
35
35
|
|
|
36
36
|
The generated transformation functions iterate over `int32[]` values, but since **no actual transformation occurs**, this code could be **optimized away**.
|
|
37
37
|
|
|
38
|
-
```ts src/models/serializers.ts function jsonArrayInt32ToTransportTransform
|
|
38
|
+
```ts src/models/internal/serializers.ts function jsonArrayInt32ToTransportTransform
|
|
39
39
|
export function jsonArrayInt32ToTransportTransform(items_?: Array<number> | null): any {
|
|
40
40
|
if (!items_) {
|
|
41
41
|
return items_ as any;
|
|
@@ -55,7 +55,7 @@ export function jsonArrayInt32ToTransportTransform(items_?: Array<number> | null
|
|
|
55
55
|
|
|
56
56
|
Uses `jsonArrayInt32ToTransportTransform` for `myValues`, though this could be optimized by **directly passing the array** instead of applying a redundant transformation function.
|
|
57
57
|
|
|
58
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
58
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
59
59
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
60
60
|
if (!input_) {
|
|
61
61
|
return input_ as any;
|
|
@@ -92,7 +92,7 @@ export async function foo(client: ClientContext, options?: FooOptions): Promise<
|
|
|
92
92
|
|
|
93
93
|
Again, the transformation logic is redundant for primitive types. Instead of generating a function, the deserializer could **use the array directly**.
|
|
94
94
|
|
|
95
|
-
```ts src/models/serializers.ts function jsonArrayInt32ToApplicationTransform
|
|
95
|
+
```ts src/models/internal/serializers.ts function jsonArrayInt32ToApplicationTransform
|
|
96
96
|
export function jsonArrayInt32ToApplicationTransform(items_?: any): Array<number> {
|
|
97
97
|
if (!items_) {
|
|
98
98
|
return items_ as any;
|
|
@@ -112,7 +112,7 @@ export function jsonArrayInt32ToApplicationTransform(items_?: any): Array<number
|
|
|
112
112
|
|
|
113
113
|
Uses the same unnecessary transformation for `myValues`. Optimizing the pipeline could **eliminate this step** for primitive arrays.
|
|
114
114
|
|
|
115
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
115
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
116
116
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
117
117
|
if (!input_) {
|
|
118
118
|
return input_ as any;
|
|
@@ -164,7 +164,7 @@ export interface Bar {
|
|
|
164
164
|
|
|
165
165
|
Uses `jsonArrayBarToTransportTransform` to serialize each `Bar` instance inside `myValues`, ensuring proper transformation of complex objects.
|
|
166
166
|
|
|
167
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
167
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
168
168
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
169
169
|
if (!input_) {
|
|
170
170
|
return input_ as any;
|
|
@@ -179,7 +179,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
179
179
|
|
|
180
180
|
Similarly, the deserializer converts each `Bar` instance in `myValues` back into an application model using `jsonArrayBarToApplicationTransform`.
|
|
181
181
|
|
|
182
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
182
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
183
183
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
184
184
|
if (!input_) {
|
|
185
185
|
return input_ as any;
|
|
@@ -29,7 +29,7 @@ export interface Foo {
|
|
|
29
29
|
|
|
30
30
|
This function should correctly transform a Foo instance into a transport-friendly format, ensuring all properties are properly mapped.
|
|
31
31
|
|
|
32
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
32
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
33
33
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
34
34
|
if (!input_) {
|
|
35
35
|
return input_ as any;
|
|
@@ -45,7 +45,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
45
45
|
|
|
46
46
|
This function should correctly reconstruct a Foo instance from a transport-friendly representation, ensuring all properties are properly mapped back.
|
|
47
47
|
|
|
48
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
48
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
49
49
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
50
50
|
if (!input_) {
|
|
51
51
|
return input_ as any;
|
|
@@ -82,7 +82,7 @@ op foo(): Foo | Bar;
|
|
|
82
82
|
|
|
83
83
|
This function should transform Foo into a transport-friendly format while ensuring that the bar property is serialized using the jsonBarToTransportTransform function.
|
|
84
84
|
|
|
85
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
85
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
86
86
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
87
87
|
if (!input_) {
|
|
88
88
|
return input_ as any;
|
|
@@ -99,7 +99,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
99
99
|
|
|
100
100
|
This function should transform a Bar instance into its transport format, correctly mapping its properties.
|
|
101
101
|
|
|
102
|
-
```ts src/models/serializers.ts function jsonBarToTransportTransform
|
|
102
|
+
```ts src/models/internal/serializers.ts function jsonBarToTransportTransform
|
|
103
103
|
export function jsonBarToTransportTransform(input_?: Bar | null): any {
|
|
104
104
|
if (!input_) {
|
|
105
105
|
return input_ as any;
|
|
@@ -12,7 +12,7 @@ op foo(): Foo;
|
|
|
12
12
|
|
|
13
13
|
## TypeScript
|
|
14
14
|
|
|
15
|
-
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
15
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/internal/serializers.ts`.
|
|
16
16
|
The generated model should have property names using camelCasing. Serializer should return these properties with the same name defined in the spec while the deserializer
|
|
17
17
|
should return these properties with the same name as the generated model (camelCase)
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ export interface Foo {
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
26
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
27
27
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
28
28
|
if (!input_) {
|
|
29
29
|
return input_ as any;
|
|
@@ -35,7 +35,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
38
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
39
39
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
40
40
|
if (!input_) {
|
|
41
41
|
return input_ as any;
|
|
@@ -31,7 +31,7 @@ op put(@body body: WidgetData): void;
|
|
|
31
31
|
|
|
32
32
|
## Typescript
|
|
33
33
|
|
|
34
|
-
```ts src/models/serializers.ts function jsonWidgetDataToTransportTransform
|
|
34
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToTransportTransform
|
|
35
35
|
export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null): any {
|
|
36
36
|
if (!input_) {
|
|
37
37
|
return input_ as any;
|
|
@@ -40,7 +40,7 @@ export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null):
|
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
```ts src/models/serializers.ts function jsonWidgetDataToApplicationTransform
|
|
43
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToApplicationTransform
|
|
44
44
|
export function jsonWidgetDataToApplicationTransform(input_?: any): WidgetData {
|
|
45
45
|
if (!input_) {
|
|
46
46
|
return input_ as any;
|
|
@@ -49,7 +49,7 @@ export function jsonWidgetDataToApplicationTransform(input_?: any): WidgetData {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
```ts src/models/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
52
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
53
53
|
export function jsonWidgetDataToTransportDiscriminator(input_?: WidgetData): any {
|
|
54
54
|
if (!input_) {
|
|
55
55
|
return input_ as any;
|
|
@@ -67,7 +67,7 @@ export function jsonWidgetDataToTransportDiscriminator(input_?: WidgetData): any
|
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
```ts src/models/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
70
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
71
71
|
export function jsonWidgetDataToApplicationDiscriminator(input_?: any): WidgetData {
|
|
72
72
|
if (!input_) {
|
|
73
73
|
return input_ as any;
|
|
@@ -39,7 +39,7 @@ op put(@body body: SpreadRecordForDiscriminatedUnion): void;
|
|
|
39
39
|
|
|
40
40
|
## Typescript
|
|
41
41
|
|
|
42
|
-
```ts src/models/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToTransportTransform
|
|
42
|
+
```ts src/models/internal/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToTransportTransform
|
|
43
43
|
export function jsonSpreadRecordForDiscriminatedUnionToTransportTransform(
|
|
44
44
|
input_?: SpreadRecordForDiscriminatedUnion | null,
|
|
45
45
|
): any {
|
|
@@ -53,7 +53,7 @@ export function jsonSpreadRecordForDiscriminatedUnionToTransportTransform(
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
```ts src/models/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform
|
|
56
|
+
```ts src/models/internal/serializers.ts function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform
|
|
57
57
|
export function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform(
|
|
58
58
|
input_?: any,
|
|
59
59
|
): SpreadRecordForDiscriminatedUnion {
|
|
@@ -69,7 +69,7 @@ export function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform(
|
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
```ts src/models/serializers.ts function jsonWidgetDataToTransportTransform
|
|
72
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToTransportTransform
|
|
73
73
|
export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null): any {
|
|
74
74
|
if (!input_) {
|
|
75
75
|
return input_ as any;
|
|
@@ -78,7 +78,7 @@ export function jsonWidgetDataToTransportTransform(input_?: WidgetData | null):
|
|
|
78
78
|
}
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
```ts src/models/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
81
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToApplicationDiscriminator
|
|
82
82
|
export function jsonWidgetDataToApplicationDiscriminator(input_?: any): WidgetData {
|
|
83
83
|
if (!input_) {
|
|
84
84
|
return input_ as any;
|
|
@@ -96,7 +96,7 @@ export function jsonWidgetDataToApplicationDiscriminator(input_?: any): WidgetDa
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
```ts src/models/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
99
|
+
```ts src/models/internal/serializers.ts function jsonWidgetDataToTransportDiscriminator
|
|
100
100
|
export function jsonWidgetDataToTransportDiscriminator(input_?: WidgetData): any {
|
|
101
101
|
if (!input_) {
|
|
102
102
|
return input_ as any;
|
|
@@ -14,7 +14,7 @@ op foo(): Foo;
|
|
|
14
14
|
|
|
15
15
|
## TypeScript
|
|
16
16
|
|
|
17
|
-
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
17
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/internal/serializers.ts`.
|
|
18
18
|
The generated model should have a property `createdOn` of type `Date`, the generated serializer `jsonFooToTransportTransform` should convert a Date into a string.
|
|
19
19
|
|
|
20
20
|
```ts src/models/models.ts interface Foo
|
|
@@ -23,7 +23,7 @@ export interface Foo {
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
26
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
27
27
|
export function jsonFooToTransportTransform(item: Foo): any {
|
|
28
28
|
return {
|
|
29
29
|
created_on: dateRfc3339Serializer(item.createdOn),
|
|
@@ -31,7 +31,7 @@ export function jsonFooToTransportTransform(item: Foo): any {
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
34
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
35
35
|
export function jsonFooToApplicationTransform(item: any): Foo {
|
|
36
36
|
return {
|
|
37
37
|
createdOn: dateDeserializer(item.created_on),
|
|
@@ -53,10 +53,10 @@ op foo(): Foo;
|
|
|
53
53
|
|
|
54
54
|
## TypeScript
|
|
55
55
|
|
|
56
|
-
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/serializers.ts`.
|
|
56
|
+
Should generate a type for type with name `Foo` in the `src/models/models.ts` file along with a serializer named `jsonFooToTransportTransform` and a deserializer named `jsonFooToApplicationTransform` in `src/models/internal/serializers.ts`.
|
|
57
57
|
The generated model should have a property `createdOn` of type `Date`, the generated serializer `jsonFooToTransportTransform` should convert a Date into a string using `toUTCString()`
|
|
58
58
|
|
|
59
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
59
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
60
60
|
export function jsonFooToTransportTransform(item: Foo): any {
|
|
61
61
|
return {
|
|
62
62
|
created_on: dateRfc7231Serializer(item.createdOn),
|
|
@@ -46,7 +46,7 @@ op getModel(): Bird;
|
|
|
46
46
|
**Expectation for `jsonBirdToTransportDiscriminator`:**
|
|
47
47
|
This function should select the appropriate transport transformation based on the `kind` property of the `Bird` instance. It checks for specific kinds ("seagull", "sparrow", "goose", "eagle") and delegates to the corresponding transform. If the kind is unknown, it logs a warning and returns a fallback value.
|
|
48
48
|
|
|
49
|
-
```ts src/models/serializers.ts function jsonBirdToTransportDiscriminator
|
|
49
|
+
```ts src/models/internal/serializers.ts function jsonBirdToTransportDiscriminator
|
|
50
50
|
export function jsonBirdToTransportDiscriminator(input_?: Bird): any {
|
|
51
51
|
if (!input_) {
|
|
52
52
|
return input_ as any;
|
|
@@ -75,7 +75,7 @@ export function jsonBirdToTransportDiscriminator(input_?: Bird): any {
|
|
|
75
75
|
**Expectation for `jsonBirdToTransportTransform`:**
|
|
76
76
|
This function should transform a basic `Bird` instance by mapping its core properties (`kind` and `wingspan`) to the transport format.
|
|
77
77
|
|
|
78
|
-
```ts src/models/serializers.ts function jsonBirdToTransportTransform
|
|
78
|
+
```ts src/models/internal/serializers.ts function jsonBirdToTransportTransform
|
|
79
79
|
export function jsonBirdToTransportTransform(input_?: Bird | null): any {
|
|
80
80
|
if (!input_) {
|
|
81
81
|
return input_ as any;
|
|
@@ -91,7 +91,7 @@ export function jsonBirdToTransportTransform(input_?: Bird | null): any {
|
|
|
91
91
|
**Expectation for `jsonSeaGullToTransportTransform`:**
|
|
92
92
|
For a `SeaGull` instance, the serializer should extend the base transformation provided by `jsonBirdToApplicationTransform` and then explicitly include all properties from SeaGull in this case it is just the `kind` .
|
|
93
93
|
|
|
94
|
-
```ts src/models/serializers.ts function jsonSeaGullToTransportTransform
|
|
94
|
+
```ts src/models/internal/serializers.ts function jsonSeaGullToTransportTransform
|
|
95
95
|
export function jsonSeaGullToTransportTransform(input_?: SeaGull | null): any {
|
|
96
96
|
if (!input_) {
|
|
97
97
|
return input_ as any;
|
|
@@ -106,7 +106,7 @@ export function jsonSeaGullToTransportTransform(input_?: SeaGull | null): any {
|
|
|
106
106
|
**Expectation for `jsonSparrowToTransportTransform`:**
|
|
107
107
|
Similarly, the serializer for a `Sparrow` instance should build upon the base Bird transformation and add the `kind` property accordingly.
|
|
108
108
|
|
|
109
|
-
```ts src/models/serializers.ts function jsonSparrowToTransportTransform
|
|
109
|
+
```ts src/models/internal/serializers.ts function jsonSparrowToTransportTransform
|
|
110
110
|
export function jsonSparrowToTransportTransform(input_?: Sparrow | null): any {
|
|
111
111
|
if (!input_) {
|
|
112
112
|
return input_ as any;
|
|
@@ -121,7 +121,7 @@ export function jsonSparrowToTransportTransform(input_?: Sparrow | null): any {
|
|
|
121
121
|
**Expectation for `jsonGooseToTransportTransform`:**
|
|
122
122
|
This function should transform a `Goose` instance by reusing the base Bird transformation and explicitly setting the `kind` property.
|
|
123
123
|
|
|
124
|
-
```ts src/models/serializers.ts function jsonGooseToTransportTransform
|
|
124
|
+
```ts src/models/internal/serializers.ts function jsonGooseToTransportTransform
|
|
125
125
|
export function jsonGooseToTransportTransform(input_?: Goose | null): any {
|
|
126
126
|
if (!input_) {
|
|
127
127
|
return input_ as any;
|
|
@@ -141,7 +141,7 @@ The serializer for an `Eagle` instance is more complex due to additional propert
|
|
|
141
141
|
- Transform the `hate` property (a primitive Record of `Bird` instances) using `jsonRecordBirdToTransportTransform`, and
|
|
142
142
|
- Transform the `partner` property (a single `Bird` instance) using `jsonBirdToApplicationTransform`.
|
|
143
143
|
|
|
144
|
-
```ts src/models/serializers.ts function jsonEagleToTransportTransform
|
|
144
|
+
```ts src/models/internal/serializers.ts function jsonEagleToTransportTransform
|
|
145
145
|
export function jsonEagleToTransportTransform(input_?: Eagle | null): any {
|
|
146
146
|
if (!input_) {
|
|
147
147
|
return input_ as any;
|
|
@@ -43,7 +43,7 @@ Validates that the serializer generates the correct serialization logic for:
|
|
|
43
43
|
- Direct property references (`title?: TodoItem.title`)
|
|
44
44
|
- Nullable property references (`assignedTo?: TodoItem.assignedTo | null`)
|
|
45
45
|
|
|
46
|
-
```ts src/models/serializers.ts function jsonTodoItemPatchToTransportTransform
|
|
46
|
+
```ts src/models/internal/serializers.ts function jsonTodoItemPatchToTransportTransform
|
|
47
47
|
export function jsonTodoItemPatchToTransportTransform(input_?: TodoItemPatch | null): any {
|
|
48
48
|
if (!input_) {
|
|
49
49
|
return input_ as any;
|
|
@@ -59,7 +59,7 @@ export function jsonTodoItemPatchToTransportTransform(input_?: TodoItemPatch | n
|
|
|
59
59
|
|
|
60
60
|
Validates the deserialization logic maintains type consistency when converting from transport to application models.
|
|
61
61
|
|
|
62
|
-
```ts src/models/serializers.ts function jsonTodoItemPatchToApplicationTransform
|
|
62
|
+
```ts src/models/internal/serializers.ts function jsonTodoItemPatchToApplicationTransform
|
|
63
63
|
export function jsonTodoItemPatchToApplicationTransform(input_?: any): TodoItemPatch {
|
|
64
64
|
if (!input_) {
|
|
65
65
|
return input_ as any;
|
|
@@ -20,7 +20,7 @@ export interface Foo {
|
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
23
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
24
24
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
25
25
|
if (!input_) {
|
|
26
26
|
return input_ as any;
|
|
@@ -31,7 +31,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
34
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
35
35
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
36
36
|
if (!input_) {
|
|
37
37
|
return input_ as any;
|
|
@@ -74,7 +74,7 @@ export interface Bar {
|
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
```ts src/models/serializers.ts function jsonFooToTransportTransform
|
|
77
|
+
```ts src/models/internal/serializers.ts function jsonFooToTransportTransform
|
|
78
78
|
export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
79
79
|
if (!input_) {
|
|
80
80
|
return input_ as any;
|
|
@@ -85,7 +85,7 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
85
85
|
}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
```ts src/models/serializers.ts function jsonFooToApplicationTransform
|
|
88
|
+
```ts src/models/internal/serializers.ts function jsonFooToApplicationTransform
|
|
89
89
|
export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
90
90
|
if (!input_) {
|
|
91
91
|
return input_ as any;
|
|
@@ -31,7 +31,7 @@ op spreadWithMultipleParameters(...MultipleRequestParameters): NoContentResponse
|
|
|
31
31
|
|
|
32
32
|
## Typescript
|
|
33
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/serializers.ts
|
|
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
35
|
|
|
36
36
|
```ts src/api/testClientOperations.ts function spreadWithMultipleParameters
|
|
37
37
|
export async function spreadWithMultipleParameters(
|
|
@@ -43,7 +43,7 @@ export async function unionEnumName(
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
```ts src/models/serializers.ts function jsonServerExtensibleEnumToTransportTransform
|
|
46
|
+
```ts src/models/internal/serializers.ts function jsonServerExtensibleEnumToTransportTransform
|
|
47
47
|
export function jsonServerExtensibleEnumToTransportTransform(
|
|
48
48
|
input_?: ServerExtensibleEnum | null,
|
|
49
49
|
): any {
|
package/test/scenarios.test.ts
CHANGED
|
@@ -3,16 +3,24 @@ import {
|
|
|
3
3
|
createTypeScriptExtractorConfig,
|
|
4
4
|
executeScenarios,
|
|
5
5
|
} from "@typespec/emitter-framework/testing";
|
|
6
|
-
import { join } from "path";
|
|
6
|
+
import { dirname, join } from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
7
8
|
import { HttpClientJavascriptEmitterTestLibrary } from "../src/testing/index.js";
|
|
8
9
|
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
|
|
9
13
|
const tsExtractorConfig = createTypeScriptExtractorConfig();
|
|
10
14
|
const snipperExtractor = createSnipperExtractor(tsExtractorConfig);
|
|
11
15
|
|
|
16
|
+
// Construct the test path relative to this file.
|
|
17
|
+
const scenarioPath = join(__dirname, "scenarios");
|
|
18
|
+
const outputPath = join("tsp-output", "@typespec", "http-client-js");
|
|
19
|
+
|
|
12
20
|
await executeScenarios(
|
|
13
21
|
HttpClientJavascriptEmitterTestLibrary,
|
|
14
22
|
tsExtractorConfig,
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
scenarioPath,
|
|
24
|
+
outputPath,
|
|
17
25
|
snipperExtractor,
|
|
18
26
|
);
|
|
@@ -0,0 +1,16 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { babel } from "@rollup/plugin-babel";
|
|
2
|
+
import { defineConfig, mergeConfig } from "vitest/config";
|
|
3
|
+
import { defaultTypeSpecVitestConfig } from "../../vitest.workspace.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
|
+
esbuild: {
|
|
14
|
+
jsx: "preserve",
|
|
15
|
+
sourcemap: "both",
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
babel({
|
|
19
|
+
sourceMaps: true,
|
|
20
|
+
babelHelpers: "bundled",
|
|
21
|
+
extensions: [".ts", ".tsx"],
|
|
22
|
+
presets: ["@babel/preset-typescript", "@alloy-js/babel-preset"],
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
26
|
+
);
|
package/vitest.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { babel } from "@rollup/plugin-babel";
|
|
2
|
-
import { defineConfig } from "vitest/config";
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
test: {
|
|
6
|
-
include: ["test/**/*.test.ts", "test/**/*.test.tsx"],
|
|
7
|
-
exclude: ["test/**/*.d.ts"],
|
|
8
|
-
passWithNoTests: true,
|
|
9
|
-
},
|
|
10
|
-
esbuild: {
|
|
11
|
-
jsx: "preserve",
|
|
12
|
-
sourcemap: "both",
|
|
13
|
-
},
|
|
14
|
-
plugins: [
|
|
15
|
-
babel({
|
|
16
|
-
inputSourceMap: true,
|
|
17
|
-
sourceMaps: "both",
|
|
18
|
-
babelHelpers: "bundled",
|
|
19
|
-
extensions: [".ts", ".tsx"],
|
|
20
|
-
presets: ["@babel/preset-typescript", "@alloy-js/babel-preset"],
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
});
|