microsoft / microsoft/typespec

Add support for declaring optional part in the tuple form

Open
#3,645 2 comments 0 reactions 0 assignees View on GitHub
lib:http needs-area triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

According to https://github.com/microsoft/typespec/issues/3046, multipart supports two kind of format:
✅ model format
```
op upload(
@header `content-type`: "multipart/form-data",
@multipartBody body: {
// # String body
fullName: HttpPart,
headShots: HttpPart[]
}
): void;
```
❌ array format:
```
op upload(
@header `content-type`: "multipart/form-data",
@multipartBody body: [
// # String body
HttpPart
]): void;
```

However, with array format, it is hard to declare the part is "optional". I try to add `?` with `HttpPart?` and `HttpPart` but compiler reports error.

I think the following format shall work:
![image](https://github.com/microsoft/typespec/assets/70930885/e6241a66-0032-41b3-ac71-14873009d6f9)
But http parse result is still `optional: false`. I think it is a bug?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.