[BUG][typescript-axios] Body is sent as {}(empty object) after serializing when body is actually undefined
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
Description
While using a typescript-axios generator generated client the body is sent as {}(empty object) after serializing when the body is undefined. In common.ts file at line 117, while serializing the body:
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
const nonString = typeof value !== 'string';
const needsSerialization = nonString && configuration && configuration.isJsonMime
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? value : {})
: (value || "");
}
here in the last third line, we can see that it makes the body as {} when it's undefined. In Typescript-Fetch this issue is fixed it sends body as undefined if it's undefined and body as null if it's null.
openapi-generator version
version 6.0.1 and below
Suggest a fix
It can be fixed by replacing line number 117 of common.ts file
from ? JSON.stringify(value !== undefined ? value : {})
to ? JSON.stringify(value)
I have the same issue
you can skip serialization, set Content-Type in header, but it doesn't work in real request , still empty
you can skip serialization, set Content-Type in header, but it doesn't work in real request , still empty
OK, 'Content-Type' + 'FormData' , it's working now:
- set Content-Type'
{ headers: { 'Content-Type': ContentTypeEnum.FORM_DATA } }
2.append file param to formData: const formData = new FormData(); formData.append('file', rawFile);