Merged
requested to merge github/fork/giveadamakick/#9902-use-flow-for-arrays-in-kotlin-delegate into master
Created by: giveadamakick
This PR fixes the problem described in issue #9902, which I'll summarize here:
- For the
kotlin-spring
generator, withdelegatePattern
andreactive
set to true, the generated API file should use a Kotlin coroutine-typeFlow
when dealing with an OpenAPIarray
data type. - For a
requestBody
parameter, it does this for a generated API class, but not for a generated Delegate class. In generated Delegate classes, an array type that is the request body is generated as akotlin.collections.List
instead of aFlow
. - This is not only incorrect, it also means the generated code does not compile, as the API class is attempting to pass a
Flow
to a Delegate that is expecting akotlin.collections.List
.
To fix this, I have made the following changes:
- I have updated the relevant Delegate Moustache template to use a
Flow
when therequestBody
parameter is an array. - I've also added some unit tests to cover this case.
How to validate
- Using this OpenAPI spec, and using an openapi-generator-maven-plugin config with
delegatePattern
andreactive
set totrue
(see this example I used), run amvn install
without the changes in this PR. You'll see that the generated code does not compile. - Repeat the above using the generator including the changes in this PR. The code now compiles, and the delegate has the correct
Flow
type for therequestBody
parameter.
After running both ./bin/generate-samples.sh
and ./bin/utils/export_docs_generators.sh
, no extra files were generated, so nothing extra to include in this PR.
Mentioning Kotlin technical committee members: @jimschubert @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(5.3.0),6.0.x
-
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.