-
-
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
Merged
jimschubert
merged 16 commits into
OpenAPITools:master
from
sylvainmoindron:kotlin_coroutines
Jun 2, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6ee8389
kotlin spring : add reactivity via kotlin's coroutines
sylvainmoindron 2965f9d
regenerate samples
sylvainmoindron ff91c0f
add kotlin spring boot reactive samples
sylvainmoindron 3987358
bug : fix spring version and import for coroutines
sylvainmoindron a2b2011
remove exception handler for reactive (webflux doesn't support it)
sylvainmoindron bf768be
regenerate samples
sylvainmoindron 3ced764
fix typo in gradle dependency
sylvainmoindron 9ea7970
add spring milestone repository to maven pom
sylvainmoindron 8f64813
regenerate samples
sylvainmoindron fae1524
fix type in gradle import
sylvainmoindron 9849fdc
add reactive type for list in Api and ApiImpl methodes for mathching …
sylvainmoindron e4f2ff3
fix baseType for ArraySchema
sylvainmoindron 6977ad9
regenerate samples
sylvainmoindron cf8a19f
correcting unit test
sylvainmoindron 8ebdcb5
updating documentation
sylvainmoindron 1ac9881
running bin/utils/ensure-up-to-date
sylvainmoindron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
./bin/kotlin-springboot-petstore-server.sh | ||
./bin/kotlin-springboot-petstore-server-reactive.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=$(dirname "$SCRIPT")/.. | ||
APP_DIR=$(cd "${APP_DIR}"; pwd) | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
fi | ||
|
||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/server/petstore/kotlin-springboot-reactive --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true,reactive=true" | ||
|
||
echo "Cleaning previously generated files if any from samples/server/petstore/kotlin-springboot-reactive" | ||
rm -rf samples/server/petstore/kotlin-springboot-reactive | ||
|
||
echo "Generating Kotling Spring Boot reactive server..." | ||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
./bin/openapi3/kotlin-springboot-petstore-server.sh | ||
./bin/openapi3/kotlin-springboot-petstore-server-reactive.sh |
35 changes: 35 additions & 0 deletions
35
bin/openapi3/kotlin-springboot-petstore-server-reactive.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=$(ls -ld "$SCRIPT") | ||
link=$(expr "$ls" : '.*-> \(.*\)$') | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=$(dirname "$SCRIPT")/.. | ||
APP_DIR=$(cd "${APP_DIR}"; pwd) | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
fi | ||
|
||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/server/openapi3/petstore/kotlin-springboot-reactive --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true,reactive=true" | ||
|
||
echo "Cleaning previously generated files if any from samples/server/openapi3/petstore/kotlin-springboot-reactive" | ||
rm -rf samples/server/openapi3/petstore/kotlin-springboot-reactive | ||
|
||
echo "Generating Kotling Spring Boot server..." | ||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody {{paramName}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}}{{/isBodyParam}} | ||
{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody {{paramName}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isListContainer}}{{>optionalDataType}}{{/isListContainer}}{{#isListContainer}}Flow<{{{baseType}}}>{{/isListContainer}}{{/reactive}}{{/isBodyParam}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...-generator/src/main/resources/kotlin-spring/libraries/spring-boot/settingsGradle.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
pluginManagement { | ||
repositories { | ||
maven { url = uri("https://repo.spring.io/snapshot") } | ||
maven { url = uri("https://repo.spring.io/milestone") } | ||
gradlePluginPortal() | ||
} | ||
resolutionStrategy { | ||
eachPlugin { | ||
if (requested.id.id == "org.springframework.boot") { | ||
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") | ||
} | ||
} | ||
} | ||
} | ||
rootProject.name = "{{artifactId}}" |
2 changes: 1 addition & 1 deletion
2
modules/openapi-generator/src/main/resources/kotlin-spring/returnTypes.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#isMapContainer}}{{#reactive}}Mono<{{/reactive}}Map<String, {{{returnType}}}{{#reactive}}>{{/reactive}}>{{/isMapContainer}}{{#isListContainer}}{{#reactive}}Flux{{/reactive}}{{^reactive}}List{{/reactive}}<{{{returnType}}}>{{/isListContainer}}{{^returnContainer}}{{#reactive}}Mono<{{{returnType}}}>{{/reactive}}{{^reactive}}{{{returnType}}}{{/reactive}}{{/returnContainer}} | ||
{{#isMapContainer}}Map<String, {{{returnType}}}>{{/isMapContainer}}{{#isListContainer}}{{#reactive}}Flow{{/reactive}}{{^reactive}}List{{/reactive}}<{{{returnType}}}>{{/isListContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 returnResponseEntity<T>
ResponseEntity<List<T>>
. Because my generated code contains non-suspended functions withResponseEntity<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
Generated method looks like
And I want it to be
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