OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][MAVEN] Avoid Mono<T> wrapper around method parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Generating an interface using reactive flag, and an open-api.yaml like this:
/sample-patch:
patch:
summary: Sample Update.
tags:
- userDevices
operationId: sampleUpdate
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SamplePatchRequest'
required: true
Generates a method like this
default Mono<ResponseEntity<String>> sampleTest(Mono<SamplePatchRequest> samplePatchRequest, ServerWebExchange exchange) {
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
Iterator var5 = exchange.getRequest().getHeaders().getAccept().iterator();
while(var5.hasNext()) {
MediaType mediaType = (MediaType)var5.next();
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"createdAt\" : \"2000-01-23\", \"active\" : true }";
result = ApiUtil.getExampleResponse(exchange, exampleString);
break;
}
}
return result.then(Mono.empty());
}
The desired result was to receive the same result without mono wrapper
default Mono<ResponseEntity<String>> sampleTest(SamplePatchRequest samplePatchRequest, ServerWebExchange exchange){
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
Iterator var5 = exchange.getRequest().getHeaders().getAccept().iterator();
while(var5.hasNext()) {
MediaType mediaType = (MediaType)var5.next();
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"createdAt\" : \"2000-01-23\", \"active\" : true }";
result = ApiUtil.getExampleResponse(exchange, exampleString);
break;
}
}
return result.then(Mono.empty());
}
Suggest a fix
I updated my open-api-template/bodyParams.mustache and open-api-template/apiDelegate.mustache file, in order to fix autogenerated code. It could be considered a valid solution to apply? (files in attachments)
open-api-template.zip
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
Reproduce the issue with the provided OpenAPI YAML and reactive setting, then inspect open-api-template/bodyParams.mustache and open-api-template/apiDelegate.mustache. Compare the generated interface signature with the requested output; done means method parameters no longer use the Mono wrapper while the reactive return type remains.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100