@typespec/http-client-js 0.2.0-dev.8 → 0.2.0
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/CHANGELOG.md +21 -0
- package/dist/src/components/output.d.ts.map +1 -1
- package/dist/src/components/output.js +0 -2
- 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 +20 -13
- package/dist/src/components/serializers.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/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -11
- package/src/components/output.tsx +1 -2
- package/src/components/serializers.tsx +14 -6
- package/src/components/transforms/multipart/simple-part-transform.tsx +12 -6
- package/test/e2e/http/payload/multipart/main.test.ts +20 -24
- package/test/e2e/http/type/property/additional-properties/spreads.test.ts +0 -27
- package/test/scenarios/auth/basic_auth.md +1 -3
- package/test/scenarios/auth/bearer.md +1 -3
- package/test/scenarios/auth/client_parameters.md +1 -3
- package/test/scenarios/auth/client_structure.md +1 -3
- package/test/scenarios/auth/key_credential.md +1 -3
- package/test/scenarios/auth/sub_client_override.md +1 -3
- package/test/scenarios/client/client_context.md +1 -3
- package/test/scenarios/client/dotted_namespace.md +1 -3
- package/test/scenarios/client/nested_client.md +1 -3
- package/test/scenarios/client/wrapping_namespace.md +1 -3
- package/test/scenarios/http-operations/basic-request.md +3 -9
- package/test/scenarios/http-operations/basic-response.md +4 -12
- package/test/scenarios/http-operations/path-parameter-in-model.md +1 -3
- package/test/scenarios/http-operations/path-parameter.md +1 -3
- package/test/scenarios/http-operations/scalar-payload.md +1 -3
- package/test/scenarios/http-operations/with-parameters.md +1 -3
- package/test/scenarios/multipart/anonymous_part.md +1 -1
- package/test/scenarios/multipart/file_content_type.md +15 -0
- package/test/scenarios/multipart/non-string-float.md +50 -0
- package/test/scenarios/serializers/polymorphic_single_level_inheritance.md +1 -3
- package/test/scenarios/serializers/spread.md +1 -3
- package/test/scenarios/serializers/string_union.md +1 -3
- package/test/scenarios/server/multiple-parameters.md +1 -3
- package/test/scenarios/server/parametrized-endpoint.md +1 -3
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http-client-js",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"homepage": "https://typespec.io",
|
|
6
|
+
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
|
|
5
7
|
"exports": {
|
|
6
8
|
".": {
|
|
7
9
|
"types": "./dist/src/index.d.ts",
|
|
@@ -24,16 +26,16 @@
|
|
|
24
26
|
"license": "MIT",
|
|
25
27
|
"description": "TypeSpec library for emitting Http Client libraries for JavaScript/TypeScript",
|
|
26
28
|
"peerDependencies": {
|
|
27
|
-
"@typespec/compiler": "^0.
|
|
28
|
-
"@typespec/
|
|
29
|
-
"@typespec/
|
|
30
|
-
"@typespec/http-client": "^0.2.0 || >=0.3.0-dev <0.3.0",
|
|
31
|
-
"@typespec/rest": "^0.66.0 || >=0.67.0-dev <0.67.0"
|
|
29
|
+
"@typespec/compiler": "^0.67.0",
|
|
30
|
+
"@typespec/http": "^0.67.0",
|
|
31
|
+
"@typespec/rest": "^0.67.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@alloy-js/core": "^0.6.0",
|
|
35
35
|
"@alloy-js/typescript": "^0.6.0",
|
|
36
|
-
"prettier": "~3.5.3"
|
|
36
|
+
"prettier": "~3.5.3",
|
|
37
|
+
"@typespec/emitter-framework": "^0.3.0",
|
|
38
|
+
"@typespec/http-client": "^0.3.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@alloy-js/babel-preset": "^0.2.0",
|
|
@@ -41,10 +43,7 @@
|
|
|
41
43
|
"@babel/core": "^7.26.9",
|
|
42
44
|
"@rollup/plugin-babel": "^6.0.4",
|
|
43
45
|
"@types/yargs": "~17.0.33",
|
|
44
|
-
"@typespec/http-specs": "^0.1.0-alpha.11 || >=0.1.0-alpha.12-dev <0.1.0-alpha.12",
|
|
45
|
-
"@typespec/spector": "^0.1.0-alpha.8 || >=0.1.0-alpha.9-dev <0.1.0-alpha.9",
|
|
46
46
|
"@typespec/ts-http-runtime": "0.1.0",
|
|
47
|
-
"@typespec/versioning": "^0.66.0 || >=0.67.0-dev <0.67.0",
|
|
48
47
|
"@vitest/ui": "^3.0.7",
|
|
49
48
|
"picocolors": "~1.1.1",
|
|
50
49
|
"concurrently": "^9.1.2",
|
|
@@ -59,7 +58,11 @@
|
|
|
59
58
|
"vitest": "^3.0.7",
|
|
60
59
|
"yargs": "~17.7.2",
|
|
61
60
|
"change-case": "~5.4.4",
|
|
62
|
-
"@typespec/
|
|
61
|
+
"@typespec/http": "^0.67.0",
|
|
62
|
+
"@typespec/http-specs": "^0.1.0-alpha.13",
|
|
63
|
+
"@typespec/spector": "^0.1.0-alpha.9",
|
|
64
|
+
"@typespec/tspd": "^0.46.0",
|
|
65
|
+
"@typespec/versioning": "^0.67.0"
|
|
63
66
|
},
|
|
64
67
|
"scripts": {
|
|
65
68
|
"build-src": "babel src -d dist/src --extensions .ts,.tsx",
|
|
@@ -2,7 +2,6 @@ import * as ay from "@alloy-js/core";
|
|
|
2
2
|
import * as ts from "@alloy-js/typescript";
|
|
3
3
|
import { TransformNamePolicyContext } from "@typespec/emitter-framework";
|
|
4
4
|
import { ClientLibrary } from "@typespec/http-client/components";
|
|
5
|
-
import { httpParamsMutator } from "../utils/operations.js";
|
|
6
5
|
import { EncodingProvider } from "./encoding-provider.jsx";
|
|
7
6
|
import { httpRuntimeTemplateLib } from "./external-packages/ts-http-runtime.js";
|
|
8
7
|
import { uriTemplateLib } from "./external-packages/uri-template.js";
|
|
@@ -17,7 +16,7 @@ export function Output(props: OutputProps) {
|
|
|
17
16
|
const defaultTransformNamePolicy = createTransformNamePolicy();
|
|
18
17
|
return (
|
|
19
18
|
<ay.Output namePolicy={tsNamePolicy} externals={[uriTemplateLib, httpRuntimeTemplateLib]}>
|
|
20
|
-
<ClientLibrary
|
|
19
|
+
<ClientLibrary>
|
|
21
20
|
<TransformNamePolicyContext.Provider value={defaultTransformNamePolicy}>
|
|
22
21
|
<EncodingProvider>{props.children}</EncodingProvider>
|
|
23
22
|
</TransformNamePolicyContext.Provider>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ts from "@alloy-js/typescript";
|
|
2
|
+
import { $ } from "@typespec/compiler/experimental/typekit";
|
|
2
3
|
import {
|
|
3
4
|
DateDeserializer,
|
|
4
5
|
DateRfc3339Serializer,
|
|
@@ -40,12 +41,19 @@ export function ModelSerializers(props: ModelSerializersProps) {
|
|
|
40
41
|
))}
|
|
41
42
|
{dataTypes
|
|
42
43
|
.filter((m) => m.kind === "Model" || m.kind === "Union")
|
|
43
|
-
.map((type) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
.map((type) => {
|
|
45
|
+
let bytesDefaultEncoding: "base64" | "none" = "base64";
|
|
46
|
+
if ($.model.is(type) && type.baseModel && $.model.isHttpFile(type.baseModel)) {
|
|
47
|
+
bytesDefaultEncoding = "none";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<EncodingProvider defaults={{ bytes: bytesDefaultEncoding }}>
|
|
52
|
+
<JsonTransformDeclaration type={type} target="transport" />
|
|
53
|
+
<JsonTransformDeclaration type={type} target="application" />
|
|
54
|
+
</EncodingProvider>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
49
57
|
</ts.SourceFile>
|
|
50
58
|
);
|
|
51
59
|
}
|
|
@@ -16,6 +16,11 @@ export function SimplePartTransform(props: SimplePartTransformProps) {
|
|
|
16
16
|
const partName = ts.ValueExpression({ jsValue: props.part.name });
|
|
17
17
|
const partContentType = props.part.body.contentTypes[0] ?? "application/json";
|
|
18
18
|
const partRef = getPartRef(props.itemRef, applicationName);
|
|
19
|
+
let bodyRef = ay.code`${partRef}`;
|
|
20
|
+
|
|
21
|
+
if (props.part.body.property) {
|
|
22
|
+
bodyRef = ay.code`${partRef}.${props.part.body.property.name}`;
|
|
23
|
+
}
|
|
19
24
|
|
|
20
25
|
if (!partContentType.startsWith("application/json")) {
|
|
21
26
|
reportDiagnostic($.program, {
|
|
@@ -27,12 +32,13 @@ export function SimplePartTransform(props: SimplePartTransformProps) {
|
|
|
27
32
|
|
|
28
33
|
return (
|
|
29
34
|
<ts.ObjectExpression>
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
<ay.List comma line>
|
|
36
|
+
<ts.ObjectProperty name="name" jsValue={partName} />
|
|
37
|
+
<ts.ObjectProperty
|
|
38
|
+
name="body"
|
|
39
|
+
value={<JsonTransform itemRef={bodyRef} target="transport" type={props.part.body.type} />}
|
|
40
|
+
/>
|
|
41
|
+
</ay.List>
|
|
36
42
|
</ts.ObjectExpression>
|
|
37
43
|
);
|
|
38
44
|
}
|
|
@@ -4,30 +4,26 @@ import { fileURLToPath } from "url";
|
|
|
4
4
|
import { beforeEach, describe, it } from "vitest";
|
|
5
5
|
import { FormDataClient, HttpPartsClient } from "../../../generated/payload/multipart/src/index.js";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
|
|
10
|
+
const jpegImagePath = resolve(__dirname, "../../../assets/image.jpg");
|
|
11
|
+
const jpegBuffer = await readFile(jpegImagePath);
|
|
12
|
+
const jpegContents = new Uint8Array(jpegBuffer);
|
|
13
|
+
|
|
14
|
+
const pngImagePath = resolve(__dirname, "../../../assets/image.png");
|
|
15
|
+
const pngBuffer = await readFile(pngImagePath);
|
|
16
|
+
const pngContents = new Uint8Array(pngBuffer);
|
|
12
17
|
|
|
18
|
+
describe("Payload.MultiPart", () => {
|
|
19
|
+
// Skipping as implicit multipart is going to be deprecated in TypeSpec
|
|
13
20
|
describe.skip("FormDataClient", () => {
|
|
14
21
|
const client = new FormDataClient({
|
|
15
22
|
allowInsecureConnection: true,
|
|
16
23
|
retryOptions: { maxRetries: 1 },
|
|
17
24
|
});
|
|
18
25
|
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
__filename = fileURLToPath(import.meta.url);
|
|
21
|
-
__dirname = dirname(__filename);
|
|
22
|
-
|
|
23
|
-
const jpegImagePath = resolve(__dirname, "../../../assets/image.jpg");
|
|
24
|
-
const jpegBuffer = await readFile(jpegImagePath);
|
|
25
|
-
jpegContents = new Uint8Array(jpegBuffer);
|
|
26
|
-
|
|
27
|
-
const pngImagePath = resolve(__dirname, "../../../assets/image.png");
|
|
28
|
-
const pngBuffer = await readFile(pngImagePath);
|
|
29
|
-
pngContents = new Uint8Array(pngBuffer);
|
|
30
|
-
});
|
|
26
|
+
beforeEach(async () => {});
|
|
31
27
|
|
|
32
28
|
it("should send mixed parts with multipart/form-data", async () => {
|
|
33
29
|
await client.basic({
|
|
@@ -82,7 +78,7 @@ describe("Payload.MultiPart", () => {
|
|
|
82
78
|
});
|
|
83
79
|
});
|
|
84
80
|
|
|
85
|
-
describe
|
|
81
|
+
describe("FormDataClient.HttpParts.ContentType", () => {
|
|
86
82
|
const client = new HttpPartsClient({
|
|
87
83
|
allowInsecureConnection: true,
|
|
88
84
|
retryOptions: { maxRetries: 1 },
|
|
@@ -93,7 +89,7 @@ describe("Payload.MultiPart", () => {
|
|
|
93
89
|
profileImage: {
|
|
94
90
|
contents: jpegContents,
|
|
95
91
|
contentType: "image/jpg",
|
|
96
|
-
filename: "
|
|
92
|
+
filename: "hello.jpg",
|
|
97
93
|
},
|
|
98
94
|
});
|
|
99
95
|
});
|
|
@@ -102,8 +98,8 @@ describe("Payload.MultiPart", () => {
|
|
|
102
98
|
await client.contentTypeClient.requiredContentType({
|
|
103
99
|
profileImage: {
|
|
104
100
|
contents: jpegContents,
|
|
105
|
-
contentType: "
|
|
106
|
-
filename: "
|
|
101
|
+
contentType: "application/octet-stream",
|
|
102
|
+
filename: "hello.jpg",
|
|
107
103
|
},
|
|
108
104
|
});
|
|
109
105
|
});
|
|
@@ -112,14 +108,14 @@ describe("Payload.MultiPart", () => {
|
|
|
112
108
|
await client.contentTypeClient.optionalContentType({
|
|
113
109
|
profileImage: {
|
|
114
110
|
contents: jpegContents,
|
|
115
|
-
filename: "
|
|
111
|
+
filename: "hello.jpg",
|
|
116
112
|
},
|
|
117
113
|
});
|
|
118
114
|
});
|
|
119
115
|
});
|
|
120
116
|
|
|
121
117
|
describe("FormDataClient.HttpParts", () => {
|
|
122
|
-
it
|
|
118
|
+
it("should send json array and file array", async () => {
|
|
123
119
|
const client = new HttpPartsClient({
|
|
124
120
|
allowInsecureConnection: true,
|
|
125
121
|
retryOptions: {
|
|
@@ -146,7 +142,7 @@ describe("Payload.MultiPart", () => {
|
|
|
146
142
|
});
|
|
147
143
|
|
|
148
144
|
describe("FormDataClient.HttpParts.NonString", () => {
|
|
149
|
-
it
|
|
145
|
+
it("should handle non-string float", async () => {
|
|
150
146
|
const client = new HttpPartsClient({
|
|
151
147
|
allowInsecureConnection: true,
|
|
152
148
|
retryOptions: {
|
|
@@ -20,8 +20,6 @@ import {
|
|
|
20
20
|
SpreadFloatClient,
|
|
21
21
|
SpreadModelArrayClient,
|
|
22
22
|
SpreadModelClient,
|
|
23
|
-
SpreadRecordDiscriminatedUnionClient,
|
|
24
|
-
SpreadRecordForDiscriminatedUnion,
|
|
25
23
|
SpreadRecordForNonDiscriminatedUnion,
|
|
26
24
|
SpreadRecordForNonDiscriminatedUnion2,
|
|
27
25
|
SpreadRecordForNonDiscriminatedUnion3,
|
|
@@ -377,31 +375,6 @@ describe("Missing AdditionalProperties Endpoints", () => {
|
|
|
377
375
|
});
|
|
378
376
|
});
|
|
379
377
|
|
|
380
|
-
/**
|
|
381
|
-
* Deprecated @discriminator in unions
|
|
382
|
-
*/
|
|
383
|
-
describe.skip("SpreadRecordDiscriminatedUnion", () => {
|
|
384
|
-
const client = new SpreadRecordDiscriminatedUnionClient(clientOptions);
|
|
385
|
-
const expected: SpreadRecordForDiscriminatedUnion = {
|
|
386
|
-
name: "abc",
|
|
387
|
-
additionalProperties: {
|
|
388
|
-
prop1: { kind: "kind0", fooProp: "abc" },
|
|
389
|
-
prop2: {
|
|
390
|
-
kind: "kind1",
|
|
391
|
-
start: new Date("2021-01-01T00:00:00Z"),
|
|
392
|
-
end: new Date("2021-01-02T00:00:00Z"),
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
};
|
|
396
|
-
it("GET returns the expected response", async () => {
|
|
397
|
-
const response = await client.get();
|
|
398
|
-
expect(response).toEqual(expected);
|
|
399
|
-
});
|
|
400
|
-
it("PUT accepts the expected input", async () => {
|
|
401
|
-
await client.put(expected);
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
378
|
describe("SpreadRecordNonDiscriminatedUnion", () => {
|
|
406
379
|
const client = new SpreadRecordNonDiscriminatedUnionClient(clientOptions);
|
|
407
380
|
const expected: SpreadRecordForNonDiscriminatedUnion = {
|
|
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a basic authentication scheme co
|
|
|
7
7
|
The spec contains a simple service with a Bearer authentication scheme
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Test Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Test Service" })
|
|
13
11
|
@useAuth(BasicAuth)
|
|
14
12
|
namespace Test;
|
|
15
13
|
|
|
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a simple bearer authentication s
|
|
|
7
7
|
The spec contains a simple service with a Bearer authentication scheme
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Test Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Test Service" })
|
|
13
11
|
@useAuth(BearerAuth)
|
|
14
12
|
namespace Test;
|
|
15
13
|
|
|
@@ -7,9 +7,7 @@ This test validates that the emitter can generate the correct client signature w
|
|
|
7
7
|
The spec contains 2 Schemas Bearer and ApiKey
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Test Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Test Service" })
|
|
13
11
|
@useAuth(BearerAuth | ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
|
|
14
12
|
namespace Test;
|
|
15
13
|
|
|
@@ -7,9 +7,7 @@ This test validates that the emitter can handle a key auth scheme correctly with
|
|
|
7
7
|
The spec contains a simple service with a ApiKey authentication scheme
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Test Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Test Service" })
|
|
13
11
|
@useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-KEY">)
|
|
14
12
|
namespace Test;
|
|
15
13
|
|
|
@@ -7,9 +7,7 @@ The sub client sets NoAuth to override the auth scheme of the parent
|
|
|
7
7
|
The spec contains a client with BasicAuth and a sub client with no auth
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Test Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Test Service" })
|
|
13
11
|
@useAuth(BasicAuth)
|
|
14
12
|
namespace Test;
|
|
15
13
|
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
A dotted namespace where only the last part has content. The leading namespaces have no operations and a single sub namespace
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "TestService",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "TestService" })
|
|
11
9
|
namespace Foo.Bar.Baz;
|
|
12
10
|
@get op get(): string[];
|
|
13
11
|
```
|
|
@@ -9,9 +9,7 @@ In this scenario the emitter is expected to resolve the root namespace as a clie
|
|
|
9
9
|
A dotted namespace where only the last part has stuff
|
|
10
10
|
|
|
11
11
|
```tsp
|
|
12
|
-
@service({
|
|
13
|
-
title: "TestService",
|
|
14
|
-
})
|
|
12
|
+
@service(#{ title: "TestService" })
|
|
15
13
|
namespace Foo;
|
|
16
14
|
|
|
17
15
|
@route("/bar")
|
|
@@ -5,9 +5,7 @@ This test verifies that a basic `GET` request with no headers, body, or paramete
|
|
|
5
5
|
## TypeSpec
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "Widget Service",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "Widget Service" })
|
|
11
9
|
namespace DemoService;
|
|
12
10
|
|
|
13
11
|
@route("/widgets")
|
|
@@ -46,9 +44,7 @@ This test verifies that a `POST` request with headers, a body, and query paramet
|
|
|
46
44
|
## TypeSpec
|
|
47
45
|
|
|
48
46
|
```tsp
|
|
49
|
-
@service({
|
|
50
|
-
title: "Widget Service",
|
|
51
|
-
})
|
|
47
|
+
@service(#{ title: "Widget Service" })
|
|
52
48
|
namespace DemoService;
|
|
53
49
|
|
|
54
50
|
@test
|
|
@@ -110,9 +106,7 @@ This test verifies that a `GET` request with a scalar body is correctly handled.
|
|
|
110
106
|
## TypeSpec
|
|
111
107
|
|
|
112
108
|
```tsp
|
|
113
|
-
@service({
|
|
114
|
-
title: "Widget Service",
|
|
115
|
-
})
|
|
109
|
+
@service(#{ title: "Widget Service" })
|
|
116
110
|
namespace DemoService;
|
|
117
111
|
|
|
118
112
|
@route("/widgets")
|
|
@@ -5,9 +5,7 @@ This test verifies that a response with status `204` and no body is correctly ha
|
|
|
5
5
|
## **TypeSpec**
|
|
6
6
|
|
|
7
7
|
```tsp
|
|
8
|
-
@service({
|
|
9
|
-
title: "Widget Service",
|
|
10
|
-
})
|
|
8
|
+
@service(#{ title: "Widget Service" })
|
|
11
9
|
namespace DemoService;
|
|
12
10
|
|
|
13
11
|
@route("/widgets")
|
|
@@ -48,9 +46,7 @@ This test verifies that a response with a body containing a `Widget` model is co
|
|
|
48
46
|
## **TypeSpec**
|
|
49
47
|
|
|
50
48
|
```tsp
|
|
51
|
-
@service({
|
|
52
|
-
title: "Widget Service",
|
|
53
|
-
})
|
|
49
|
+
@service(#{ title: "Widget Service" })
|
|
54
50
|
namespace DemoService;
|
|
55
51
|
|
|
56
52
|
@test
|
|
@@ -115,9 +111,7 @@ This test verifies that a response with multiple status codes (`200` and `204`)
|
|
|
115
111
|
## **TypeSpec**
|
|
116
112
|
|
|
117
113
|
```tsp
|
|
118
|
-
@service({
|
|
119
|
-
title: "Widget Service",
|
|
120
|
-
})
|
|
114
|
+
@service(#{ title: "Widget Service" })
|
|
121
115
|
namespace DemoService;
|
|
122
116
|
|
|
123
117
|
@test
|
|
@@ -172,9 +166,7 @@ This test verifies that a response with multiple content types is correctly hand
|
|
|
172
166
|
## **TypeSpec**
|
|
173
167
|
|
|
174
168
|
```tsp
|
|
175
|
-
@service({
|
|
176
|
-
title: "Widget Service",
|
|
177
|
-
})
|
|
169
|
+
@service(#{ title: "Widget Service" })
|
|
178
170
|
namespace DemoService;
|
|
179
171
|
|
|
180
172
|
model Widget {
|
|
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter as a property of the input
|
|
|
7
7
|
The path parameter is a property of a spread model input in the operation signature
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Widget Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Widget Service" })
|
|
13
11
|
namespace DemoService;
|
|
14
12
|
|
|
15
13
|
model ReadParams {
|
|
@@ -7,9 +7,7 @@ A request that sends a request with a path parameter directly on the operation s
|
|
|
7
7
|
The path parameter is a positional parameter in the operation signature
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Widget Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Widget Service" })
|
|
13
11
|
namespace DemoService;
|
|
14
12
|
|
|
15
13
|
@route("/widgets")
|
|
@@ -7,9 +7,7 @@ A request that sends a body payload of scalar type
|
|
|
7
7
|
The body is modeled as an explicit body property of type int32
|
|
8
8
|
|
|
9
9
|
```tsp
|
|
10
|
-
@service({
|
|
11
|
-
title: "Widget Service",
|
|
12
|
-
})
|
|
10
|
+
@service(#{ title: "Widget Service" })
|
|
13
11
|
namespace DemoService;
|
|
14
12
|
|
|
15
13
|
@route("/widgets")
|
|
@@ -60,3 +60,18 @@ export function jsonFileWithHttpPartSpecificContentTypeRequestToApplicationTrans
|
|
|
60
60
|
}!;
|
|
61
61
|
}
|
|
62
62
|
```
|
|
63
|
+
|
|
64
|
+
```ts src/models/serializers.ts function jsonFileSpecificContentTypeToApplicationTransform
|
|
65
|
+
export function jsonFileSpecificContentTypeToApplicationTransform(
|
|
66
|
+
input_?: any,
|
|
67
|
+
): FileSpecificContentType {
|
|
68
|
+
if (!input_) {
|
|
69
|
+
return input_ as any;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
filename: input_.filename,
|
|
73
|
+
contentType: input_.contentType,
|
|
74
|
+
contents: input_.contents,
|
|
75
|
+
}!;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Tests content-type: multipart/form-data for non string
|
|
2
|
+
|
|
3
|
+
## Spec
|
|
4
|
+
|
|
5
|
+
```tsp
|
|
6
|
+
namespace Test;
|
|
7
|
+
@post
|
|
8
|
+
@route("/non-string-float")
|
|
9
|
+
op float(
|
|
10
|
+
@header contentType: "multipart/form-data",
|
|
11
|
+
@multipartBody body: {
|
|
12
|
+
temperature: HttpPart<{
|
|
13
|
+
@body body: float64;
|
|
14
|
+
@header contentType: "text/plain";
|
|
15
|
+
}>;
|
|
16
|
+
},
|
|
17
|
+
): NoContentResponse;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Operation
|
|
21
|
+
|
|
22
|
+
```ts src/api/testClientOperations.ts function float
|
|
23
|
+
export async function float(
|
|
24
|
+
client: TestClientContext,
|
|
25
|
+
body: { temperature: { body: number; contentType: "text/plain" } },
|
|
26
|
+
options?: FloatOptions,
|
|
27
|
+
): Promise<void> {
|
|
28
|
+
const path = parse("/non-string-float").expand({});
|
|
29
|
+
const httpRequestOptions = {
|
|
30
|
+
headers: {
|
|
31
|
+
"content-type": options?.contentType ?? "multipart/form-data",
|
|
32
|
+
},
|
|
33
|
+
body: [
|
|
34
|
+
{
|
|
35
|
+
name: "temperature",
|
|
36
|
+
body: body.temperature.body,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const response = await client.pathUnchecked(path).post(httpRequestOptions);
|
|
41
|
+
|
|
42
|
+
if (typeof options?.operationOptions?.onResponse === "function") {
|
|
43
|
+
options?.operationOptions?.onResponse(response);
|
|
44
|
+
}
|
|
45
|
+
if (+response.status === 204 && !response.body) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw createRestError(response);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
@@ -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.")
|
|
@@ -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.",
|