From e7c8ca31df777c2cb4bbc6857043bd8530a328a0 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 27 Aug 2024 15:52:13 +0800 Subject: [PATCH 1/3] multipart doc --- docs/howtos/Client Generation/12multipart.mdx | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 docs/howtos/Client Generation/12multipart.mdx diff --git a/docs/howtos/Client Generation/12multipart.mdx b/docs/howtos/Client Generation/12multipart.mdx new file mode 100644 index 0000000000..3b84c441b5 --- /dev/null +++ b/docs/howtos/Client Generation/12multipart.mdx @@ -0,0 +1,138 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Multipart + +This doc details what emitters will generate for multipart request. + +## Common multipart request + +When content-type of operation is "multipart/form-data", the body payload is multipart payload. + + + + +```typespec +model Address { + city: string; +} +model MultipartRequest { + id: string; + address: Address; + profileImage: bytes; + pictures: bytes[]; +} + +@post +op upload(@header contentType: "multipart/form-data", @body body: MultipartRequest): NoContentResponse; +``` + + + + + +```python +class MultipartRequest: + id: str = rest_field() + address: "Address" = rest_field() + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) + +def upload( + self, body: Union[_models.MultipartRequest, JSON], **kwargs: Any +) -> None: +``` + + + + + +```csharp + +``` + + + + + +```typescript + +``` + + + + + +```java +``` + + + + + +## Multipart request with `@multipartBody` + +With `@multipartBody`, typespec author could define part of multipart request with more detailed info. +For example, typespec author could use `File` model predefined in `@typespec/http` to declare the requiredness of filename and +contentType. + + + + +```typespec +model Address { + city: string; +} +model MultipartRequest { + id: HttpPart; + address: HttpPart
; + profileImage: HttpPart; + previousAddresses: HttpPart; + pictures: HttpPart[]; +} + +@post +op upload(@header contentType: "multipart/form-data", @multipartBody body: MultipartRequest): NoContentResponse; +``` + + + + + +```python +class MultipartRequest: + id: str = rest_field() + address: "Address" = rest_field() + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) + +def upload( + self, body: Union[_models.MultipartRequest, JSON], **kwargs: Any +) -> None: +``` + + + + + +```csharp + +``` + + + + + +```typescript + +``` + + + + + +```java +``` + + + From 9dd7292765d85a9164b099c96ad02649238bedb2 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Mon, 2 Sep 2024 13:27:35 +0800 Subject: [PATCH 2/3] multipart docs java (#1456) --- docs/howtos/Client Generation/12multipart.mdx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/howtos/Client Generation/12multipart.mdx b/docs/howtos/Client Generation/12multipart.mdx index 3b84c441b5..2b7127fce6 100644 --- a/docs/howtos/Client Generation/12multipart.mdx +++ b/docs/howtos/Client Generation/12multipart.mdx @@ -64,6 +64,14 @@ def upload( ```java +// Model class +@Immutable +public final class MultipartRequest { + public MultipartRequest(String id, Address address, ProfileImageFileDetails profileImage, List pictures); +} + +// Client API +public void upload(MultipartRequest body); ``` @@ -132,6 +140,14 @@ def upload( ```java +// Model class +@Immutable +public final class MultipartRequest { + public MultipartRequest(String id, Address address, FileDetails profileImage, List
previousAddresses, List pictures); +} + +// Client API +public void upload(MultipartRequest body); ``` From 6604b07162db8eacb59268291d7bc901468245e6 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:08:36 +0800 Subject: [PATCH 3/3] update doc --- docs/howtos/Client Generation/12multipart.mdx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/howtos/Client Generation/12multipart.mdx b/docs/howtos/Client Generation/12multipart.mdx index 2b7127fce6..ff4491ae37 100644 --- a/docs/howtos/Client Generation/12multipart.mdx +++ b/docs/howtos/Client Generation/12multipart.mdx @@ -5,7 +5,7 @@ import TabItem from "@theme/TabItem"; This doc details what emitters will generate for multipart request. -## Common multipart request +## Common multipart request When content-type of operation is "multipart/form-data", the body payload is multipart payload. @@ -24,7 +24,10 @@ model MultipartRequest { } @post -op upload(@header contentType: "multipart/form-data", @body body: MultipartRequest): NoContentResponse; +op upload( + @header contentType: "multipart/form-data", + @body body: MultipartRequest, +): NoContentResponse; ``` @@ -77,11 +80,10 @@ public void upload(MultipartRequest body); - ## Multipart request with `@multipartBody` -With `@multipartBody`, typespec author could define part of multipart request with more detailed info. -For example, typespec author could use `File` model predefined in `@typespec/http` to declare the requiredness of filename and +With `@multipartBody`, typespec author could define part of multipart request with more detailed info. +For example, typespec author could use `File` model predefined in `@typespec/http` to declare the requiredness of filename and contentType. @@ -100,7 +102,10 @@ model MultipartRequest { } @post -op upload(@header contentType: "multipart/form-data", @multipartBody body: MultipartRequest): NoContentResponse; +op upload( + @header contentType: "multipart/form-data", + @multipartBody body: MultipartRequest, +): NoContentResponse; ```