-
Notifications
You must be signed in to change notification settings - Fork 322
Description
Reported in python support channel:
Expected Behavior:
When an operation is decorated with @Header contentType: "multipart/form-data" and @multipartBody, the SDK should send multipart/form-data requests, regardless of whether individual HttpPart fields are None or empty.
Actual Behavior:
The generated SDK only uses multipart/form-data if at least one file field has a non-None value. Otherwise, it falls back to application/x-www-form-urlencoded, causing 415 Unsupported Media Type errors from the service.
TypeSpec Definition:
// routes.tsp
op transcribe(
@Header contentType: "multipart/form-data",
@multipartBody body: TranscriptionContent,
): TranscriptionResult;
// models.tsp
model TranscriptionContent {
definition: HttpPart; // JSON object
audio?: HttpPart; // Optional audio file
}
Generated Code (Incorrect):
operations.py
@overload
def transcribe(
self,
*,
definition: JSON,
audio: Optional[FileType] = None,
**kwargs: Any
) -> _models.TranscriptionResult: ...
When called with audio=None:
def transcribe(self, *, definition: JSON, audio: Optional[FileType] = None, **kwargs):
# Incorrectly sends as application/x-www-form-urlencoded
# Should use multipart/form-data based on @Header decorator
current work-around: Send definition as a 3-tuple multipart file entry ("definition", (None, definition_json, "application/json")) without including the optional audio field, bypassing the generated transcribe method's multipart preparation that always expects audio data.