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

* kotlin spring : add reactivity via kotlin's coroutines

* add kotlin spring boot reactive samples

* bug : fix spring version and import for coroutines

* remove exception handler for reactive (webflux doesn't support it)

* add spring milestone repository to maven pom

* add reactive type for list in Api and ApiImpl methodes for mathching body responsive parameter

* fix baseType for ArraySchema

* regenerate samples

* updating documentation
This commit is contained in:
sylvainmoindron
2019-06-02 21:50:45 +02:00
committed by Jim Schubert
parent b74fa4458d
commit 7916f2f880
146 changed files with 3078 additions and 268 deletions

View File

@@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3")
}
}
@@ -23,15 +23,16 @@ tasks.withType<KotlinCompile> {
}
plugins {
val kotlinVersion = "1.2.60"
val kotlinVersion = "1.3.30"
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
id("org.springframework.boot") version "2.0.3.RELEASE"
id("org.springframework.boot") version "2.2.0.M3"
id("io.spring.dependency-management") version "1.0.5.RELEASE"
}
dependencies {
val kotlinxCoroutinesVersion="1.2.0"
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
compile("org.springframework.boot:spring-boot-starter-web")
@@ -45,3 +46,9 @@ dependencies {
exclude(module = "junit")
}
}
repositories {
mavenCentral()
maven { url = uri("https://repo.spring.io/snapshot") }
maven { url = uri("https://repo.spring.io/milestone") }
}

View File

@@ -6,12 +6,13 @@
<name>openapi-spring</name>
<version>1.0.0</version>
<properties>
<kotlin.version>1.2.60</kotlin.version>
<kotlin.version>1.3.30</kotlin.version>
<kotlinx-coroutines.version>1.2.0</kotlinx-coroutines.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<version>2.2.0.M3</version>
</parent>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
@@ -79,6 +80,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
@@ -112,4 +114,34 @@
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -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 = "openapi-spring"

View File

@@ -12,7 +12,7 @@ import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -36,7 +37,7 @@ import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@Controller
@RestController
@Validated
@Api(value = "Pet", description = "The Pet API")
@RequestMapping("\${api.base-path:/v2}")

View File

@@ -2,22 +2,21 @@ package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
interface PetApiService {
fun addPet(body: Pet): Unit
fun addPet(body: Pet): Unit
fun deletePet(petId: Long, apiKey: String?): Unit
fun deletePet(petId: Long, apiKey: String?): Unit
fun findPetsByStatus(status: List<String>): List<Pet>
fun findPetsByStatus(status: List<String>): List<Pet>
fun findPetsByTags(tags: List<String>): List<Pet>
fun findPetsByTags(tags: List<String>): List<Pet>
fun getPetById(petId: Long): Pet
fun getPetById(petId: Long): Pet
fun updatePet(body: Pet): Unit
fun updatePet(body: Pet): Unit
fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit
fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit
fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse
fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse
}

View File

@@ -11,7 +11,7 @@ import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -35,7 +36,7 @@ import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@Controller
@RestController
@Validated
@Api(value = "Store", description = "The Store API")
@RequestMapping("\${api.base-path:/v2}")

View File

@@ -1,14 +1,13 @@
package org.openapitools.api
import org.openapitools.model.Order
interface StoreApiService {
fun deleteOrder(orderId: String): Unit
fun deleteOrder(orderId: String): Unit
fun getInventory(): Map<String, Int>
fun getInventory(): Map<String, Int>
fun getOrderById(orderId: Long): Order
fun getOrderById(orderId: Long): Order
fun placeOrder(body: Order): Order
fun placeOrder(body: Order): Order
}

View File

@@ -11,7 +11,7 @@ import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -35,7 +36,7 @@ import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@Controller
@RestController
@Validated
@Api(value = "User", description = "The User API")
@RequestMapping("\${api.base-path:/v2}")

View File

@@ -1,22 +1,21 @@
package org.openapitools.api
import org.openapitools.model.User
interface UserApiService {
fun createUser(body: User): Unit
fun createUser(body: User): Unit
fun createUsersWithArrayInput(body: List<User>): Unit
fun createUsersWithArrayInput(body: List<User>): Unit
fun createUsersWithListInput(body: List<User>): Unit
fun createUsersWithListInput(body: List<User>): Unit
fun deleteUser(username: String): Unit
fun deleteUser(username: String): Unit
fun getUserByName(username: String): User
fun getUserByName(username: String): User
fun loginUser(username: String, password: String): String
fun loginUser(username: String, password: String): String
fun logoutUser(): Unit
fun logoutUser(): Unit
fun updateUser(username: String, body: User): Unit
fun updateUser(username: String, body: User): Unit
}