diff --git a/docs/generators/kotlin-server.md b/docs/generators/kotlin-server.md index 72604be478a..b0580d7318c 100644 --- a/docs/generators/kotlin-server.md +++ b/docs/generators/kotlin-server.md @@ -34,6 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |interfaceOnly|Whether to generate only API interface stubs without the server files. This option is currently supported only when using jaxrs-spec library.| |false| |library|library template (sub-template)|
**ktor**
ktor framework
**jaxrs-spec**
JAX-RS spec only
|ktor| |modelMutable|Create mutable models| |false| +|omitGradleWrapper|Whether to omit Gradle wrapper for creating a sub project.| |false| |packageName|Generated artifact package name.| |org.openapitools.server| |parcelizeModels|toggle "@Parcelize" for generated models| |null| |returnResponse|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.| |false| 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 004d955d4f7..9dcd71a06ea 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 @@ -50,6 +50,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa private boolean useCoroutines = false; private boolean useMutiny = false; private boolean returnResponse = false; + private boolean omitGradleWrapper = false; // This is here to potentially warn the user when an option is not supported by the target framework. private Map> optionsSupportedPerFramework = new ImmutableMap.Builder>() @@ -60,7 +61,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa Constants.CORS, Constants.COMPRESSION, Constants.RESOURCES, - Constants.METRICS + Constants.METRICS, + Constants.OMIT_GRADLE_WRAPPER )) .put(Constants.JAXRS_SPEC, Arrays.asList( USE_BEANVALIDATION, @@ -132,6 +134,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa 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(Constants.OMIT_GRADLE_WRAPPER, Constants.OMIT_GRADLE_WRAPPER_DESC, omitGradleWrapper); addSwitch(USE_JAKARTA_EE, Constants.USE_JAKARTA_EE_DESC, useJakartaEe); } @@ -183,6 +186,14 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa return resourcesFeatureEnabled; } + public boolean getOmitGradleWrapper() { + return omitGradleWrapper; + } + + public void setOmitGradleWrapper(boolean omitGradleWrapper) { + this.omitGradleWrapper = omitGradleWrapper; + } + public void setResourcesFeatureEnabled(Boolean resourcesFeatureEnabled) { this.resourcesFeatureEnabled = resourcesFeatureEnabled; } @@ -247,6 +258,10 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); } + if (additionalProperties.containsKey(Constants.OMIT_GRADLE_WRAPPER)) { + setOmitGradleWrapper(Boolean.parseBoolean(additionalProperties.get(Constants.OMIT_GRADLE_WRAPPER).toString())); + } + writePropertyBack(USE_BEANVALIDATION, useBeanValidation); // set default library to "ktor" @@ -360,6 +375,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa 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."; + public static final String OMIT_GRADLE_WRAPPER = "omitGradleWrapper"; + public static final String OMIT_GRADLE_WRAPPER_DESC = "Whether to omit Gradle wrapper for creating a sub project."; } @Override 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 a4b2b673051..206a8720e0c 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 @@ -2,7 +2,7 @@ group "{{groupId}}" version "{{artifactVersion}}" wrapper { - gradleVersion = "6.9" + gradleVersion = '6.9' distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" } @@ -67,4 +67,4 @@ dependencies { implementation("io.smallrye.reactive:mutiny-kotlin:$mutiny_version") {{/useMutiny}} testImplementation("junit:junit:4.13.2") -} \ No newline at end of file +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache index a4547b0469f..114a9a37559 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache @@ -1,10 +1,12 @@ group "{{groupId}}" version "{{artifactVersion}}" +{{^omitGradleWrapper}} wrapper { gradleVersion = "7.4.2" distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" } +{{/omitGradleWrapper}} buildscript { ext.kotlin_version = "1.7.20" diff --git a/samples/server/petstore/kotlin-server/ktor/build.gradle b/samples/server/petstore/kotlin-server/ktor/build.gradle index bd883dc2291..2edfc7bdbc1 100644 --- a/samples/server/petstore/kotlin-server/ktor/build.gradle +++ b/samples/server/petstore/kotlin-server/ktor/build.gradle @@ -2,7 +2,7 @@ group "org.openapitools" version "1.0.0" wrapper { - gradleVersion = "7.4.2" + gradleVersion = '7.5' distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" }