-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
<Tabs> | ||
<TabItem value="typespec" label="TypeSpec" default> | ||
|
||
```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; | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="python" label="Python"> | ||
|
||
```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: | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="csharp" label="CSharp"> | ||
|
||
```csharp | ||
|
||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="typescript" label="Typescript"> | ||
|
||
```typescript | ||
|
||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="java" label="Java"> | ||
|
||
```java | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
## 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. | ||
|
||
<Tabs> | ||
<TabItem value="typespec" label="TypeSpec" default> | ||
|
||
```typespec | ||
model Address { | ||
city: string; | ||
} | ||
model MultipartRequest { | ||
id: HttpPart<string>; | ||
address: HttpPart<Address>; | ||
profileImage: HttpPart<File>; | ||
previousAddresses: HttpPart<Address[]>; | ||
pictures: HttpPart<File>[]; | ||
} | ||
@post | ||
op upload(@header contentType: "multipart/form-data", @multipartBody body: MultipartRequest): NoContentResponse; | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="python" label="Python"> | ||
|
||
```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: | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="csharp" label="CSharp"> | ||
|
||
```csharp | ||
|
||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="typescript" label="Typescript"> | ||
|
||
```typescript | ||
|
||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="java" label="Java"> | ||
|
||
```java | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |