-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] typescript-fetch casts enum scalar values to Blob #11613
Comments
The same problem happens when I want to send an object as JSON to the backend. Without the SDK I would just |
|
Im having issues with this also. I was able to get it working for my needs with a workaround, but I would much rather this handle it properly and generate the client code cleanly. If anyone is curious, here is the workaround I used. It essentially unravels the Blob wrapper around the enum to get the string value in a middleware. async function ResolveAssetTypeEnumMiddleware(context: RequestContext) {
const { body } = context.init;
if (body && body instanceof FormData) {
const type = body.get("type");
if (type instanceof File) {
const jsonType = await type.text();
const resolvedType = JSON.parse(jsonType);
body.set("type", resolvedType);
}
}
return context;
}
const assetsApi = new AssetsApi(tokenApiConfig).withPreMiddleware(
ResolveAssetTypeEnumMiddleware
); |
@zmrl010 Thanks! BTW, if you have multiple types to handle: async function resolveEnumTypes(context: RequestContext) {
const { body } = context.init;
if (body && body instanceof FormData) {
for (const key of ["amazing_type1", "amazing_type2"]) {
const type = body.get(key);
if (type instanceof File) {
const jsonType = await type.text();
const resolvedType = JSON.parse(jsonType);
body.set(key, resolvedType);
}
}
}
return context;
} |
Confirmed this with 6.2.1 have the same issue Request Interface
implementation
swagger
|
Same problem with multipart/form-data openapi-generator-cli version 6.5.0 swagger.json
generated code:
Fix it please |
Also hoping in. How it is currently done, requests fail on mobile devices using React-Native with fetch. Treating enum values as scalar values fixes it. if (requestParameters.type !== undefined) {
formParams.append('type', requestParameters.type as any);
} |
Description
Currently, when the OpenAPI declaration file is being generated, the open-api-generator treats enum values (which are scalars, such as string and numbers) as complex, object-like structures in insists of casting them to Blob as a part of the
multipart/form-data
request payload.openapi-generator version
5.3.1
OpenAPI declaration file content or url
This is the output from the FASTApi application, an endpoint expecting a
multipart/form-data
request with both file and some "metadata" describing this file.Generation Details
The command-line script to run the docker container with open-api generator
The output of the generated code:
Steps to reproduce
Create an appropriate data structure in your code so that it leads to the OpenAPI declaration output as shown above
Suggest a fix
Treat enum value as a primitive and allow it to be directly taken as an argument for formData in
multipart/form-data
requests.The text was updated successfully, but these errors were encountered: