Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !11695

[kotlin-spring] fix #9902 use coroutine Flow for arrays in delegate when reactive=true

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/giveadamakick/#9902-use-flow-for-arrays-in-kotlin-delegate into master Feb 23, 2022
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 3

Created by: giveadamakick

This PR fixes the problem described in issue #9902, which I'll summarize here:

  • For the kotlin-spring generator, with delegatePattern and reactive set to true, the generated API file should use a Kotlin coroutine-type Flow when dealing with an OpenAPI array 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 a kotlin.collections.List instead of a Flow.
  • 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 a kotlin.collections.List.

To fix this, I have made the following changes:

  • I have updated the relevant Delegate Moustache template to use a Flow when the requestBody parameter is an array.
  • I've also added some unit tests to cover this case.

How to validate

  1. Using this OpenAPI spec, and using an openapi-generator-maven-plugin config with delegatePattern and reactive set to true (see this example I used), run a mvn install without the changes in this PR. You'll see that the generated code does not compile.
  2. 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 the requestBody 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
    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 ./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.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/giveadamakick/#9902-use-flow-for-arrays-in-kotlin-delegate