swagger-api / swagger-api/swagger-codegen
feature request- Generation Spring-Reactor Code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Generation Spring-Reactor Code
The generation of reactive code works so far with the settings listed below. But the generated code of delegates includes the only references of Mono objects. See example:
/**
* PUT /object-store/{group-id}/{object-key} : Ressource aktualisieren
*
* @param groupId group-id des Objektes, das überschrieben bzw. neu angelegt werden soll (required)
* @param objectKey object-key des Objektes, das überschrieben werden soll (required)
* @param contentType MIME-Typ des Objektes, wird so bei der Speicherung übernommen (required)
* @param body Ein (binäres) Objekt, die abgespeichert werden soll (required)
* @return Das Objekt wurde anhand seiner group-id und object-key nicht im Store gefunden und daher neu angelegt. (status code 201)
* or Das Objekt wurde anhand seiner group-id und object-key im Store gefunden und der Inhalt und/oder die Metainformationen wurden überschrieben (status code 204)
* or Unerwarteter Fehler (status code 500)
*/
default Mono<ResponseEntity<Void>> objectStoreGroupIdObjectKeyPut(String groupId,
String objectKey,
String contentType,
Mono<org.springframework.core.io.Resource> body,
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
return result.then(Mono.empty());
}
That’s okay and it works.
However, a so-called FLux object is very often required for a reactive applications. In our case that was even decisive, so that we have to do without the generation and have reprogrammed the code by hand.
As per the documentation:
Flux is a stream which can emit 0..N elements:
Flux<String> fl = Flux.just("a", "b", "c");
Mono is a stream of 0..1 elements:
Mono<String> mn = Mono.just("hello");
Both are the implementations of the Publisher interface in the reactive stream.
Since the reactive applications are becoming more and more popular, it would definitely be nice to have an option when generating which of the interfaces Flux or Mono are used.
Swagger-codegen version
id 'org.openapi.generator' version '4.3.1'
Swagger declaration file content or url
openApiGenerate{
generatorName = "spring"
inputSpec = "${rootDir}/spec/api/swagger.yaml".toString()
outputDir = "${rootDir}/generated/api".toString()
...
additionalProperties = [
interfaceOnly: 'false',
reactive: 'true',
skipDefaultInterface: "false",
implicitHeaders: "false",
]
configOptions = [
dateLibrary: "java8",
delegatePattern: "true"
]
}
Command line used for generation
gradle openApiGenerate
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Suggestion is to implement an Option in additionalProperties
...
additionalProperties = [
interfaceOnly: 'false',
reactive: 'true',
publisherInterface: 'Flux'
]
...
Thank you
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 Spring generator's reactive generation path and the additionalProperties handling used by the Gradle openApiGenerate configuration. Trace how reactive delegate return types are selected, then verify that a publisherInterface option can select Flux and that generated delegate signatures remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100