OpenAPITools / OpenAPITools/openapi-generator
[BUG][java-vertx-web] Generated code does not compile for text/plain request bodies
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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}}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the java-vertx-web generator's bodyParams.mustache template and reproduce the issue using the supplied OpenAPI YAML and generation command. Inspect the generated handler for the text/plain body and verify that the resulting Java source compiles without the body variable redeclaration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100