openapi-generator
openapi-generator copied to clipboard
[BUG][java-vertx-web] Generated code does not compile for text/plain request bodies
Description
Generated code does not compile for text/plain request bodies.
There is a redeclaration like so:
RequestParameter body = requestParameters.body();
String body = body != null ? DatabindCodec.mapper().convertValue(body.get(), new TypeReference<String>(){}) : null;
openapi-generator version
7.2.0 Also checked on latest master via Docker
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Example
version: 1.0.0
paths:
/example:
post:
operationId: postExample
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
200:
description: Successful operation
Generation Details
openapi-generator generate \
-i ./api.yaml \
"-g" "java-vertx-web"
Steps to reproduce
Run the above command
Related issues/PRs
Suggest a fix
Not the cleanest, but bodyParams.mustache can be:
{{#isBodyParam}}
RequestParameter rawBody = requestParameters.body();
{{dataType}} {{paramName}};
if ((routingContext.parsedHeaders().contentType().component() + "/" + routingContext.parsedHeaders().contentType().subComponent()).equals("text/plain")) {
{{paramName}} = rawBody != null ? ({{dataType}}) (Object) rawBody.get().toString() : null;
} else {
{{paramName}} = rawBody != null ? DatabindCodec.mapper().convertValue(rawBody.get(), new TypeReference<{{{dataType}}}>(){}) : null;
}
{{/isBodyParam}}