Skip to content

Commit 677bcc5

Browse files
authored
Merge branch 'main' into mini-website-refresh
2 parents 4d37722 + 5eafeb1 commit 677bcc5

File tree

10 files changed

+68
-2
lines changed

10 files changed

+68
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
changeKind: deprecation
3+
packages:
4+
- "@typespec/http"
5+
---
6+
7+
Deprecate implicit multipart body
8+
9+
```diff lang=tsp
10+
op upload(
11+
@header contentType: "multipart/form-data",
12+
-@body body: {
13+
+@multipartBody body: {
14+
- name: string;
15+
+ name: HttpPart<string>;
16+
- avatar: bytes;
17+
+ avatar: HttpPart<bytes>;
18+
}
19+
): void;
20+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/http-specs"
6+
---
7+
8+
Suppress implicit multipart deprecation for this release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-js"
5+
---
6+
7+
Add homepage and readme links

packages/http-client-csharp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"author": "Microsoft Corporation",
55
"description": "The typespec library that can be used to generate C# models from a TypeSpec REST protocol binding",
6-
"homepage": "https://github.com/Microsoft/typespec",
6+
"homepage": "https://typespec.io",
77
"readme": "https://github.com/Microsoft/typespec/blob/main/packages/http-client-csharp/readme.md",
88
"license": "MIT",
99
"repository": {

packages/http-client-java/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"TypeSpec"
77
],
88
"author": "Microsoft Corporation",
9-
"homepage": "https://github.com/Microsoft/typespec",
9+
"homepage": "https://typespec.io",
1010
"readme": "https://github.com/Microsoft/typespec/blob/main/packages/http-client-java/README.md",
1111
"repository": {
1212
"type": "git",

packages/http-client-js/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "@typespec/http-client-js",
33
"version": "0.1.0",
44
"type": "module",
5+
"homepage": "https://typespec.io",
6+
"readme": "https://github.com/microsoft/typespec/blob/main/packages/http-client-js/README.md",
57
"scripts": {
68
"build-src": "babel src -d dist/src --extensions .ts,.tsx",
79
"build": "tsc -p . && npm run build-src",

packages/http-specs/specs/payload/multipart/main.tsp

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ namespace FormData {
106106
@route("/mixed-parts")
107107
op basic(
108108
@header contentType: "multipart/form-data",
109+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
109110
@body body: MultiPartRequest,
110111
): NoContentResponse;
111112

@@ -166,6 +167,7 @@ namespace FormData {
166167
@route("/complex-parts")
167168
op fileArrayAndBasic(
168169
@header contentType: "multipart/form-data",
170+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
169171
@body body: ComplexPartsRequest,
170172
): NoContentResponse;
171173

@@ -202,6 +204,7 @@ namespace FormData {
202204
@route("/json-part")
203205
op jsonPart(
204206
@header contentType: "multipart/form-data",
207+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
205208
@body body: JsonPartRequest,
206209
): NoContentResponse;
207210

@@ -241,6 +244,7 @@ namespace FormData {
241244
@route("/binary-array-parts")
242245
op binaryArrayParts(
243246
@header contentType: "multipart/form-data",
247+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
244248
@body body: BinaryArrayPartsRequest,
245249
): NoContentResponse;
246250

@@ -275,6 +279,7 @@ namespace FormData {
275279
@route("/multi-binary-parts")
276280
op multiBinaryParts(
277281
@header contentType: "multipart/form-data",
282+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
278283
@body body: MultiBinaryPartsRequest,
279284
): NoContentResponse;
280285

@@ -304,9 +309,11 @@ namespace FormData {
304309
@route("/check-filename-and-content-type")
305310
op checkFileNameAndContentType(
306311
@header contentType: "multipart/form-data",
312+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
307313
@body body: MultiPartRequest,
308314
): NoContentResponse;
309315

316+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
310317
@scenario
311318
@scenarioDoc("""
312319
Expect request (

packages/http/src/payload.ts

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export function resolveHttpPayload(
6868
const body = diagnostics.pipe(resolveBody(program, type, metadata, visibility, disposition));
6969

7070
if (body) {
71+
if (body.contentTypes.some((x) => x.startsWith("multipart/")) && body.bodyKind === "single") {
72+
diagnostics.add({
73+
severity: "warning",
74+
code: "deprecated",
75+
message: `Deprecated: Implicit multipart is deprecated, use @multipartBody instead with HttpPart`,
76+
target: body.property ?? type,
77+
});
78+
}
7179
if (
7280
body.contentTypes.includes("multipart/form-data") &&
7381
body.bodyKind === "single" &&

packages/http/test/parameters.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ it("emit diagnostic when there are multiple @body param", async () => {
8484

8585
it("emit error if using multipart/form-data contentType parameter with a body not being a model", async () => {
8686
const [_, diagnostics] = await compileOperations(`
87+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
8788
@get op get(@header contentType: "multipart/form-data", @body body: string | int32): string;
8889
`);
8990

packages/openapi3/test/multipart.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ worksFor(["3.0.0", "3.1.0"], ({ openApiFor }) => {
7373
const res = await openApiFor(
7474
`
7575
model Form { @header contentType: "multipart/form-data", name: string, profileImage: bytes }
76+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
7677
op upload(...Form): void;
7778
`,
7879
);
@@ -88,6 +89,7 @@ worksFor(["3.0.0", "3.1.0"], ({ openApiFor }) => {
8889
const res = await openApiFor(
8990
`
9091
union MyUnion {string, int32}
92+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
9193
op upload(@header contentType: "multipart/form-data", profileImage: MyUnion): void;
9294
`,
9395
);
@@ -108,6 +110,7 @@ worksFor(["3.0.0", "3.1.0"], ({ openApiFor }) => {
108110
it("part of type `string` produce `type: string`", async () => {
109111
const res = await openApiFor(
110112
`
113+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
111114
op upload(@header contentType: "multipart/form-data", name: string): void;
112115
`,
113116
);
@@ -128,6 +131,7 @@ worksFor(["3.0.0", "3.1.0"], ({ openApiFor }) => {
128131
it("part of type `object` produce an object", async () => {
129132
const res = await openApiFor(
130133
`
134+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
131135
op upload(@header contentType: "multipart/form-data", address: {city: string, street: string}): void;
132136
`,
133137
);
@@ -164,6 +168,7 @@ worksFor(["3.0.0", "3.1.0"], ({ openApiFor }) => {
164168
165169
interface Files {
166170
@get listFiles(purpose: FilePurpose): string;
171+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
167172
@post uploadFile(@header contentType: "multipart/form-data", purpose: FilePurpose): string;
168173
}
169174
`,
@@ -334,6 +339,7 @@ worksFor(["3.0.0"], ({ openApiFor }) => {
334339
it("part of type `bytes` produce `type: string, format: binary`", async () => {
335340
const res = await openApiFor(
336341
`
342+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
337343
op upload(@header contentType: "multipart/form-data", profileImage: bytes): void;
338344
`,
339345
);
@@ -355,6 +361,7 @@ worksFor(["3.0.0"], ({ openApiFor }) => {
355361
it("part of type union `bytes | {content: bytes}` produce `type: string, format: binary`", async () => {
356362
const res = await openApiFor(
357363
`
364+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
358365
op upload(@header contentType: "multipart/form-data", profileImage: bytes | {content: bytes}): void;
359366
`,
360367
);
@@ -387,6 +394,7 @@ worksFor(["3.0.0"], ({ openApiFor }) => {
387394
it("part of type `bytes[]` produce `type: array, items: {type: string, format: binary}`", async () => {
388395
const res = await openApiFor(
389396
`
397+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
390398
op upload(@header contentType: "multipart/form-data", profileImage: bytes[]): void;
391399
`,
392400
);
@@ -408,6 +416,7 @@ worksFor(["3.0.0"], ({ openApiFor }) => {
408416
it("bytes inside a json part will be treated as base64 encoded by default(same as for a json body)", async () => {
409417
const res = await openApiFor(
410418
`
419+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
411420
op upload(@header contentType: "multipart/form-data", address: {city: string, icon: bytes}): void;
412421
`,
413422
);
@@ -585,6 +594,7 @@ worksFor(["3.1.0"], ({ openApiFor }) => {
585594
it("part of type `bytes` produce `{}`", async () => {
586595
const res = await openApiFor(
587596
`
597+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
588598
op upload(@header contentType: "multipart/form-data", profileImage: bytes): void;
589599
`,
590600
);
@@ -603,6 +613,7 @@ worksFor(["3.1.0"], ({ openApiFor }) => {
603613
it("part of type union `bytes | {content: bytes}` produce `{} | { content: {type: string, contentEncoding: 'base64' }`", async () => {
604614
const res = await openApiFor(
605615
`
616+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
606617
op upload(@header contentType: "multipart/form-data", profileImage: bytes | {content: bytes}): void;
607618
`,
608619
);
@@ -632,6 +643,7 @@ worksFor(["3.1.0"], ({ openApiFor }) => {
632643
it("part of type `bytes[]` produce `type: array, items: {}`", async () => {
633644
const res = await openApiFor(
634645
`
646+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
635647
op upload(@header contentType: "multipart/form-data", profileImage: bytes[]): void;
636648
`,
637649
);
@@ -653,6 +665,7 @@ worksFor(["3.1.0"], ({ openApiFor }) => {
653665
it("bytes inside a json part will be treated as base64 encoded by default(same as for a json body)", async () => {
654666
const res = await openApiFor(
655667
`
668+
#suppress "deprecated" "For testing to migrate for 1.0-rc"
656669
op upload(@header contentType: "multipart/form-data", address: {city: string, icon: bytes}): void;
657670
`,
658671
);

0 commit comments

Comments
 (0)