From ecafe781490c40a666b69c7c67515564b771db09 Mon Sep 17 00:00:00 2001 From: stefankoppier Date: Sat, 20 May 2023 09:22:39 +0200 Subject: [PATCH] Fixed additional property omitGradleWrapper for kotlin generator --- .../languages/KotlinClientCodegen.java | 25 +++++++++++++++---- .../kotlin/KotlinClientCodegenModelTest.java | 21 ++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 447e1c1f8895..e5a337110250 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -99,10 +99,11 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { protected boolean doNotUseRxAndCoroutines = true; protected boolean generateRoomModels = false; protected String roomModelPackage = ""; - + protected boolean omitGradleWrapper = false; protected String authFolder; + public enum DateLibrary { STRING("string"), THREETENBP("threetenbp"), @@ -265,6 +266,10 @@ public boolean getGenerateRoomModels() { return generateRoomModels; } + public boolean getOmitGradleWrapper() { + return omitGradleWrapper; + } + public void setGenerateRoomModels(Boolean generateRoomModels) { this.generateRoomModels = generateRoomModels; } @@ -336,6 +341,10 @@ public void setRoomModelPackage(String roomModelPackage) { this.roomModelPackage = roomModelPackage; } + public void setOmitGradleWrapper(boolean omitGradleWrapper) { + this.omitGradleWrapper = omitGradleWrapper; + } + @Override public String modelFilename(String templateName, String modelName) { String suffix = modelTemplateFiles().get(templateName); @@ -426,6 +435,10 @@ public void processOpts() { setRequestDateConverter(additionalProperties.get(REQUEST_DATE_CONVERTER).toString()); } + if (additionalProperties.containsKey(OMIT_GRADLE_WRAPPER)) { + setOmitGradleWrapper(Boolean.parseBoolean(additionalProperties.get(OMIT_GRADLE_WRAPPER).toString())); + } + commonSupportingFiles(); switch (getLibrary()) { @@ -787,10 +800,12 @@ private void commonSupportingFiles() { } // gradle wrapper supporting files - supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew")); - supportingFiles.add(new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat")); - supportingFiles.add(new SupportingFile("gradle-wrapper.properties.mustache", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.properties")); - supportingFiles.add(new SupportingFile("gradle-wrapper.jar", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.jar")); + if (!getOmitGradleWrapper()) { + supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew")); + supportingFiles.add(new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat")); + supportingFiles.add(new SupportingFile("gradle-wrapper.properties.mustache", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.properties")); + supportingFiles.add(new SupportingFile("gradle-wrapper.jar", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.jar")); + } } @Override diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java index 902b7fd9161d..3f0faf43367a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java @@ -384,6 +384,27 @@ public void testNativeClientExplodedQueryParamObject() throws IOException { ); } + @Test + public void testOmitGradleWrapperDoesNotGenerateWrapper() throws IOException { + File output = Files.createTempDirectory("test").toFile(); + String path = output.getAbsolutePath(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("kotlin") + .setInputSpec("src/test/resources/3_0/ping.yaml") + .addAdditionalProperty("omitGradleWrapper", true) + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + DefaultGenerator generator = new DefaultGenerator(); + + generator.opts(configurator.toClientOptInput()).generate(); + + TestUtils.assertFileNotExists(Paths.get(path, "gradlew")); + TestUtils.assertFileNotExists(Paths.get(path, "gradlew.bat")); + TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.properties")); + TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.jar")); + } + private static class ModelNameTest { private final String expectedName; private final String expectedClassName;