-
-
Notifications
You must be signed in to change notification settings - Fork 529
Closed as not planned
Closed as not planned
Copy link
Labels
workaroundA workaround has been providedA workaround has been provided
Description
What are the steps to reproduce this issue?
Given the following schema, generate the client types
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
/test:
post:
tags:
- hello-controller
operationId: saveDocu2ment
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
personDTO:
$ref: '#/components/schemas/PersonDTO'
file:
type: string
format: binary
encoding:
personDTO:
contentType: application/json
responses:
'200':
description: OK
components:
schemas:
PersonDTO:
type: object
properties:
email:
type: string
firstName:
type: string
lastName:
type: stringWhat happens?
For the upload function using client: "react-query", this is what's generated
export const useUploadFilesHook = () => {
const uploadFiles = useCustomInstance<UploadFiles200>();
return (uploadFilesBody: UploadFilesBody) => {
const formData = new FormData();
formData.append("personDTO", JSON.stringify(uploadFilesBody.personDTO));
formData.append("file", uploadFilesBody.file);
return uploadFiles({
url: "/test",
method: "post",
headers: { "Content-Type": "multipart/form-data" },
data: formData,
});
};
};However, this is broken and will result in the following error
{
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/octet-stream' not supported"
}The reason for this, is that the personDTO field is expected to be encoded in application/json and not in the default application/octet-stream.
What were you expecting to happen?
Instead, this is what works if I manually update the file
export const useUploadFilesHook = () => {
const uploadFiles = useCustomInstance<UploadFiles200>();
return (uploadFilesBody: UploadFilesBody) => {
const formData = new FormData();
formData.append("personDTO", new Blob([JSON.stringify(uploadFilesBody.personDTO)], { type: "application/json" }));
formData.append("file", uploadFilesBody.file);
return uploadFiles({
url: "/test",
method: "post",
headers: { "Content-Type": "multipart/form-data" },
data: formData,
});
};
};Any other comments?
This issue is very closely related.
What versions are you using?
Package Version: ^6.15.0
Hypenate
Metadata
Metadata
Assignees
Labels
workaroundA workaround has been providedA workaround has been provided