microsoft / typespec

https://typespec.io/
MIT License
4.25k stars 199 forks source link

[Discussion] Is implicit body permitted in `HttpPart<>` for multipart? #4367

Open msyyc opened 1 week ago

msyyc commented 1 week ago

In design https://github.com/microsoft/typespec/issues/3046, Typespec permit users define explicit body in HttpPart<> like:

model Address {
    city: string;
    country: string;
}
op upload(
  @header `content-type`: "multipart/form-data";
  @multipartBody body: {
    // # String body
    address: HttpPart<@body body: Address; @header MyHeader: string>,
  }
): void;

Shall we permit implicit body in HttpPart<> like:

op upload(
  @header `content-type`: "multipart/form-data";
  @multipartBody body: {
    // # String body
    address: HttpPart<city: string; country: string; @header MyHeader: string>,
  }
): void;

?

PS: I try implicit body in playground. Although compiler doesn't report error, the generated swagger obviously is not right.

cc @bterlson

timotheeguerin commented 1 week ago

I believe so, if you look at openapi3 emitter it is emitted correctly playground

timotheeguerin commented 1 week ago

actually so is autorest swagger 2.0 doesn't support json parts so it just treat them as string. So just missing a warning I think