From c6a100cce29c519b03d79511565d2065020e5e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Lepp=C3=A4?= Date: Mon, 31 Jul 2023 04:50:44 +0300 Subject: [PATCH] Added support for using mutiny instead of coroutines for asynchronous kotlin server APIs (#15262) --- .github/workflows/samples-kotlin-server.yaml | 1 + .../kotlin-server-jaxrs-spec-mutiny.yaml | 9 ++ docs/generators/kotlin-server.md | 1 + .../languages/KotlinServerCodegen.java | 12 +++ .../jaxrs-spec/apiInterface.mustache | 2 +- .../jaxrs-spec/build.gradle.mustache | 9 +- .../.openapi-generator-ignore | 23 +++++ .../.openapi-generator/FILES | 13 +++ .../.openapi-generator/VERSION | 1 + .../kotlin-server/jaxrs-spec-mutiny/README.md | 91 +++++++++++++++++++ .../jaxrs-spec-mutiny/build.gradle | 54 +++++++++++ .../jaxrs-spec-mutiny/gradle.properties | 1 + .../jaxrs-spec-mutiny/settings.gradle | 1 + .../org/openapitools/server/apis/PetApi.kt | 57 ++++++++++++ .../org/openapitools/server/apis/StoreApi.kt | 35 +++++++ .../org/openapitools/server/apis/UserApi.kt | 50 ++++++++++ .../openapitools/server/models/Category.kt | 34 +++++++ .../server/models/ModelApiResponse.kt | 39 ++++++++ .../org/openapitools/server/models/Order.kt | 67 ++++++++++++++ .../org/openapitools/server/models/Pet.kt | 69 ++++++++++++++ .../org/openapitools/server/models/Tag.kt | 34 +++++++ .../org/openapitools/server/models/User.kt | 65 +++++++++++++ .../kotlin-server/jaxrs-spec/build.gradle | 2 +- 23 files changed, 667 insertions(+), 3 deletions(-) create mode 100644 bin/configs/kotlin-server-jaxrs-spec-mutiny.yaml create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator-ignore create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/FILES create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/VERSION create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/README.md create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/build.gradle create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/gradle.properties create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/settings.gradle create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/PetApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/UserApi.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Category.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Order.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Pet.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Tag.kt create mode 100644 samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/User.kt diff --git a/.github/workflows/samples-kotlin-server.yaml b/.github/workflows/samples-kotlin-server.yaml index ca54c38e5db..3fbafa1d09b 100644 --- a/.github/workflows/samples-kotlin-server.yaml +++ b/.github/workflows/samples-kotlin-server.yaml @@ -29,6 +29,7 @@ jobs: - samples/server/petstore/kotlin-springboot-springfox - samples/server/petstore/kotlin-server/ktor - samples/server/petstore/kotlin-server/jaxrs-spec + - samples/server/petstore/kotlin-server/jaxrs-spec-mutiny - samples/server/petstore/kotlin-server-modelMutable # no build.gradle file #- samples/server/petstore/kotlin-vertx-modelMutable diff --git a/bin/configs/kotlin-server-jaxrs-spec-mutiny.yaml b/bin/configs/kotlin-server-jaxrs-spec-mutiny.yaml new file mode 100644 index 00000000000..28c51a4a4ef --- /dev/null +++ b/bin/configs/kotlin-server-jaxrs-spec-mutiny.yaml @@ -0,0 +1,9 @@ +generatorName: kotlin-server +outputDir: samples/server/petstore/kotlin-server/jaxrs-spec-mutiny +library: jaxrs-spec +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-server +additionalProperties: + returnResponse: "true" + interfaceOnly: "true" + useMutiny: "true" diff --git a/docs/generators/kotlin-server.md b/docs/generators/kotlin-server.md index 7c99a8d22f7..72604be478a 100644 --- a/docs/generators/kotlin-server.md +++ b/docs/generators/kotlin-server.md @@ -45,6 +45,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useBeanValidation|Use BeanValidation API annotations. This option is currently supported only when using jaxrs-spec library.| |false| |useCoroutines|Whether to use the Coroutines. This option is currently supported only when using jaxrs-spec library.| |false| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| +|useMutiny|Whether to use Mutiny (should not be used with useCoroutines). This option is currently supported only when using jaxrs-spec library.| |false| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 27d2b456db1..004d955d4f7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -48,6 +48,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa private boolean interfaceOnly = false; private boolean useBeanValidation = false; private boolean useCoroutines = false; + private boolean useMutiny = false; private boolean returnResponse = false; // This is here to potentially warn the user when an option is not supported by the target framework. @@ -64,6 +65,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa .put(Constants.JAXRS_SPEC, Arrays.asList( USE_BEANVALIDATION, Constants.USE_COROUTINES, + Constants.USE_MUTINY, Constants.RETURN_RESPONSE, Constants.INTERFACE_ONLY )) @@ -128,6 +130,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa addSwitch(Constants.INTERFACE_ONLY, Constants.INTERFACE_ONLY_DESC, interfaceOnly); addSwitch(USE_BEANVALIDATION, Constants.USE_BEANVALIDATION_DESC, useBeanValidation); addSwitch(Constants.USE_COROUTINES, Constants.USE_COROUTINES_DESC, useCoroutines); + addSwitch(Constants.USE_MUTINY, Constants.USE_MUTINY_DESC, useMutiny); addSwitch(Constants.RETURN_RESPONSE, Constants.RETURN_RESPONSE_DESC, returnResponse); addSwitch(USE_JAKARTA_EE, Constants.USE_JAKARTA_EE_DESC, useJakartaEe); } @@ -226,6 +229,13 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa } } + if (additionalProperties.containsKey(Constants.USE_MUTINY)) { + useMutiny = Boolean.parseBoolean(additionalProperties.get(Constants.USE_MUTINY).toString()); + if (!useMutiny) { + additionalProperties.remove(Constants.USE_MUTINY); + } + } + if (additionalProperties.containsKey(Constants.RETURN_RESPONSE)) { returnResponse = Boolean.parseBoolean(additionalProperties.get(Constants.RETURN_RESPONSE).toString()); if (!returnResponse) { @@ -348,6 +358,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa public static final String RETURN_RESPONSE = "returnResponse"; public static final String RETURN_RESPONSE_DESC = "Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true. This option is currently supported only when using jaxrs-spec library."; public static final String USE_JAKARTA_EE_DESC = "whether to use Jakarta EE namespace instead of javax"; + public static final String USE_MUTINY = "useMutiny"; + public static final String USE_MUTINY_DESC = "Whether to use Mutiny (should not be used with useCoroutines). This option is currently supported only when using jaxrs-spec library."; } @Override diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache index d64ab757938..7994ec111f2 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/apiInterface.mustache @@ -10,4 +10,4 @@ {{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }) @ApiResponses(value = { {{#responses}} @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}){{^-last}},{{/-last}}{{/responses}} }){{/useSwaggerAnnotations}} - {{#useCoroutines}}suspend {{/useCoroutines}}fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}){{#returnResponse}}: Response{{/returnResponse}}{{^returnResponse}}{{#returnType}}: {{{returnType}}}{{/returnType}}{{/returnResponse}} \ No newline at end of file + {{#useCoroutines}}suspend {{/useCoroutines}}fun {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}){{#returnResponse}}: {{#useMutiny}}io.smallrye.mutiny.Uni<{{/useMutiny}}Response{{#useMutiny}}>{{/useMutiny}}{{/returnResponse}}{{^returnResponse}}{{#returnType}}: {{#useMutiny}}io.smallrye.mutiny.Uni<{{/useMutiny}}{{{returnType}}}{{#useMutiny}}>{{/useMutiny}}{{/returnType}}{{/returnResponse}}{{^returnResponse}}{{^returnType}}{{#useMutiny}}: io.smallrye.mutiny.Uni{{/useMutiny}}{{/returnType}}{{/returnResponse}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache index d1cc9f65473..a4b2b673051 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/jaxrs-spec/build.gradle.mustache @@ -7,7 +7,7 @@ wrapper { } buildscript { - ext.kotlin_version = "1.4.32" + ext.kotlin_version = "1.7.20" ext.swagger_annotations_version = "1.5.3" {{#useJakartaEe}} ext.jakarta_annotations_version = "2.1.1" @@ -17,6 +17,9 @@ buildscript { ext.jakarta_annotations_version = "1.3.5" ext.jakarta_ws_rs_version = "2.1.6" {{/useJakartaEe}} +{{#useMutiny}} + ext.mutiny_version = "2.2.0" +{{/useMutiny}} ext.jackson_version = "2.9.9" {{#useBeanValidation}} ext.beanvalidation_version = "2.0.2" @@ -59,5 +62,9 @@ dependencies { {{#useBeanValidation}} implementation("jakarta.validation:jakarta.validation-api:$beanvalidation_version") {{/useBeanValidation}} +{{#useMutiny}} + implementation("io.smallrye.reactive:mutiny:$mutiny_version") + implementation("io.smallrye.reactive:mutiny-kotlin:$mutiny_version") +{{/useMutiny}} testImplementation("junit:junit:4.13.2") } \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator-ignore b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/FILES b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/FILES new file mode 100644 index 00000000000..8311b1e0d0a --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/FILES @@ -0,0 +1,13 @@ +README.md +build.gradle +gradle.properties +settings.gradle +src/main/kotlin/org/openapitools/server/apis/PetApi.kt +src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +src/main/kotlin/org/openapitools/server/apis/UserApi.kt +src/main/kotlin/org/openapitools/server/models/Category.kt +src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +src/main/kotlin/org/openapitools/server/models/Order.kt +src/main/kotlin/org/openapitools/server/models/Pet.kt +src/main/kotlin/org/openapitools/server/models/Tag.kt +src/main/kotlin/org/openapitools/server/models/User.kt diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/VERSION b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/VERSION new file mode 100644 index 00000000000..757e6740040 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/README.md b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/README.md new file mode 100644 index 00000000000..231a738d36c --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/README.md @@ -0,0 +1,91 @@ +# org.openapitools.server - Kotlin Server library for OpenAPI Petstore + +## Requires + +* Kotlin 1.4.31 +* Gradle 6.8.2 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, and Form inputs. +* Supports collection formats for query parameters: csv, tsv, ssv, pipes. +* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions. + + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store +*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet +*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status +*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags +*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID +*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet +*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status +*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet +*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user +*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array +*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user +*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name +*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system +*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session +*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user + + + +## Documentation for Models + + - [org.openapitools.server.models.Category](docs/Category.md) + - [org.openapitools.server.models.ModelApiResponse](docs/ModelApiResponse.md) + - [org.openapitools.server.models.Order](docs/Order.md) + - [org.openapitools.server.models.Pet](docs/Pet.md) + - [org.openapitools.server.models.Tag](docs/Tag.md) + - [org.openapitools.server.models.User](docs/User.md) + + + +## Documentation for Authorization + + +Authentication schemes defined for the API: + +### petstore_auth + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog +- **Scopes**: + - write:pets: modify pets in your account + - read:pets: read your pets + + +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/build.gradle b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/build.gradle new file mode 100644 index 00000000000..8ce9368aac9 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/build.gradle @@ -0,0 +1,54 @@ +group "org.openapitools" +version "1.0.0" + +wrapper { + gradleVersion = "6.9" + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = "1.7.20" + ext.swagger_annotations_version = "1.5.3" + ext.jakarta_annotations_version = "1.3.5" + ext.jakarta_ws_rs_version = "2.1.6" + ext.mutiny_version = "2.2.0" + ext.jackson_version = "2.9.9" + repositories { + maven { url "https://repo1.maven.org/maven2" } + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + } +} + +apply plugin: "java" +apply plugin: "kotlin" +apply plugin: "application" + +sourceCompatibility = 1.8 + +compileKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +compileTestKotlin { + kotlinOptions.jvmTarget = "1.8" +} + +repositories { + maven { setUrl("https://repo1.maven.org/maven2") } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") + implementation("ch.qos.logback:logback-classic:1.2.1") + implementation("jakarta.ws.rs:jakarta.ws.rs-api:$jakarta_ws_rs_version") + implementation("jakarta.annotation:jakarta.annotation-api:$jakarta_annotations_version") + implementation("io.swagger:swagger-annotations:$swagger_annotations_version") + implementation("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version") + implementation("io.smallrye.reactive:mutiny:$mutiny_version") + implementation("io.smallrye.reactive:mutiny-kotlin:$mutiny_version") + testImplementation("junit:junit:4.13.2") +} \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/gradle.properties b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/gradle.properties new file mode 100644 index 00000000000..5f1ed7bbe02 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/gradle.properties @@ -0,0 +1 @@ +org.gradle.caching=true \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/settings.gradle b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/settings.gradle new file mode 100644 index 00000000000..a09a58efab1 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'kotlin-server' \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/PetApi.kt new file mode 100644 index 00000000000..a3d27af07af --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -0,0 +1,57 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.ModelApiResponse +import org.openapitools.server.models.Pet + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream + + + +@Path("/") +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen")) +interface PetApi { + + @POST + @Path("/pet") + @Consumes("application/json", "application/xml") + fun addPet( body: Pet): io.smallrye.mutiny.Uni + + @DELETE + @Path("/pet/{petId}") + fun deletePet(@PathParam("petId") petId: kotlin.Long,@HeaderParam("api_key") apiKey: kotlin.String?): io.smallrye.mutiny.Uni + + @GET + @Path("/pet/findByStatus") + @Produces("application/xml", "application/json") + fun findPetsByStatus(@QueryParam("status") status: kotlin.collections.List): io.smallrye.mutiny.Uni + + @GET + @Path("/pet/findByTags") + @Produces("application/xml", "application/json") + fun findPetsByTags(@QueryParam("tags") tags: kotlin.collections.List): io.smallrye.mutiny.Uni + + @GET + @Path("/pet/{petId}") + @Produces("application/xml", "application/json") + fun getPetById(@PathParam("petId") petId: kotlin.Long): io.smallrye.mutiny.Uni + + @PUT + @Path("/pet") + @Consumes("application/json", "application/xml") + fun updatePet( body: Pet): io.smallrye.mutiny.Uni + + @POST + @Path("/pet/{petId}") + @Consumes("application/x-www-form-urlencoded") + fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "name") name: kotlin.String?,@FormParam(value = "status") status: kotlin.String?): io.smallrye.mutiny.Uni + + @POST + @Path("/pet/{petId}/uploadImage") + @Consumes("multipart/form-data") + @Produces("application/json") + fun uploadFile(@PathParam("petId") petId: kotlin.Long,@FormParam(value = "additionalMetadata") additionalMetadata: kotlin.String?, @FormParam(value = "file") fileInputStream: InputStream?): io.smallrye.mutiny.Uni +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt new file mode 100644 index 00000000000..f762f310450 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -0,0 +1,35 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.Order + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream + + + +@Path("/") +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen")) +interface StoreApi { + + @DELETE + @Path("/store/order/{orderId}") + fun deleteOrder(@PathParam("orderId") orderId: kotlin.String): io.smallrye.mutiny.Uni + + @GET + @Path("/store/inventory") + @Produces("application/json") + fun getInventory(): io.smallrye.mutiny.Uni + + @GET + @Path("/store/order/{orderId}") + @Produces("application/xml", "application/json") + fun getOrderById(@PathParam("orderId") orderId: kotlin.Long): io.smallrye.mutiny.Uni + + @POST + @Path("/store/order") + @Produces("application/xml", "application/json") + fun placeOrder( body: Order): io.smallrye.mutiny.Uni +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/UserApi.kt new file mode 100644 index 00000000000..e27e93c65c2 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -0,0 +1,50 @@ +package org.openapitools.server.apis; + +import org.openapitools.server.models.User + +import javax.ws.rs.* +import javax.ws.rs.core.Response + + +import java.io.InputStream + + + +@Path("/") +@javax.annotation.Generated(value = arrayOf("org.openapitools.codegen.languages.KotlinServerCodegen")) +interface UserApi { + + @POST + @Path("/user") + fun createUser( body: User): io.smallrye.mutiny.Uni + + @POST + @Path("/user/createWithArray") + fun createUsersWithArrayInput( body: kotlin.collections.List): io.smallrye.mutiny.Uni + + @POST + @Path("/user/createWithList") + fun createUsersWithListInput( body: kotlin.collections.List): io.smallrye.mutiny.Uni + + @DELETE + @Path("/user/{username}") + fun deleteUser(@PathParam("username") username: kotlin.String): io.smallrye.mutiny.Uni + + @GET + @Path("/user/{username}") + @Produces("application/xml", "application/json") + fun getUserByName(@PathParam("username") username: kotlin.String): io.smallrye.mutiny.Uni + + @GET + @Path("/user/login") + @Produces("application/xml", "application/json") + fun loginUser(@QueryParam("username") username: kotlin.String,@QueryParam("password") password: kotlin.String): io.smallrye.mutiny.Uni + + @GET + @Path("/user/logout") + fun logoutUser(): io.smallrye.mutiny.Uni + + @PUT + @Path("/user/{username}") + fun updateUser(@PathParam("username") username: kotlin.String, body: User): io.smallrye.mutiny.Uni +} diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Category.kt new file mode 100644 index 00000000000..9a39acd8aea --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -0,0 +1,34 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import com.fasterxml.jackson.annotation.JsonProperty +/** + * A category for a pet + * + * @param id + * @param name + */ + + +data class Category ( + + + @JsonProperty("id") + val id: kotlin.Long? = null, + + + @JsonProperty("name") + val name: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt new file mode 100644 index 00000000000..531f364e2f7 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -0,0 +1,39 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import com.fasterxml.jackson.annotation.JsonProperty +/** + * Describes the result of uploading an image resource + * + * @param code + * @param type + * @param message + */ + + +data class ModelApiResponse ( + + + @JsonProperty("code") + val code: kotlin.Int? = null, + + + @JsonProperty("type") + val type: kotlin.String? = null, + + + @JsonProperty("message") + val message: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Order.kt new file mode 100644 index 00000000000..d4a39a2c2bb --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -0,0 +1,67 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import com.fasterxml.jackson.annotation.JsonProperty +/** + * An order for a pets from the pet store + * + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ + + +data class Order ( + + + @JsonProperty("id") + val id: kotlin.Long? = null, + + + @JsonProperty("petId") + val petId: kotlin.Long? = null, + + + @JsonProperty("quantity") + val quantity: kotlin.Int? = null, + + + @JsonProperty("shipDate") + val shipDate: java.time.OffsetDateTime? = null, + + /* Order Status */ + + @JsonProperty("status") + val status: Order.Status? = null, + + + @JsonProperty("complete") + val complete: kotlin.Boolean? = false + +) { + + /** + * Order Status + * + * Values: placed,approved,delivered + */ + enum class Status(val value: kotlin.String) { + @JsonProperty(value = "placed") placed("placed"), + @JsonProperty(value = "approved") approved("approved"), + @JsonProperty(value = "delivered") delivered("delivered"); + } +} + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Pet.kt new file mode 100644 index 00000000000..826d87a7303 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -0,0 +1,69 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import org.openapitools.server.models.Category +import org.openapitools.server.models.Tag +import com.fasterxml.jackson.annotation.JsonProperty +/** + * A pet for sale in the pet store + * + * @param name + * @param photoUrls + * @param id + * @param category + * @param tags + * @param status pet status in the store + */ + + +data class Pet ( + + + @JsonProperty("name") + val name: kotlin.String, + + + @JsonProperty("photoUrls") + val photoUrls: kotlin.collections.List, + + + @JsonProperty("id") + val id: kotlin.Long? = null, + + + @JsonProperty("category") + val category: Category? = null, + + + @JsonProperty("tags") + val tags: kotlin.collections.List? = null, + + /* pet status in the store */ + + @JsonProperty("status") + val status: Pet.Status? = null + +) { + + /** + * pet status in the store + * + * Values: available,pending,sold + */ + enum class Status(val value: kotlin.String) { + @JsonProperty(value = "available") available("available"), + @JsonProperty(value = "pending") pending("pending"), + @JsonProperty(value = "sold") sold("sold"); + } +} + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Tag.kt new file mode 100644 index 00000000000..ded0e6fab03 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -0,0 +1,34 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import com.fasterxml.jackson.annotation.JsonProperty +/** + * A tag for a pet + * + * @param id + * @param name + */ + + +data class Tag ( + + + @JsonProperty("id") + val id: kotlin.Long? = null, + + + @JsonProperty("name") + val name: kotlin.String? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/User.kt new file mode 100644 index 00000000000..4d0dcec6691 --- /dev/null +++ b/samples/server/petstore/kotlin-server/jaxrs-spec-mutiny/src/main/kotlin/org/openapitools/server/models/User.kt @@ -0,0 +1,65 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.server.models + +import com.fasterxml.jackson.annotation.JsonProperty +/** + * A User who is purchasing from the pet store + * + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ + + +data class User ( + + + @JsonProperty("id") + val id: kotlin.Long? = null, + + + @JsonProperty("username") + val username: kotlin.String? = null, + + + @JsonProperty("firstName") + val firstName: kotlin.String? = null, + + + @JsonProperty("lastName") + val lastName: kotlin.String? = null, + + + @JsonProperty("email") + val email: kotlin.String? = null, + + + @JsonProperty("password") + val password: kotlin.String? = null, + + + @JsonProperty("phone") + val phone: kotlin.String? = null, + + /* User Status */ + + @JsonProperty("userStatus") + val userStatus: kotlin.Int? = null + +) + diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle b/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle index b6a64f9fe9c..08b7d334129 100644 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle +++ b/samples/server/petstore/kotlin-server/jaxrs-spec/build.gradle @@ -7,7 +7,7 @@ wrapper { } buildscript { - ext.kotlin_version = "1.4.32" + ext.kotlin_version = "1.7.20" ext.swagger_annotations_version = "1.5.3" ext.jakarta_annotations_version = "1.3.5" ext.jakarta_ws_rs_version = "2.1.6"