BUG [JAVA] Generated java client code from openapi-generator-maven-plugin using okhttp-gson library failing to serialize RequestBody with contentType text/plain
Created by: prkumarm
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generated java client code from openapi-generator-maven-plugin using okhttp-gson library failing to serialize RequestBody with contentType text/plain.
When using httpok library(okhttp-gson) openapi-generator throws ApiException with message "Content type text/plain is not supported" for contentType text/plain.
I see below related mustache template code in serialize(Object obj, String contentType) method in ApiClient.mustache https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache
Is this a expected behavior? if so, what is the work around to serialize RequestBody of type text/plain
openapi-generator version
5.1.0
OpenApi generator dependency org.openapitools openapi-generator-maven-plugin 4.3.1
okhttp dependency - com.squareup.okhttp3 okhttp
OpenAPI declaration file content or url
N/A
Generation Details
Please refer steps defined below in "Steps to reproduce" section
Steps to reproduce
Step1 - Springfox generated contract with contentType text/plain
"/endPoint" : { "post" : { "tags" : [ "controller" ], "summary" : "summary", "operationId" : "operationId", "requestBody" : { "content" : { "application/json" : { "schema" : { "type" : "string" } }, "text/plain" : { "schema" : { "type" : "string" } } } }
Step 2: Generate client code using below Maven plugin for okhttp-gson library, org.openapitools openapi-generator-maven-plugin 4.3.1
Step3. Invoke rest endpoint using generated client code.
Output: Below error message is thrown by the generatened ApiClient class in serialize method.
"Content type text/plain is not supported" for contentType text/plain"
Related issues/PRs
NA
Suggest a fix
NA