Bug Report Checklist
Description
Complex types are incorrectly serialized as the string [object Object] when they are used as a part in a multipart/form-data request body.
openapi-generator version
4.3.1 / 5.0.0-beta2 / 2ec96f7
OpenAPI declaration file content or url
---
openapi: "3.0.0"
info:
title: Bug test case
version: "1.0"
paths:
/example:
post:
operationId: exampleOperation
requestBody:
content:
multipart/form-data:
schema:
properties:
complexvalue:
properties:
value1:
type: number
value2:
type: string
type: object
type: object
responses:
"201":
description: Created
Generation Details
java -jar openapi-generator-cli.jar generate -g typescript-fetch -i testcase.yml -o generated
Steps to reproduce
Related issues/PRs
Suggest a fix
The generated model (models/ExampleComplexvalue.ts, 21-34) is correct:
export interface ExampleComplexvalue {
/**
*
* @type {number}
* @memberof ExampleComplexvalue
*/
value1?: number;
/**
*
* @type {string}
* @memberof ExampleComplexvalue
*/
value2?: string;
}
However, the generated serialization code (apis/DefaultApi.ts, 53-55) is incorrect:
if (requestParameters.complexvalue !== undefined) {
formParams.append('complexvalue', requestParameters.complexvalue as any);
}
As you can see from the documentation of FormData.append(), all other types than Blob or subclasses will be converted into string:
value
The field's value. This can be a USVString or Blob (including subclasses such as File). If none of these are specified the value is converted to a string.
The correct way to serialize this would be to convert the complex type into a JSON Blob before serializing it:
new Blob([JSON.stringify(requestParameters.complexvalue)], { type: "application/json", }
This should not be done to simple string types though, since they need to be appended as-is and should have the default text/plain Content-Type.
Bug Report Checklist
Description
Complex types are incorrectly serialized as the string
[object Object]when they are used as a part in amultipart/form-datarequest body.openapi-generator version
4.3.1 / 5.0.0-beta2 / 2ec96f7
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate -g typescript-fetch -i testcase.yml -o generatedSteps to reproduce
Related issues/PRs
Suggest a fix
The generated model (
models/ExampleComplexvalue.ts, 21-34) is correct:However, the generated serialization code (
apis/DefaultApi.ts, 53-55) is incorrect:As you can see from the documentation of FormData.append(), all other types than Blob or subclasses will be converted into string:
The correct way to serialize this would be to convert the complex type into a JSON Blob before serializing it:
This should not be done to simple string types though, since they need to be appended as-is and should have the default
text/plainContent-Type.