-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[kotlin-spring] add reactive behavior via Kotlin coroutines #2934
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
...api-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradleKts.mustache
Outdated
Show resolved
Hide resolved
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 |
@jimschubert @Zomzog, in the classe UserApi methode createUsersWithArrayInput in my mustache template I use |
To be clear, the input parameter is an array/list of User (model). Are you saying |
@wing328 yes |
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. |
@Zomzog I think i found the baseType bug |
do i need to run |
@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) |
I've done a quick look over this PR and I think it looks good. |
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. |
Generates samples to match with code introduced in #2934.
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}}> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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>>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
PR checklist
./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.master
.Description of the PR
add reactive behavior via kotlin's coroutines for #2765
@jimschubert , @dr4ke616 @karismann @Zomzog
@botcoder