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-springgenerator, withdelegatePatternandreactiveset to true, the generated API file should use a Kotlin coroutine-typeFlowwhen dealing with an OpenAPIarraydata type. - For a
requestBodyparameter, 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.Listinstead 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
Flowto 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
Flowwhen therequestBodyparameter 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
delegatePatternandreactiveset totrue(see this example I used), run amvn installwithout 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
Flowtype for therequestBodyparameter.
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: Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./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.