Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kotlin-spring] add reactive behavior via Kotlin coroutines #2934

Merged
merged 16 commits into from
Jun 2, 2019
Merged

[kotlin-spring] add reactive behavior via Kotlin coroutines #2934

merged 16 commits into from
Jun 2, 2019

Conversation

sylvainmoindron
Copy link
Contributor

@sylvainmoindron sylvainmoindron commented May 19, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

add reactive behavior via kotlin's coroutines for #2765

@jimschubert , @dr4ke616 @karismann @Zomzog

@botcoder

@auto-labeler
Copy link

auto-labeler bot commented May 19, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@sylvainmoindron
Copy link
Contributor Author

with openapi in general (not related to this PR) i don't understand why pathParam, queryParm and bodyParam are not handled the same way for data type

@sylvainmoindron
Copy link
Contributor Author

@jimschubert @Zomzog, in the classe UserApi methode createUsersWithArrayInput in my mustache template I use
Flow<{{{baseType}}}> and it's converted to Flow<List> instead of Flow<User> what did i do wrong ?

@wing328
Copy link
Member

wing328 commented May 20, 2019

Flow<{{{baseType}}}> and it's converted to Flow instead of Flow what did i do wrong ?

To be clear, the input parameter is an array/list of User (model). Are you saying Flow<User> is the correct syntax to describe such input parameter?

@sylvainmoindron
Copy link
Contributor Author

@wing328 yes Flow<User> is the correct type for a list of user in reactive mode

@Zomzog
Copy link
Contributor

Zomzog commented May 20, 2019

There is an issue with type resolution. There is the same one with Java Spring, I will try to understand why it after working hours to help you.

@sylvainmoindron
Copy link
Contributor Author

@Zomzog I think i found the baseType bug

@sylvainmoindron
Copy link
Contributor Author

do i need to run bin/utils/ensure-up-to-date on local before comit since i modified a common element ?

@wing328
Copy link
Member

wing328 commented May 29, 2019

@sylvainmoindron thanks for fixing the bug in the default codegen (cc @OpenAPITools/generator-core-team )

If no further feedback on this PR, I'll merge it tomorrow (Thur)

@wing328 wing328 modified the milestones: 4.0.1, 4.0.2 May 31, 2019
@jimschubert
Copy link
Member

I've done a quick look over this PR and I think it looks good.

@jimschubert jimschubert merged commit 7916f2f into OpenAPITools:master Jun 2, 2019
@jimschubert
Copy link
Member

Sorry for the delay in merge. We hit a snag with the gradle plugin deployment in the 4.0.1 patch release, which pushed this merge back a few days.

jimschubert added a commit that referenced this pull request Jun 2, 2019
Generates samples to match with code introduced in #2934.
@jimschubert jimschubert mentioned this pull request Jun 2, 2019
4 tasks
jimschubert added a commit that referenced this pull request Jun 2, 2019
Generates samples to match with code introduced in #2934.
consumes = "{{{vendorExtensions.x-contentType}}}",{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
produces = [{{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}}], {{/hasProduces}}{{#hasConsumes}}
consumes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}],{{/hasConsumes}}{{/singleContentTypes}}
method = [RequestMethod.{{httpMethod}}])
fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
{{#reactive}}{{^isListContainer}}suspend {{/isListContainer}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
Copy link

@elijah-pl elijah-pl Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylvainmoindron @Zomzog Could you please help to understand how to generate a controller API with suspend functions that return ResponseEntity<T> ResponseEntity<List<T>>. Because my generated code contains non-suspended functions with ResponseEntity<Flow<T>> return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does your response is a single item or a list ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylvainmoindron A list

paths:
  /something:
    get:
      operationId: getSomething
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Something'

Generated method looks like

fun getSomething(): ResponseEntity<Flow<Something>>

And I want it to be

suspend fun getSomething(): ResponseEntity<List<Something>>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if your result is a list it's nomal that the method return a flow. flow are member of coroutine.
in your flow you can call suspend method or methos the return a flow.
when you define a flow with flow{ action here }, your action are in a coroutineScope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want single List you can define your return as an object SometingList with contain your list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants