@typespec/http-client-js 0.2.0-dev.1 → 0.2.0-dev.11
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/.github/copilot-instructions.md +193 -0
- package/README.md +31 -15
- package/dist/src/components/client-context/client-context-declaration.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-declaration.js.map +1 -1
- package/dist/src/components/client-context/client-context-factory.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-factory.js +7 -4
- package/dist/src/components/client-context/client-context-factory.js.map +1 -1
- package/dist/src/components/client-context/client-context-options.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context-options.js +13 -9
- package/dist/src/components/client-context/client-context-options.js.map +1 -1
- package/dist/src/components/client-context/client-context.d.ts.map +1 -1
- package/dist/src/components/client-context/client-context.js +7 -12
- package/dist/src/components/client-context/client-context.js.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.d.ts +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.d.ts.map +1 -1
- package/dist/src/components/client-context/parametrized-endpoint.js +22 -13
- package/dist/src/components/client-context/parametrized-endpoint.js.map +1 -1
- package/dist/src/components/client-directory.d.ts +2 -2
- package/dist/src/components/client-directory.d.ts.map +1 -1
- package/dist/src/components/client-directory.js +33 -21
- package/dist/src/components/client-directory.js.map +1 -1
- package/dist/src/components/client-operation.d.ts.map +1 -1
- package/dist/src/components/client-operation.js +6 -6
- package/dist/src/components/client-operation.js.map +1 -1
- package/dist/src/components/client.d.ts +1 -1
- package/dist/src/components/client.d.ts.map +1 -1
- package/dist/src/components/client.js +83 -64
- package/dist/src/components/client.js.map +1 -1
- package/dist/src/components/encoding-provider.d.ts.map +1 -1
- package/dist/src/components/encoding-provider.js +0 -1
- package/dist/src/components/encoding-provider.js.map +1 -1
- package/dist/src/components/http-request-options.d.ts.map +1 -1
- package/dist/src/components/http-request-options.js +3 -3
- package/dist/src/components/http-request-options.js.map +1 -1
- package/dist/src/components/http-request-parameters-expression.d.ts +1 -2
- package/dist/src/components/http-request-parameters-expression.d.ts.map +1 -1
- package/dist/src/components/http-request-parameters-expression.js +37 -33
- package/dist/src/components/http-request-parameters-expression.js.map +1 -1
- package/dist/src/components/http-request.d.ts.map +1 -1
- package/dist/src/components/http-request.js +24 -20
- package/dist/src/components/http-request.js.map +1 -1
- package/dist/src/components/http-response.d.ts +1 -1
- package/dist/src/components/http-response.d.ts.map +1 -1
- package/dist/src/components/http-response.js +36 -33
- package/dist/src/components/http-response.js.map +1 -1
- package/dist/src/components/models.d.ts.map +1 -1
- package/dist/src/components/models.js +21 -18
- package/dist/src/components/models.js.map +1 -1
- package/dist/src/components/operation-options.d.ts.map +1 -1
- package/dist/src/components/operation-options.js +17 -14
- package/dist/src/components/operation-options.js.map +1 -1
- package/dist/src/components/output.js +0 -1
- package/dist/src/components/output.js.map +1 -1
- package/dist/src/components/serializers.d.ts.map +1 -1
- package/dist/src/components/serializers.js +21 -14
- package/dist/src/components/serializers.js.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.d.ts.map +1 -1
- package/dist/src/components/static-helpers/bytes-encoding.js +2 -2
- package/dist/src/components/static-helpers/bytes-encoding.js.map +1 -1
- package/dist/src/components/static-helpers/interfaces.d.ts.map +1 -1
- package/dist/src/components/static-helpers/interfaces.js.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.d.ts.map +1 -1
- package/dist/src/components/static-helpers/multipart-helpers.js +4 -4
- package/dist/src/components/static-helpers/multipart-helpers.js.map +1 -1
- package/dist/src/components/static-helpers/rest-error.d.ts.map +1 -1
- package/dist/src/components/static-helpers/rest-error.js +66 -57
- package/dist/src/components/static-helpers/rest-error.js.map +1 -1
- package/dist/src/components/testing/client-options.d.ts.map +1 -1
- package/dist/src/components/testing/client-options.js +0 -2
- package/dist/src/components/testing/client-options.js.map +1 -1
- package/dist/src/components/transforms/content-type-encoding-provider.d.ts.map +1 -1
- package/dist/src/components/transforms/content-type-encoding-provider.js +0 -1
- package/dist/src/components/transforms/content-type-encoding-provider.js.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-array-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js +4 -4
- package/dist/src/components/transforms/json/json-model-additional-properties-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-base-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-base-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-property-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-model-transform.js +20 -17
- package/dist/src/components/transforms/json/json-model-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-record-transform.js.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform-discriminator.js +5 -10
- package/dist/src/components/transforms/json/json-transform-discriminator.js.map +1 -1
- package/dist/src/components/transforms/json/json-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/json-transform.js.map +1 -1
- package/dist/src/components/transforms/json/union-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/json/union-transform.js +2 -2
- package/dist/src/components/transforms/json/union-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/array-part-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/file-part-transform.js +1 -1
- package/dist/src/components/transforms/multipart/file-part-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/multipart-transform.js +9 -6
- package/dist/src/components/transforms/multipart/multipart-transform.js.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.d.ts.map +1 -1
- package/dist/src/components/transforms/multipart/simple-part-transform.js +23 -13
- package/dist/src/components/transforms/multipart/simple-part-transform.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-declaration.js +2 -2
- package/dist/src/components/transforms/operation-transform-declaration.js.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.d.ts.map +1 -1
- package/dist/src/components/transforms/operation-transform-expression.js.map +1 -1
- package/dist/src/components/utils/unpack-model-property.d.ts.map +1 -1
- package/dist/src/components/utils/unpack-model-property.js +11 -2
- package/dist/src/components/utils/unpack-model-property.js.map +1 -1
- package/dist/src/components/utils/url-template.d.ts.map +1 -1
- package/dist/src/components/utils/url-template.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +6 -6
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/utils/operations.d.ts +13 -1
- package/dist/src/utils/operations.d.ts.map +1 -1
- package/dist/src/utils/operations.js +71 -0
- package/dist/src/utils/operations.js.map +1 -1
- package/dist/src/utils/parameters.d.ts.map +1 -1
- package/dist/src/utils/parameters.js +1 -1
- package/dist/src/utils/parameters.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/emit-e2e.js +1 -1
- package/package.json +16 -14
- package/src/components/client-context/client-context-declaration.tsx +8 -1
- package/src/components/client-context/client-context-factory.tsx +50 -30
- package/src/components/client-context/client-context-options.tsx +13 -6
- package/src/components/client-context/client-context.tsx +5 -3
- package/src/components/client-context/parametrized-endpoint.tsx +26 -15
- package/src/components/client-directory.tsx +26 -16
- package/src/components/client-operation.tsx +24 -12
- package/src/components/client.tsx +77 -39
- package/src/components/encoding-provider.tsx +1 -3
- package/src/components/http-request-options.tsx +24 -14
- package/src/components/http-request-parameters-expression.tsx +34 -37
- package/src/components/http-request.tsx +26 -16
- package/src/components/http-response.tsx +31 -26
- package/src/components/models.tsx +18 -14
- package/src/components/operation-options.tsx +18 -5
- package/src/components/output.tsx +9 -9
- package/src/components/serializers.tsx +21 -9
- package/src/components/static-helpers/bytes-encoding.tsx +26 -8
- package/src/components/static-helpers/interfaces.tsx +14 -9
- package/src/components/static-helpers/multipart-helpers.tsx +34 -13
- package/src/components/static-helpers/rest-error.tsx +56 -18
- package/src/components/testing/client-options.tsx +0 -3
- package/src/components/transforms/content-type-encoding-provider.tsx +1 -3
- package/src/components/transforms/json/json-array-transform.tsx +6 -4
- package/src/components/transforms/json/json-model-additional-properties-transform.tsx +18 -13
- package/src/components/transforms/json/json-model-base-transform.tsx +6 -1
- package/src/components/transforms/json/json-model-property-transform.tsx +7 -9
- package/src/components/transforms/json/json-model-transform.tsx +44 -16
- package/src/components/transforms/json/json-record-transform.tsx +5 -3
- package/src/components/transforms/json/json-transform-discriminator.tsx +17 -30
- package/src/components/transforms/json/json-transform.tsx +5 -3
- package/src/components/transforms/json/union-transform.tsx +20 -8
- package/src/components/transforms/multipart/array-part-transform.tsx +6 -3
- package/src/components/transforms/multipart/file-part-transform.tsx +1 -1
- package/src/components/transforms/multipart/multipart-transform.tsx +4 -6
- package/src/components/transforms/multipart/part-transform.tsx +1 -1
- package/src/components/transforms/multipart/simple-part-transform.tsx +16 -13
- package/src/components/transforms/operation-transform-declaration.tsx +24 -7
- package/src/components/transforms/operation-transform-expression.tsx +12 -5
- package/src/components/utils/unpack-model-property.ts +13 -2
- package/src/components/utils/url-template.tsx +10 -6
- package/src/emitter.tsx +4 -3
- package/src/lib.ts +6 -1
- package/src/utils/operations.ts +96 -1
- package/src/utils/parameters.tsx +5 -1
- package/test/e2e/http/payload/multipart/main.test.ts +20 -24
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +4 -1
- package/test/scenarios/additional-properties/extends.md +0 -4
- package/test/scenarios/additional-properties/is.md +0 -4
- package/test/scenarios/additional-properties/spread.md +0 -4
- package/test/scenarios/auth/basic_auth.md +1 -4
- package/test/scenarios/auth/bearer.md +1 -4
- package/test/scenarios/auth/client_parameters.md +1 -4
- package/test/scenarios/auth/client_structure.md +1 -3
- package/test/scenarios/auth/key_credential.md +1 -4
- package/test/scenarios/auth/sub_client_override.md +1 -5
- package/test/scenarios/client/client_context.md +1 -3
- package/test/scenarios/client/dotted_namespace.md +1 -4
- package/test/scenarios/client/global_namespace.md +0 -5
- package/test/scenarios/client/multiple_top_level_clients.md +0 -2
- package/test/scenarios/client/nested_client.md +1 -5
- package/test/scenarios/client/wrapping_namespace.md +1 -3
- package/test/scenarios/encoding/bytes_body.md +0 -4
- package/test/scenarios/encoding/bytes_json_property.md +0 -5
- package/test/scenarios/encoding/bytes_nullable.md +0 -14
- package/test/scenarios/encoding/header_bytes.md +0 -12
- package/test/scenarios/encoding/header_date.md +0 -20
- package/test/scenarios/encoding/model_with_bytes_property.md +0 -5
- package/test/scenarios/encoding/query_bytes.md +0 -4
- package/test/scenarios/encoding/query_date.md +0 -20
- package/test/scenarios/http-operations/basic-request.md +3 -21
- package/test/scenarios/http-operations/basic-response.md +4 -31
- package/test/scenarios/http-operations/basic.md +0 -6
- package/test/scenarios/http-operations/constant-header.md +0 -4
- package/test/scenarios/http-operations/create-operation.md +0 -4
- package/test/scenarios/http-operations/on_response.md +0 -4
- package/test/scenarios/http-operations/optional-request-body.md +0 -5
- package/test/scenarios/http-operations/path-parameter-in-model.md +1 -7
- package/test/scenarios/http-operations/path-parameter.md +1 -7
- package/test/scenarios/http-operations/scalar-payload.md +1 -7
- package/test/scenarios/http-operations/with-parameters.md +1 -8
- package/test/scenarios/models/inheritance_2_discriminators.md +0 -24
- package/test/scenarios/models/inheritance_discriminator.md +0 -4
- package/test/scenarios/models/inline-models.md +1 -4
- package/test/scenarios/models/model_additional_properties.md +0 -4
- package/test/scenarios/models/model_extends.md +0 -4
- package/test/scenarios/models/model_spread.md +0 -2
- package/test/scenarios/models/nested_property.md +0 -4
- package/test/scenarios/models/property_references_property.md +0 -6
- package/test/scenarios/multipart/anonymous_part.md +2 -11
- package/test/scenarios/multipart/file.md +0 -12
- package/test/scenarios/multipart/file_content_type.md +15 -5
- package/test/scenarios/multipart/non-string-float.md +50 -0
- package/test/scenarios/multipart/simple_part.md +0 -4
- package/test/scenarios/operation-parameters/body_root_anonymous.md +2 -17
- package/test/scenarios/operation-parameters/constant_as_optional.md +0 -5
- package/test/scenarios/operation-parameters/default_value_as_optional.md +0 -5
- package/test/scenarios/operation-parameters/no_content_type.md +0 -5
- package/test/scenarios/operation-parameters/no_parameters.md +0 -5
- package/test/scenarios/operation-parameters/only_optional.md +0 -5
- package/test/scenarios/operation-parameters/only_required.md +0 -5
- package/test/scenarios/operation-parameters/reserved_names.md +0 -5
- package/test/scenarios/operation-parameters/spread_body.md +0 -5
- package/test/scenarios/operation-parameters/spread_with_nested.md +0 -5
- package/test/scenarios/operation-parameters/union_body.md +0 -6
- package/test/scenarios/operation-parameters/with_body_property.md +0 -5
- package/test/scenarios/operation-parameters/with_body_root.md +0 -5
- package/test/scenarios/serializers/arrays.md +0 -8
- package/test/scenarios/serializers/basic_model.md +0 -4
- package/test/scenarios/serializers/basic_model_wire_name.md +0 -2
- package/test/scenarios/serializers/discriminated_union.md +1 -1
- package/test/scenarios/serializers/discriminated_union_spread.md +1 -5
- package/test/scenarios/serializers/multipart.md +0 -4
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +1 -8
- package/test/scenarios/serializers/property_references_property.md +72 -0
- package/test/scenarios/serializers/record.md +0 -4
- package/test/scenarios/serializers/scalars.md +0 -5
- package/test/scenarios/serializers/spread.md +1 -7
- package/test/scenarios/serializers/string_union.md +1 -7
- package/test/scenarios/server/multiple-parameters.md +1 -3
- package/test/scenarios/server/parametrized-endpoint.md +1 -3
|
@@ -60,7 +60,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
60
60
|
if (!input_) {
|
|
61
61
|
return input_ as any;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
63
|
return {
|
|
65
64
|
my_values: jsonArrayInt32ToTransportTransform(input_.myValues),
|
|
66
65
|
}!;
|
|
@@ -74,21 +73,17 @@ Handles the API request, expecting a `Widget` response and applying the correct
|
|
|
74
73
|
```ts src/api/clientOperations.ts function foo
|
|
75
74
|
export async function foo(client: ClientContext, options?: FooOptions): Promise<Foo> {
|
|
76
75
|
const path = parse("/").expand({});
|
|
77
|
-
|
|
78
76
|
const httpRequestOptions = {
|
|
79
77
|
headers: {},
|
|
80
78
|
};
|
|
81
|
-
|
|
82
79
|
const response = await client.pathUnchecked(path).get(httpRequestOptions);
|
|
83
80
|
|
|
84
81
|
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
85
82
|
options?.operationOptions?.onResponse(response);
|
|
86
83
|
}
|
|
87
|
-
|
|
88
84
|
if (+response.status === 200 && response.headers["content-type"]?.includes("application/json")) {
|
|
89
85
|
return jsonFooToApplicationTransform(response.body)!;
|
|
90
86
|
}
|
|
91
|
-
|
|
92
87
|
throw createRestError(response);
|
|
93
88
|
}
|
|
94
89
|
```
|
|
@@ -122,7 +117,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
122
117
|
if (!input_) {
|
|
123
118
|
return input_ as any;
|
|
124
119
|
}
|
|
125
|
-
|
|
126
120
|
return {
|
|
127
121
|
myValues: jsonArrayInt32ToApplicationTransform(input_.my_values),
|
|
128
122
|
}!;
|
|
@@ -175,7 +169,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
175
169
|
if (!input_) {
|
|
176
170
|
return input_ as any;
|
|
177
171
|
}
|
|
178
|
-
|
|
179
172
|
return {
|
|
180
173
|
my_values: jsonArrayBarToTransportTransform(input_.myValues),
|
|
181
174
|
}!;
|
|
@@ -191,7 +184,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
191
184
|
if (!input_) {
|
|
192
185
|
return input_ as any;
|
|
193
186
|
}
|
|
194
|
-
|
|
195
187
|
return {
|
|
196
188
|
myValues: jsonArrayBarToApplicationTransform(input_.my_values),
|
|
197
189
|
}!;
|
|
@@ -34,7 +34,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
34
34
|
if (!input_) {
|
|
35
35
|
return input_ as any;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
return {
|
|
39
38
|
name: input_.name,
|
|
40
39
|
age: input_.age,
|
|
@@ -51,7 +50,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
51
50
|
if (!input_) {
|
|
52
51
|
return input_ as any;
|
|
53
52
|
}
|
|
54
|
-
|
|
55
53
|
return {
|
|
56
54
|
name: input_.name,
|
|
57
55
|
age: input_.age,
|
|
@@ -89,7 +87,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
89
87
|
if (!input_) {
|
|
90
88
|
return input_ as any;
|
|
91
89
|
}
|
|
92
|
-
|
|
93
90
|
return {
|
|
94
91
|
name: input_.name,
|
|
95
92
|
age: input_.age,
|
|
@@ -107,7 +104,6 @@ export function jsonBarToTransportTransform(input_?: Bar | null): any {
|
|
|
107
104
|
if (!input_) {
|
|
108
105
|
return input_ as any;
|
|
109
106
|
}
|
|
110
|
-
|
|
111
107
|
return {
|
|
112
108
|
address: input_.address,
|
|
113
109
|
}!;
|
|
@@ -28,7 +28,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
28
28
|
if (!input_) {
|
|
29
29
|
return input_ as any;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
return {
|
|
33
32
|
element_name: input_.elementName,
|
|
34
33
|
age: input_.age,
|
|
@@ -41,7 +40,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
41
40
|
if (!input_) {
|
|
42
41
|
return input_ as any;
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
return {
|
|
46
44
|
elementName: input_.element_name,
|
|
47
45
|
age: input_.age,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
```tsp
|
|
6
6
|
@service
|
|
7
7
|
namespace Test;
|
|
8
|
-
@
|
|
8
|
+
@discriminated(#{ envelope: "none", discriminatorPropertyName: "kind" })
|
|
9
9
|
union WidgetData {
|
|
10
10
|
kind0: WidgetData0,
|
|
11
11
|
kind1: WidgetData1,
|
|
@@ -46,10 +46,8 @@ export function jsonSpreadRecordForDiscriminatedUnionToTransportTransform(
|
|
|
46
46
|
if (!input_) {
|
|
47
47
|
return input_ as any;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
return {
|
|
51
50
|
...jsonRecordWidgetDataToTransportTransform(input_.additionalProperties),
|
|
52
|
-
|
|
53
51
|
name: input_.name,
|
|
54
52
|
}!;
|
|
55
53
|
}
|
|
@@ -62,12 +60,10 @@ export function jsonSpreadRecordForDiscriminatedUnionToApplicationTransform(
|
|
|
62
60
|
if (!input_) {
|
|
63
61
|
return input_ as any;
|
|
64
62
|
}
|
|
65
|
-
|
|
66
63
|
return {
|
|
67
64
|
additionalProperties: jsonRecordWidgetDataToApplicationTransform(
|
|
68
65
|
(({ name, ...rest }) => rest)(input_),
|
|
69
66
|
),
|
|
70
|
-
|
|
71
67
|
name: input_.name,
|
|
72
68
|
}!;
|
|
73
69
|
}
|
|
@@ -43,24 +43,20 @@ export async function create(
|
|
|
43
43
|
options?: CreateOptions,
|
|
44
44
|
): Promise<void> {
|
|
45
45
|
const path = parse("/").expand({});
|
|
46
|
-
|
|
47
46
|
const httpRequestOptions = {
|
|
48
47
|
headers: {
|
|
49
48
|
"content-type": options?.contentType ?? "multipart/form-data",
|
|
50
49
|
},
|
|
51
50
|
body: [createFilePartDescriptor("profileImage", body.profileImage, "image/jpg")],
|
|
52
51
|
};
|
|
53
|
-
|
|
54
52
|
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
55
53
|
|
|
56
54
|
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
57
55
|
options?.operationOptions?.onResponse(response);
|
|
58
56
|
}
|
|
59
|
-
|
|
60
57
|
if (+response.status === 204 && !response.body) {
|
|
61
58
|
return;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
throw createRestError(response);
|
|
65
61
|
}
|
|
66
62
|
```
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
The following TypeSpec block defines a service and several data models that serve as the foundation for our serializer tests. It starts with a base model, Bird, which uses a discriminator (kind) to support polymorphic behavior. Several derived models—SeaGull, Sparrow, Goose, and Eagle—are declared, each with a specific kind value to enable precise runtime type dispatching. Notably, the Eagle model includes additional complex properties (an array, a record, and a singular instance of Bird) to thoroughly test serialization of nested and compound types. This specification also exposes an HTTP GET endpoint returning a polymorphic Bird instance, ensuring that the generated TypeScript serializers handle these scenarios correctly.
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "Test Service",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "Test Service" })
|
|
11
9
|
namespace Test;
|
|
12
10
|
|
|
13
11
|
@doc("This is base model for polymorphic single level inheritance with a discriminator.")
|
|
@@ -82,7 +80,6 @@ export function jsonBirdToTransportTransform(input_?: Bird | null): any {
|
|
|
82
80
|
if (!input_) {
|
|
83
81
|
return input_ as any;
|
|
84
82
|
}
|
|
85
|
-
|
|
86
83
|
return {
|
|
87
84
|
...jsonBirdToTransportDiscriminator(input_),
|
|
88
85
|
kind: input_.kind,
|
|
@@ -99,7 +96,6 @@ export function jsonSeaGullToTransportTransform(input_?: SeaGull | null): any {
|
|
|
99
96
|
if (!input_) {
|
|
100
97
|
return input_ as any;
|
|
101
98
|
}
|
|
102
|
-
|
|
103
99
|
return {
|
|
104
100
|
kind: input_.kind,
|
|
105
101
|
wingspan: input_.wingspan,
|
|
@@ -115,7 +111,6 @@ export function jsonSparrowToTransportTransform(input_?: Sparrow | null): any {
|
|
|
115
111
|
if (!input_) {
|
|
116
112
|
return input_ as any;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
114
|
return {
|
|
120
115
|
kind: input_.kind,
|
|
121
116
|
wingspan: input_.wingspan,
|
|
@@ -131,7 +126,6 @@ export function jsonGooseToTransportTransform(input_?: Goose | null): any {
|
|
|
131
126
|
if (!input_) {
|
|
132
127
|
return input_ as any;
|
|
133
128
|
}
|
|
134
|
-
|
|
135
129
|
return {
|
|
136
130
|
kind: input_.kind,
|
|
137
131
|
wingspan: input_.wingspan,
|
|
@@ -152,7 +146,6 @@ export function jsonEagleToTransportTransform(input_?: Eagle | null): any {
|
|
|
152
146
|
if (!input_) {
|
|
153
147
|
return input_ as any;
|
|
154
148
|
}
|
|
155
|
-
|
|
156
149
|
return {
|
|
157
150
|
kind: input_.kind,
|
|
158
151
|
friends: jsonArrayBirdToTransportTransform(input_.friends),
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Property References in Model Serialization
|
|
2
|
+
|
|
3
|
+
This test verifies that property references in TypeSpec models are correctly serialized, particularly in scenarios involving nullable property references. This was created to address a specific issue where property references combined with nullable types were causing incorrect serialization.
|
|
4
|
+
|
|
5
|
+
## Background
|
|
6
|
+
|
|
7
|
+
When a model property references another model's property (e.g., `TodoItemPatch.title` referencing `TodoItem.title`), the emitter needs to:
|
|
8
|
+
|
|
9
|
+
1. Correctly unpack the referenced property
|
|
10
|
+
2. Handle cases where the reference is combined with a nullable type
|
|
11
|
+
3. Generate appropriate serialization code
|
|
12
|
+
|
|
13
|
+
### Key Concepts
|
|
14
|
+
|
|
15
|
+
- Property References: Using dot notation to reference properties from other models (e.g., `TodoItem.title`)
|
|
16
|
+
- Nullable References: Combining property references with null union type (e.g., `TodoItem.assignedTo | null`)
|
|
17
|
+
|
|
18
|
+
## Spec
|
|
19
|
+
|
|
20
|
+
```tsp
|
|
21
|
+
namespace Test;
|
|
22
|
+
model TodoItem {
|
|
23
|
+
id: safeint;
|
|
24
|
+
title: string;
|
|
25
|
+
assignedTo: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
model TodoItemPatch {
|
|
29
|
+
title?: TodoItem.title;
|
|
30
|
+
assignedTo?: TodoItem.assignedTo | null;
|
|
31
|
+
}
|
|
32
|
+
@patch op update(
|
|
33
|
+
@header contentType: "application/merge-patch+json",
|
|
34
|
+
@path id: TodoItem.id,
|
|
35
|
+
@body patch: TodoItemPatch,
|
|
36
|
+
): TodoItem;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Serializer
|
|
40
|
+
|
|
41
|
+
Validates that the serializer generates the correct serialization logic for:
|
|
42
|
+
|
|
43
|
+
- Direct property references (`title?: TodoItem.title`)
|
|
44
|
+
- Nullable property references (`assignedTo?: TodoItem.assignedTo | null`)
|
|
45
|
+
|
|
46
|
+
```ts src/models/serializers.ts function jsonTodoItemPatchToTransportTransform
|
|
47
|
+
export function jsonTodoItemPatchToTransportTransform(input_?: TodoItemPatch | null): any {
|
|
48
|
+
if (!input_) {
|
|
49
|
+
return input_ as any;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
title: input_.title,
|
|
53
|
+
assignedTo: input_.assignedTo,
|
|
54
|
+
}!;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Deserializer
|
|
59
|
+
|
|
60
|
+
Validates the deserialization logic maintains type consistency when converting from transport to application models.
|
|
61
|
+
|
|
62
|
+
```ts src/models/serializers.ts function jsonTodoItemPatchToApplicationTransform
|
|
63
|
+
export function jsonTodoItemPatchToApplicationTransform(input_?: any): TodoItemPatch {
|
|
64
|
+
if (!input_) {
|
|
65
|
+
return input_ as any;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
title: input_.title,
|
|
69
|
+
assignedTo: input_.assignedTo,
|
|
70
|
+
}!;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
@@ -25,7 +25,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
25
25
|
if (!input_) {
|
|
26
26
|
return input_ as any;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
return {
|
|
30
29
|
my_values: jsonRecordInt32ToTransportTransform(input_.myValues),
|
|
31
30
|
}!;
|
|
@@ -37,7 +36,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
37
36
|
if (!input_) {
|
|
38
37
|
return input_ as any;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
return {
|
|
42
40
|
myValues: jsonRecordInt32ToApplicationTransform(input_.my_values),
|
|
43
41
|
}!;
|
|
@@ -81,7 +79,6 @@ export function jsonFooToTransportTransform(input_?: Foo | null): any {
|
|
|
81
79
|
if (!input_) {
|
|
82
80
|
return input_ as any;
|
|
83
81
|
}
|
|
84
|
-
|
|
85
82
|
return {
|
|
86
83
|
my_values: jsonRecordBarToTransportTransform(input_.myValues),
|
|
87
84
|
}!;
|
|
@@ -93,7 +90,6 @@ export function jsonFooToApplicationTransform(input_?: any): Foo {
|
|
|
93
90
|
if (!input_) {
|
|
94
91
|
return input_ as any;
|
|
95
92
|
}
|
|
96
|
-
|
|
97
93
|
return {
|
|
98
94
|
myValues: jsonRecordBarToApplicationTransform(input_.my_values),
|
|
99
95
|
}!;
|
|
@@ -20,14 +20,9 @@ op foo(a: MyDate, b: MyUtcDate, c: MyIsoDate, d: MyUnixDate): void;
|
|
|
20
20
|
|
|
21
21
|
```ts src/models/models.ts
|
|
22
22
|
export type String = string;
|
|
23
|
-
|
|
24
23
|
export type MyDate = Date;
|
|
25
|
-
|
|
26
24
|
export type UtcDateTime = Date;
|
|
27
|
-
|
|
28
25
|
export type MyUtcDate = Date;
|
|
29
|
-
|
|
30
26
|
export type MyIsoDate = Date;
|
|
31
|
-
|
|
32
27
|
export type MyUnixDate = Date;
|
|
33
28
|
```
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
## Typespec
|
|
4
4
|
|
|
5
5
|
```tsp
|
|
6
|
-
@service({
|
|
7
|
-
title: "Test Service",
|
|
8
|
-
})
|
|
6
|
+
@service(#{ title: "Test Service" })
|
|
9
7
|
namespace Test;
|
|
10
8
|
alias MultipleRequestParameters = {
|
|
11
9
|
@path
|
|
@@ -47,7 +45,6 @@ export async function spreadWithMultipleParameters(
|
|
|
47
45
|
const path = parse("/{id}").expand({
|
|
48
46
|
id: id,
|
|
49
47
|
});
|
|
50
|
-
|
|
51
48
|
const httpRequestOptions = {
|
|
52
49
|
headers: {
|
|
53
50
|
"x-ms-test-header": xMsTestHeader,
|
|
@@ -59,17 +56,14 @@ export async function spreadWithMultipleParameters(
|
|
|
59
56
|
optionalStringList: jsonArrayStringToTransportTransform(options?.optionalStringList),
|
|
60
57
|
},
|
|
61
58
|
};
|
|
62
|
-
|
|
63
59
|
const response = await client.pathUnchecked(path).put(httpRequestOptions);
|
|
64
60
|
|
|
65
61
|
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
66
62
|
options?.operationOptions?.onResponse(response);
|
|
67
63
|
}
|
|
68
|
-
|
|
69
64
|
if (+response.status === 204 && !response.body) {
|
|
70
65
|
return;
|
|
71
66
|
}
|
|
72
|
-
|
|
73
67
|
throw createRestError(response);
|
|
74
68
|
}
|
|
75
69
|
```
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
## Typespec
|
|
4
4
|
|
|
5
5
|
```tsp
|
|
6
|
-
@service({
|
|
7
|
-
title: "Test Service",
|
|
8
|
-
})
|
|
6
|
+
@service(#{ title: "Test Service" })
|
|
9
7
|
namespace Test;
|
|
10
8
|
union ServerExtensibleEnum {
|
|
11
9
|
string,
|
|
@@ -29,22 +27,18 @@ export async function unionEnumName(
|
|
|
29
27
|
options?: UnionEnumNameOptions,
|
|
30
28
|
): Promise<void> {
|
|
31
29
|
const path = parse("/").expand({});
|
|
32
|
-
|
|
33
30
|
const httpRequestOptions = {
|
|
34
31
|
headers: {},
|
|
35
32
|
body: jsonServerExtensibleEnumToTransportTransform(body),
|
|
36
33
|
};
|
|
37
|
-
|
|
38
34
|
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
39
35
|
|
|
40
36
|
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
41
37
|
options?.operationOptions?.onResponse(response);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
if (+response.status === 204 && !response.body) {
|
|
45
40
|
return;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
throw createRestError(response);
|
|
49
43
|
}
|
|
50
44
|
```
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
This spec defines a server that has a host template and and endpoint to fill it out.
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "Parametrized Endpoint",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "Parametrized Endpoint" })
|
|
11
9
|
@server(
|
|
12
10
|
"{endpoint}/server/path/multiple/{apiVersion}",
|
|
13
11
|
"Test server with path parameters.",
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
This spec defines a server that has a host template and and endpoint to fill it out.
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "Parametrized Endpoint",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "Parametrized Endpoint" })
|
|
11
9
|
@server(
|
|
12
10
|
"{foo}/server/path/multiple",
|
|
13
11
|
"Test server with path parameters.",
|