From a57703d3e0938879473292539cfa4d9430e7734d Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Sun, 15 Aug 2021 22:09:04 +0200 Subject: [PATCH 01/14] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20all=20depen?= =?UTF-8?q?dencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 ++++++- buildSrc/src/main/kotlin/Dependencies.kt | 20 +++++++++----------- gradle/wrapper/gradle-wrapper.properties | 2 +- lib/build.gradle.kts | 6 +++++- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 400d551..441bd5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change Log ========== -## 2.2.4 (TBD) + +## 2.3.0 (TBD) + +### Updated: +- All dependencies. +- Gradle to 7.1.1. ### Added: - Support for Kotlin Multiplatform `kotlinx.datetime` date library diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index f1e9ea1..e2d02d2 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,17 +1,16 @@ /* ============================= VERSIONS ======================= */ private object Versions { - const val kotlin = "1.3.72" - const val dokka = "0.10.0" - const val bintrayGradle = "1.8.4" + const val kotlin = "1.5.21" + const val dokka = "1.4.30" - const val openApiCodegen = "4.3.0" + const val openApiCodegen = "5.2.0" - const val junit = "4.12" - const val kotlinTest = "3.3.0" + const val junit = "5.7.2" + const val kotest = "4.6.1" - const val retrofit = "2.6.0" - const val moshi = "1.9.2" + const val retrofit = "2.9.0" + const val moshi = "1.12.0" const val swaggerCodeGen = "2.2.0" } @@ -20,7 +19,6 @@ private object Versions { object GradlePlugins { const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}" - const val bintrayGradle = "com.jfrog.bintray.gradle:gradle-bintray-plugin:${Versions.bintrayGradle}" } /* ============================= ARTIFACTS ============================= */ @@ -59,8 +57,8 @@ object Dependencies { } object TestLibs { - const val junit = "junit:junit:${Versions.junit}" - const val kotlinTest = "io.kotlintest:kotlintest-runner-junit5:${Versions.kotlinTest}" + const val junit = "org.junit.jupiter:junit-jupiter-api:${Versions.junit}" + const val kotest = "io.kotest:kotest-runner-junit5:${Versions.kotest}" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1b16c34..05679dc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 5abaa04..d267f9f 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -16,7 +16,7 @@ dependencies { implementation(Dependencies.Libs.openApiCodegen) testImplementation(Dependencies.TestLibs.junit) - testImplementation(Dependencies.TestLibs.kotlinTest) + testImplementation(Dependencies.TestLibs.kotest) } tasks.withType { @@ -25,6 +25,10 @@ tasks.withType { } } +tasks.withType { + useJUnitPlatform() +} + val dokka by tasks.getting(DokkaTask::class) { outputFormat = "html" outputDirectory = "$buildDir/dokka/html" From 7eaf7fd176a2bb937bbb6dda6e08ee3861fe7bde Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Sun, 15 Aug 2021 22:40:37 +0200 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=90=9B=20Fix=20synch=20after=20depe?= =?UTF-8?q?ndency=20update=20+=20remove=20bintray=20to=20use=20eMan=20mave?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 12 +-- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- lib/build.gradle.kts | 117 +++++++++-------------- sample/build.gradle.kts | 1 - settings.gradle.kts | 5 +- 5 files changed, 54 insertions(+), 83 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 849d8ca..915b6a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,22 +1,22 @@ buildscript { repositories { - jcenter() + mavenCentral() + mavenLocal() // TODO: remove - dev only + maven("https://nexus.eman.cz/repository/maven-public") } dependencies { classpath(GradlePlugins.kotlin) classpath(GradlePlugins.dokka) - classpath(GradlePlugins.bintrayGradle) classpath(Dependencies.GradlePlugins.swaggerCodeGen) } } allprojects { repositories { - jcenter() - - // For OpenApi generator snapshot - maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + mavenCentral() + mavenLocal() // TODO: remove - dev only + maven("https://nexus.eman.cz/repository/maven-public") } group = Artifact.groupId diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index e2d02d2..3b670ad 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -11,7 +11,7 @@ private object Versions { const val retrofit = "2.9.0" const val moshi = "1.12.0" - const val swaggerCodeGen = "2.2.0" + const val swaggerCodeGen = "2.2.3" } /* ============================= BUILD-PLUGINS ======================= */ diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index d267f9f..c801823 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -1,5 +1,3 @@ -import com.jfrog.bintray.gradle.BintrayExtension -import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -7,7 +5,6 @@ plugins { kotlin("jvm") id("org.jetbrains.dokka") id("maven-publish") - id("com.jfrog.bintray") } dependencies { @@ -29,19 +26,12 @@ tasks.withType { useJUnitPlatform() } -val dokka by tasks.getting(DokkaTask::class) { - outputFormat = "html" - outputDirectory = "$buildDir/dokka/html" - configuration { - moduleName = Artifact.artifactId - } -} - val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") from(files("src/main/kotlin")) } +val dokka by tasks.dokkaHtml val dokkaHtmlJar by tasks.creating(Jar::class) { archiveClassifier.set("kdoc-html") from(dokka.outputDirectory) @@ -57,72 +47,57 @@ gradlePlugin { } } -val releasePublication = "release" -publishing { - publications { - create(releasePublication) { - artifactId = Artifact.artifactId - from(components["java"]) - artifact(sourcesJar) - artifact(dokkaHtmlJar) - - pom { - name.set("Swagger Codegen") - description.set("A fork of the swagger-codegen by eMan") - url.set("https://github.com/eManPrague/swagger-codegen") - - licenses { - license { - name.set("MIT License") - url.set("https://opensource.org/licenses/MIT") +afterEvaluate { + publishing { + publications { + create("release") { + artifactId = Artifact.artifactId + from(components["java"]) + artifact(sourcesJar) + artifact(dokkaHtmlJar) + + pom { + name.set("Swagger Codegen") + description.set("A fork of the swagger-codegen by eMan") + url.set("https://github.com/eManPrague/swagger-codegen") + + licenses { + license { + name.set("MIT License") + url.set("https://opensource.org/licenses/MIT") + } } - } - developers { - developer { - name.set("eMan a.s.") - email.set("info@eman.cz") + developers { + developer { + name.set("eMan a.s.") + email.set("info@eman.cz") + } } - } - scm { - connection.set("scm:git:git://github.com/eManPrague/swagger-codegen.git") - developerConnection.set("scm:git:ssh://git@github.com/eManPrague/swagger-codegen.git") - url.set("https://github.com/eManPrague/swagger-codegen") + scm { + connection.set("scm:git:git://github.com/eManPrague/swagger-codegen.git") + developerConnection.set("scm:git:ssh://git@github.com/eManPrague/swagger-codegen.git") + url.set("https://github.com/eManPrague/swagger-codegen") + } + + issueManagement { + system.set("GitHub Issues") + url.set("https://github.com/eManPrague/swagger-codegen/issues") + } } } } - } - repositories { - maven(url = "https://dl.bintray.com/emanprague/maven") { name = "bintray" } - } -} + repositories { + maven(url = "https://nexus.eman.cz/repository/maven-public") { + name = "Nexus" -bintray { - user = findPropertyOrNull("bintray.user") - key = findPropertyOrNull("bintray.apikey") - publish = true - setPublications(releasePublication) - pkg(delegateClosureOf { - repo = "maven" - name = "cz.eman.swagger.codegen" - userOrg = "emanprague" - override = true - websiteUrl = "https://www.emanprague.com/en/" - githubRepo = "eManPrague/swagger-codegen" - vcsUrl = "https://github.com/eManPrague/swagger-codegen" - description = "A fork of the swagger-codegen by eMan" - setLabels( - "kotlin", - "swagger", - "codegen", - "retrofit", - "room", - "swagger-codegen", - "openapi" - ) - setLicenses("MIT") - desc = description - }) -} + credentials { + username = findPropertyOrNull("nexus.username") + password = findPropertyOrNull("nexus.password") + } + } + } + } +} \ No newline at end of file diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 7d9c66b..676e296 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,4 +1,3 @@ -// import org.jetbrains.dokka.gradle.DokkaTask import cz.eman.swagger.codegen.SwaggerCodeGenConfig import cz.eman.swagger.codegen.SwaggerCodeGenTaskConfig import org.jetbrains.kotlin.gradle.tasks.KotlinCompile diff --git a/settings.gradle.kts b/settings.gradle.kts index b474b7e..264f191 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,4 @@ rootProject.buildFileName = "build.gradle.kts" -include( - ":lib", - ":sample" -) +include(":lib", ":sample") From 39b852cea1654924c334b23f174197454f3ef2e4 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Sun, 15 Aug 2021 23:06:28 +0200 Subject: [PATCH 03/14] =?UTF-8?q?=F0=9F=90=9B=20Fix=20build=20after=20depe?= =?UTF-8?q?ndency=20upgrade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- .../swagger/codegen/SwaggerCodeGenPlugin.kt | 20 ++++- .../swagger/codegen/SwaggerCodeGenTask.kt | 6 +- .../generator/kotlin/KotlinClientCodegen.kt | 82 +++++-------------- .../swagger/codegen/language/CodegenConst.kt | 3 +- 5 files changed, 45 insertions(+), 68 deletions(-) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 3b670ad..2af332d 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -2,7 +2,7 @@ private object Versions { const val kotlin = "1.5.21" - const val dokka = "1.4.30" + const val dokka = "1.5.0" const val openApiCodegen = "5.2.0" diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt index 61509d2..a3959a5 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt @@ -51,7 +51,12 @@ open class SwaggerCodeGenPlugin : Plugin { if (compileKotlinTask == null || configsExt.forceJava) { project.getTasksByName(COMPILE_JAVA, false).firstOrNull()?.let { compileJava -> configsExt.configs.forEach { taskConfig -> - createGenerator(project, LANGUAGE_JAVA, configsExt, taskConfig)?.let { task -> + createGenerator( + project, + LANGUAGE_JAVA, + configsExt, + taskConfig + )?.let { task -> compileJava.dependsOn(task) } } @@ -70,7 +75,11 @@ open class SwaggerCodeGenPlugin : Plugin { * @param project used to search for compile tasks * @param configsExt swagger gen config */ - private fun autoHookKotlin(project: Project, configsExt: SwaggerCodeGenConfig, isMpp: Boolean = false) { + private fun autoHookKotlin( + project: Project, + configsExt: SwaggerCodeGenConfig, + isMpp: Boolean = false + ) { var hooked = false project.afterEvaluate { if (configsExt.autoHook) { @@ -81,7 +90,12 @@ open class SwaggerCodeGenPlugin : Plugin { } project.getTasksByName(compileTaskName, false).firstOrNull()?.let { compileKotlin -> configsExt.configs.forEach { taskConfig -> - createGenerator(project, LANGUAGE_KOTLIN, configsExt, taskConfig)?.let { task -> + createGenerator( + project, + LANGUAGE_KOTLIN, + configsExt, + taskConfig + )?.let { task -> compileKotlin.dependsOn(task) } } diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt index 7412ed3..22b2a1f 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt @@ -62,12 +62,12 @@ open class SwaggerCodeGenTask : DefaultTask() { //config.isVerbose = true DefaultGenerator() - .opts(config.toClientOptInput()) - .generate() + .opts(config.toClientOptInput()) + .generate() // Clean up the system environment variables that have been set by the code generator. // https://github.com/swagger-api/swagger-codegen/issues/4788 - ctx.workflowSettings.systemProperties.keys.forEach { System.clearProperty(it) } + ctx.workflowSettings.globalProperties.keys.forEach { System.clearProperty(it) } } } } \ No newline at end of file diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt index 5b93c8c..83693e7 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt @@ -35,7 +35,6 @@ import org.openapitools.codegen.CliOption import org.openapitools.codegen.CodegenConstants import org.openapitools.codegen.CodegenModel import org.openapitools.codegen.CodegenOperation -import org.openapitools.codegen.CodegenParameter import org.openapitools.codegen.CodegenProperty import org.openapitools.codegen.CodegenType import org.openapitools.codegen.SupportingFile @@ -83,7 +82,8 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient private var composedVarsNotRequired = false private var arrayAsArrayList = false private var removeOperationParams: List = emptyList() - private val numberDataTypes = arrayOf("kotlin.Short", "kotlin.Int", "kotlin.Long", "kotlin.Float", "kotlin.Double") + private val numberDataTypes = + arrayOf("kotlin.Short", "kotlin.Int", "kotlin.Long", "kotlin.Float", "kotlin.Double") companion object { val logger: Logger = LoggerFactory.getLogger(KotlinClientCodegen::class.java) @@ -236,7 +236,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient val mo = model as Map<*, *> (mo["model"] as CodegenModel?)?.let { setModelVendorExtensions(it) - fixAllOfModelInheritance(it) setComposedVarsAsNotRequired(it) } } @@ -258,7 +257,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient if (operations != null) { (operations["operation"] as List<*>?)?.forEach { operation -> if (operation is CodegenOperation) { - filterOperationParams(operation) if (operation.hasConsumes) { if (isMultipartType(operation.consumes)) { operation.isMultipart = true @@ -343,7 +341,8 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient * @since 2.0.0 */ private fun initSettingsInfrastructure() { - val infrastructureCli = CliOption(GENERATE_INFRASTRUCTURE_API, GENERATE_INFRASTRUCTURE_API_DESCRIPTION) + val infrastructureCli = + CliOption(GENERATE_INFRASTRUCTURE_API, GENERATE_INFRASTRUCTURE_API_DESCRIPTION) val infraOptions = HashMap() infraOptions[GenerateApiType.INFRASTRUCTURE.value] = "Generate Infrastructure API" infraOptions[GenerateApiType.API.value] = "Generate API" @@ -437,7 +436,8 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient * @since 2.0.0 */ private fun initSettingsRemoveOperationParams() { - val removeOperationParamsCli = CliOption(REMOVE_OPERATION_PARAMS, REMOVE_OPERATION_PARAMS_DESCRIPTION) + val removeOperationParamsCli = + CliOption(REMOVE_OPERATION_PARAMS, REMOVE_OPERATION_PARAMS_DESCRIPTION) cliOptions.add(removeOperationParamsCli) } @@ -464,11 +464,12 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient */ private fun addLibraries() { supportedLibraries[ROOM] = - "Platform: Room v1. JSON processing: Moshi 1.9.2." + "Platform: Room v1. JSON processing: Moshi 1.12.0." supportedLibraries[ROOM2] = - "Platform: Room v2 (androidx). JSON processing: Moshi 1.9.2." + "Platform: Room v2 (androidx). JSON processing: Moshi 1.12.0." - val libraryOption = CliOption(CodegenConstants.LIBRARY, "Library template (sub-template) to use") + val libraryOption = + CliOption(CodegenConstants.LIBRARY, "Library template (sub-template) to use") libraryOption.enum = supportedLibraries libraryOption.default = JVM_RETROFIT2 cliOptions.add(libraryOption) @@ -494,7 +495,8 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient private fun processOptsInfrastructure() { var generateInfrastructure = false if (additionalProperties.containsKey(GENERATE_INFRASTRUCTURE_API)) { - generateInfrastructure = convertPropertyToBooleanAndWriteBack(GENERATE_INFRASTRUCTURE_API) + generateInfrastructure = + convertPropertyToBooleanAndWriteBack(GENERATE_INFRASTRUCTURE_API) } if (!generateInfrastructure) { @@ -532,11 +534,13 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } if (additionalProperties.containsKey(GENERATE_PRIMITIVE_TYPE_ALIAS)) { - generatePrimitiveTypeAlias = convertPropertyToBooleanAndWriteBack(GENERATE_PRIMITIVE_TYPE_ALIAS) + generatePrimitiveTypeAlias = + convertPropertyToBooleanAndWriteBack(GENERATE_PRIMITIVE_TYPE_ALIAS) } if (additionalProperties.containsKey(COMPOSED_VARS_NOT_REQUIRED)) { - composedVarsNotRequired = convertPropertyToBooleanAndWriteBack(COMPOSED_VARS_NOT_REQUIRED) + composedVarsNotRequired = + convertPropertyToBooleanAndWriteBack(COMPOSED_VARS_NOT_REQUIRED) } if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)) { @@ -544,11 +548,12 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } if (additionalProperties.containsKey(REMOVE_OPERATION_PARAMS)) { - removeOperationParams = when (val tempArray = additionalProperties[REMOVE_OPERATION_PARAMS]) { - is Array<*> -> tempArray.mapNotNull { mapAnyToStringOrNull(it) } - is List<*> -> tempArray.mapNotNull { mapAnyToStringOrNull(it) } - else -> emptyList() - } + removeOperationParams = + when (val tempArray = additionalProperties[REMOVE_OPERATION_PARAMS]) { + is Array<*> -> tempArray.mapNotNull { mapAnyToStringOrNull(it) } + is List<*> -> tempArray.mapNotNull { mapAnyToStringOrNull(it) } + else -> emptyList() + } } if (additionalProperties.containsKey(ARRAY_AS_ARRAY_LIST)) { @@ -698,29 +703,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient escapePropertyBaseNameLiteral(modelProperties) } - /** - * Fixes allOf model inheritance by removing parent and flattening all variables into the model. - * Related issues: - * - https://github.com/OpenAPITools/openapi-generator/issues/5876 (forced inheritance) - * - https://github.com/OpenAPITools/openapi-generator/pull/5396 (allVars instead of vars) - * - https://github.com/OpenAPITools/openapi-generator/pull/4453 (kotlin inheritance) - * - * TODO: Multiple fixes are planned for 4.3.1 OpenApi Gen. Check if this can be removed after it is released. - * - * @param model to be fixed - * @since 2.1.0 - */ - private fun fixAllOfModelInheritance(model: CodegenModel) { - if (model.allOf != null && model.allOf.isNotEmpty()) { - logger.info("Model: ${model.name} allOf inheritance fixed") - model.parent = null - model.parentModel = null - model.vars = model.allVars.apply { - forEach { it.isInherited = false } - } - } - } - /** * Sets model vars and all vars of Composed schema as not required (nullable). This only works when * [composedVarsNotRequired] is set to true and model has either oneOf or anyOf variables set and not empty. @@ -775,21 +757,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } } - /** - * Filters out operation params if their base name is contained in [removeOperationParams] list. - * - * @param operation to have params filtered - * @since 2.0.0 - */ - private fun filterOperationParams(operation: CodegenOperation) { - if (removeOperationParams.isNotEmpty()) { - operation.allParams.removeIf { removeOperationParams.contains(it.baseName) } - if (operation.allParams.isNotEmpty()) { - operation.allParams.last().hasMore = false - } - } - } - /** * Checks if operation is Multipart or not. * @@ -819,11 +786,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient else -> 0 } } - val iterator: Iterator = operation.allParams.iterator() - while (iterator.hasNext()) { - val param = iterator.next() - param.hasMore = iterator.hasNext() - } } } } diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt index 3b723cd..9bd9cbd 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt @@ -32,7 +32,8 @@ const val ARRAY_AS_ARRAY_LIST_DESCRIPTION = const val HEADER_CLI = "headerCliOptions" const val HEADER_CLI_DESCRIPTION = "Options to generate Header" const val REMOVE_MINUS_TEXT_FROM_HEADER = "removeMinusTextInHeaderProperty" -const val REMOVE_MINUS_TEXT_FROM_HEADER_DESCRIPTION = "Remove minus text from header's property name if it is present." +const val REMOVE_MINUS_TEXT_FROM_HEADER_DESCRIPTION = + "Remove minus text from header's property name if it is present." const val REMOVE_ENDPOINT_STARTING_SLASH = "ignoreEndpointStartingSlash" const val REMOVE_ENDPOINT_STARTING_SLASH_DESCRIPTION = From fd7ac1313440ed9e1a85d939e366613c7ddfb6a0 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Sun, 15 Aug 2021 23:06:59 +0200 Subject: [PATCH 04/14] =?UTF-8?q?=F0=9F=94=96=20Increase=20lib=20version?= =?UTF-8?q?=20to=202.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 2af332d..0848f22 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -11,7 +11,7 @@ private object Versions { const val retrofit = "2.9.0" const val moshi = "1.12.0" - const val swaggerCodeGen = "2.2.3" + const val swaggerCodeGen = "2.3.0" } /* ============================= BUILD-PLUGINS ======================= */ diff --git a/gradle.properties b/gradle.properties index 096eb0b..ba6b674 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.jvmargs=-Xmx1536m -version=2.2.4 +version=2.3.0 From 806afdefae3aab9c95abe1142c8c1d69cb8a8379 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Sun, 15 Aug 2021 23:22:50 +0200 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=90=9B=20Generation=20is=20fixed=20?= =?UTF-8?q?after=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt | 2 ++ .../kotlin-client/libraries/jvm-retrofit2/api.mustache | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt index 22b2a1f..fd52573 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt @@ -2,6 +2,7 @@ package cz.eman.swagger.codegen import org.gradle.api.DefaultTask import org.gradle.api.GradleException +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.openapitools.codegen.DefaultGenerator @@ -21,6 +22,7 @@ open class SwaggerCodeGenTask : DefaultTask() { /** * Ideally this would be marked as an input to this task however I need to fix some things around how it is implemented. */ + @Internal var configuration = CodegenConfigurator() /** diff --git a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache index 4e00f1c..04c207c 100644 --- a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache +++ b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache @@ -40,7 +40,7 @@ interface {{classname}} { {{/prioritizedContentTypes}} {{/formParams}} @{{httpMethod}}("{{#ignoreEndpointStartingSlash}}{{#lambda.ignoreStartingSlash}}{{path}}{{/lambda.ignoreStartingSlash}}{{/ignoreEndpointStartingSlash}}{{^ignoreEndpointStartingSlash}}{{path}}{{/ignoreEndpointStartingSlash}}") - fun {{operationId}}({{^allParams}}){{/allParams}}{{#allParams}}{{>libraries/jvm-retrofit2/queryParams}}{{>libraries/jvm-retrofit2/pathParams}}{{>libraries/jvm-retrofit2/headerParams}}{{>libraries/jvm-retrofit2/bodyParams}}{{>libraries/jvm-retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}){{/hasMore}}{{/allParams}}: Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}> + fun {{operationId}}({{^allParams}}){{/allParams}}{{#allParams}}{{>libraries/jvm-retrofit2/queryParams}}{{>libraries/jvm-retrofit2/pathParams}}{{>libraries/jvm-retrofit2/headerParams}}{{>libraries/jvm-retrofit2/bodyParams}}{{>libraries/jvm-retrofit2/formParams}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/allParams}}: Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}> {{/operation}} } From 2c7cf2ece56e2a2dbe5d024c78530d7bb954519b Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 10:33:55 +0200 Subject: [PATCH 06/14] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20open=20api?= =?UTF-8?q?=20codegen=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- .../kotlin-client/libraries/jvm-retrofit2/queryParams.mustache | 1 - lib/src/main/resources/kotlin-client/opt_datatype.mustache | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/queryParams.mustache delete mode 100644 lib/src/main/resources/kotlin-client/opt_datatype.mustache diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 0848f22..110a354 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -4,7 +4,7 @@ private object Versions { const val kotlin = "1.5.21" const val dokka = "1.5.0" - const val openApiCodegen = "5.2.0" + const val openApiCodegen = "5.2.1" const val junit = "5.7.2" const val kotest = "4.6.1" diff --git a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/queryParams.mustache b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/queryParams.mustache deleted file mode 100644 index 002591e..0000000 --- a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/queryParams.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isQueryParam}}@Query("{{baseName}}") {{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{>opt_datatype}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{>opt_datatype}}{{/collectionFormat}}{{/isQueryParam}} \ No newline at end of file diff --git a/lib/src/main/resources/kotlin-client/opt_datatype.mustache b/lib/src/main/resources/kotlin-client/opt_datatype.mustache deleted file mode 100644 index f6b4e3b..0000000 --- a/lib/src/main/resources/kotlin-client/opt_datatype.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}}{{^required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}} ?= null{{/defaultValue}}{{/required}} From 7a60667f5d1ee56b780e3abc83a5d1e0bb532735 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 10:35:22 +0200 Subject: [PATCH 07/14] =?UTF-8?q?=F0=9F=91=BD=20Update=20codegen=20after?= =?UTF-8?q?=20open=20api=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildSrc/build.gradle.kts | 3 +- .../swagger/codegen/SwaggerCodeGenConfig.kt | 2 +- .../swagger/codegen/SwaggerCodeGenPlugin.kt | 2 +- .../swagger/codegen/SwaggerCodeGenTask.kt | 2 +- .../codegen/SwaggerCodeGenTaskConfig.kt | 2 +- .../generator/kotlin/KotlinClientCodegen.kt | 48 +++--------- .../swagger/codegen/language/CodegenConst.kt | 2 +- .../mustache/IgnoreStartingSlashLambda.kt | 2 +- .../mustache/RemoveMinusTextFromNameLambda.kt | 2 +- .../libraries/jvm-retrofit2/api.mustache | 73 +++++++++++++++---- .../jvm-retrofit2/headerParams.mustache | 2 +- 11 files changed, 78 insertions(+), 62 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index fe94d80..aebe261 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,6 +2,5 @@ plugins { `kotlin-dsl` } repositories { - jcenter() + mavenCentral() } - \ No newline at end of file diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenConfig.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenConfig.kt index dd315c7..bbfbd1c 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenConfig.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenConfig.kt @@ -21,7 +21,7 @@ import org.openapitools.codegen.config.Context * compileJava part does not run but it can be forced using [forceJava]. * - [forceJava] forces java compilation when compileKotlin is present. * - * @author eMan s.r.o. (info@eman.cz) + * @author eMan a.s. (info@eman.cz) */ open class SwaggerCodeGenConfig : CodegenConfigurator(), Cloneable { diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt index a3959a5..05afdc9 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenPlugin.kt @@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory * You can turn off auto hooking by settings [SwaggerCodeGenConfig.autoHook] to false. Java generation is disabled when * Kotlin task exists, you can force generating it using [SwaggerCodeGenConfig.forceJava]. * - * @author eMan s.r.o. (vaclav.souhrada@eman.cz) + * @author eMan a.s. (info@eman.cz) * @since 1.0.0 */ open class SwaggerCodeGenPlugin : Plugin { diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt index fd52573..7979c2e 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTask.kt @@ -11,7 +11,7 @@ import org.openapitools.codegen.config.Context import java.io.File /** - * @author eMan s.r.o. (vaclav.souhrada@eman.cz) + * @author eMan a.s. (info@eman.cz) * @since 1.0.0 */ open class SwaggerCodeGenTask : DefaultTask() { diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTaskConfig.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTaskConfig.kt index dd2428f..d8554c0 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTaskConfig.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/SwaggerCodeGenTaskConfig.kt @@ -11,7 +11,7 @@ package cz.eman.swagger.codegen * @see SwaggerCodeGenConfig * @see SwaggerCodeGenPlugin * @since 2.0.0 - * @author eMan s.r.o. (vaclav.souhrada@eman.cz) + * @author eMan a.s. (info@eman.cz) */ data class SwaggerCodeGenTaskConfig( var inputFileName: String? = null, diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt index 83693e7..3129cf2 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/generator/kotlin/KotlinClientCodegen.kt @@ -30,7 +30,6 @@ import io.swagger.v3.oas.models.media.MapSchema import io.swagger.v3.oas.models.media.ObjectSchema import io.swagger.v3.oas.models.media.Schema import io.swagger.v3.oas.models.media.StringSchema -import org.gradle.util.CollectionUtils.sort import org.openapitools.codegen.CliOption import org.openapitools.codegen.CodegenConstants import org.openapitools.codegen.CodegenModel @@ -44,7 +43,6 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import java.io.File - /** * Kotlin client generator based on [AbstractKotlinCodegen]. Contains libraries and options that are not supported in * default OpenAPI generator (https://github.com/OpenAPITools/openapi-generator). @@ -59,7 +57,6 @@ import java.io.File * Additional generator options: * - `dateLibrary` - By this property you can set date library used to serialize dates and times. * - `generateInfrastructure` - By this property you can enable to generate API infrastructure. - * - `collectionType` - By this property cou can change collection type. * - `emptyDataClasses` - By this property you can enable empty data classes being generated. (Note: it should not pass Kotlin compilation.) * - `composedArrayAsAny` - By this property array of composed is changed to array of object (kotlin.Any). * - `generatePrimitiveTypeAlias` - By this property aliases to primitive are also generated. @@ -70,8 +67,7 @@ import java.io.File * - `arrayAsArrayList` - By this property you can forcefully represent Array as ArrayList which can be useful with complex schemas. Use with caution. * - `ignoreEndpointStartingSlash` - By this property you can ignore a starting slash from an endpoint definition if it is present. * - * @author eMan s.r.o. (vaclav.souhrada@eman.cz) - * @author eMan s.r.o. (david.sucharda@eman.cz) + * @author eMan a.s. (info@eman.cz) * @since 2.0.0 */ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClientCodegen() { @@ -91,7 +87,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient const val ROOM = "room" const val ROOM2 = "room2" - const val VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal" const val VENDOR_EXTENSION_IS_ALIAS = "x-is-alias" const val TYPE_ARRAY_LIST = "ArrayList" @@ -243,7 +238,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } /** - * Post process operations with models to check if the operation is multipart ot not. + * Post process operations with models to check if the operation is multipart or not. * * @since 2.0.0 */ @@ -257,6 +252,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient if (operations != null) { (operations["operation"] as List<*>?)?.forEach { operation -> if (operation is CodegenOperation) { + filterOperationParams(operation) if (operation.hasConsumes) { if (isMultipartType(operation.consumes)) { operation.isMultipart = true @@ -273,8 +269,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } } } - - sortAllParams(operation) } } } @@ -685,8 +679,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } /** - * Sets vendor extensions to the model and it's properties. Extensions added: [markModelAsTypeAlias] and - * [escapePropertyBaseNameLiteral]. + * Sets vendor extensions to the model and it's properties. Extensions added: [markModelAsTypeAlias]. * * @param model to have extensions added * @since 2.0.0 @@ -700,7 +693,6 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient model.readWriteVars + model.parentVars markModelAsTypeAlias(model, modelProperties.size) - escapePropertyBaseNameLiteral(modelProperties) } /** @@ -744,16 +736,14 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient } /** - * Adds vendor extension [VENDOR_EXTENSION_BASE_NAME_LITERAL] which contains escaped base name for use as a string - * literal. + * Filters out operation params if their base name is contained in [removeOperationParams] list. * - * @param modelProperties all properties to have this extension set + * @param operation to have params filtered * @since 2.0.0 */ - private fun escapePropertyBaseNameLiteral(modelProperties: List) { - modelProperties.forEach { property -> - property.vendorExtensions[VENDOR_EXTENSION_BASE_NAME_LITERAL] = - property.baseName.replace("$", "\\$") + private fun filterOperationParams(operation: CodegenOperation) { + if (removeOperationParams.isNotEmpty()) { + operation.allParams.removeIf { removeOperationParams.contains(it.baseName) } } } @@ -768,24 +758,4 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient val firstType = consumes[0] return "multipart/form-data" == firstType["mediaType"] } - - /** - * Sorts all parameters of operation to have path parameters first. Retrofit2 requires to have @Path parameter must - * not come after some parameters that is why they are always first after sorting. - * https://github.com/square/retrofit/blob/master/retrofit/src/main/java/retrofit2/RequestFactory.java#L376 - * - * @param operation to sort all params for - * @since 2.0.2 - */ - private fun sortAllParams(operation: CodegenOperation) { - if (operation.allParams != null) { - sort(operation.allParams) { first, second -> - when { - first.isPathParam && !second.isPathParam -> -1 - !first.isPathParam && second.isPathParam -> 1 - else -> 0 - } - } - } - } } diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt index 9bd9cbd..f2a2af0 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/language/CodegenConst.kt @@ -1,7 +1,7 @@ package cz.eman.swagger.codegen.language /** - * @author eMan s.r.o. (david.sucharda@eman.cz) + * @author eMan a.s. (info@eman.cz) * @since 2.0.0 */ const val GENERATE_INFRASTRUCTURE_API = "generateInfrastructure" diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/IgnoreStartingSlashLambda.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/IgnoreStartingSlashLambda.kt index 06fe459..360eafd 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/IgnoreStartingSlashLambda.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/IgnoreStartingSlashLambda.kt @@ -15,7 +15,7 @@ import java.io.Writer * * For instance if _paramName=/v1/api/nice_ so result will be _v1/api/nice_ * - * @author eMan s.r.o. + * @author eMan a.s. (info@eman.cz) * @since 2.0.0 * @see[Mustache.Lambda] */ diff --git a/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/RemoveMinusTextFromNameLambda.kt b/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/RemoveMinusTextFromNameLambda.kt index 11f0291..d441f74 100644 --- a/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/RemoveMinusTextFromNameLambda.kt +++ b/lib/src/main/kotlin/cz/eman/swagger/codegen/templating/mustache/RemoveMinusTextFromNameLambda.kt @@ -15,7 +15,7 @@ import java.io.Writer * * For instance if _paramName=dogMinusCat_ so result will be _dogCat_ * - * @author eMan s.r.o. + * @author eMan a.s. (info@eman.cz) * @since 2.0.0 * @see[Mustache.Lambda] */ diff --git a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache index 04c207c..7e14e16 100644 --- a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache +++ b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache @@ -2,20 +2,73 @@ package {{apiPackage}} import retrofit2.http.* +{{#doNotUseRxAndCoroutines}} import retrofit2.Call -{{#isMultipart}}import okhttp3.MultipartBody +{{/doNotUseRxAndCoroutines}} +{{^doNotUseRxAndCoroutines}} +{{#useCoroutines}} +import retrofit2.Response +{{/useCoroutines}} +{{/doNotUseRxAndCoroutines}} +import okhttp3.RequestBody +{{#isResponseFile}} +import okhttp3.ResponseBody +{{/isResponseFile}} +{{#isMultipart}} +import okhttp3.MultipartBody {{/isMultipart}} -{{#generateInfrastructure}}import {{packageName}}.infrastructure.* -{{/generateInfrastructure}} +{{^doNotUseRxAndCoroutines}} +{{#useRxJava}} +import rx.Observable +{{/useRxJava}} +{{#useRxJava2}} +import io.reactivex.Single +{{/useRxJava2}} +{{#useRxJava3}} +import io.reactivex.rxjava3.core.Single; +{{/useRxJava3}} +{{^returnType}} +{{#useRxJava2}} +import io.reactivex.Completable +{{/useRxJava2}} +{{#useRxJava3}} +import io.reactivex.rxjava3.core.Completable; +{{/useRxJava3}} +{{/returnType}} +{{/doNotUseRxAndCoroutines}} +{{#threetenbp}} +import org.threeten.bp.LocalDateTime +{{/threetenbp}} + {{#imports}}import {{import}} {{/imports}} -{{#threetenbp}}import org.threeten.bp.LocalDateTime -{{/threetenbp}} {{#operations}} -interface {{classname}} { +{{#x-kotlin-multipart-import}} +{{^isMultipart}} +import okhttp3.MultipartBody +{{/isMultipart}} +{{/x-kotlin-multipart-import}} +{{#operation}} +{{#isResponseFile}} +import okhttp3.ResponseBody + +{{/isResponseFile}} +{{/operation}} +interface {{classname}} { {{#operation}} + /** + * {{summary}} + * {{notes}} + * Responses:{{#responses}} + * - {{code}}: {{{message}}}{{/responses}} + * + {{#allParams}} + * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + {{/allParams}} + * @return {{^useCoroutines}}[Call]<{{/useCoroutines}}{{#isResponseFile}}[ResponseBody]{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}[{{{returnType}}}]{{/returnType}}{{^returnType}}[Unit]{{/returnType}}{{/isResponseFile}}{{^useCoroutines}}>{{/useCoroutines}} + */ {{#isDeprecated}} @Deprecated("This api was deprecated") {{/isDeprecated}} @@ -25,12 +78,6 @@ interface {{classname}} { {{/-first}} {{/formParams}} {{^formParams}} - /** - * {{summary}} - * {{notes}} - {{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams}}* @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} - */ {{#prioritizedContentTypes}} {{#-first}} @Headers({ @@ -40,7 +87,7 @@ interface {{classname}} { {{/prioritizedContentTypes}} {{/formParams}} @{{httpMethod}}("{{#ignoreEndpointStartingSlash}}{{#lambda.ignoreStartingSlash}}{{path}}{{/lambda.ignoreStartingSlash}}{{/ignoreEndpointStartingSlash}}{{^ignoreEndpointStartingSlash}}{{path}}{{/ignoreEndpointStartingSlash}}") - fun {{operationId}}({{^allParams}}){{/allParams}}{{#allParams}}{{>libraries/jvm-retrofit2/queryParams}}{{>libraries/jvm-retrofit2/pathParams}}{{>libraries/jvm-retrofit2/headerParams}}{{>libraries/jvm-retrofit2/bodyParams}}{{>libraries/jvm-retrofit2/formParams}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/allParams}}: Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}> + {{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{^allParams}}){{/allParams}}{{#allParams}}{{>libraries/jvm-retrofit2/queryParams}}{{>libraries/jvm-retrofit2/pathParams}}{{>libraries/jvm-retrofit2/headerParams}}{{>libraries/jvm-retrofit2/bodyParams}}{{>libraries/jvm-retrofit2/formParams}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/allParams}}: {{^doNotUseRxAndCoroutines}}{{#useRxJava}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}>{{/useRxJava}}{{#useRxJava2}}{{#returnType}}Single<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Single<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{#useCoroutines}}Response<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}>{{/useCoroutines}}{{/doNotUseRxAndCoroutines}}{{#doNotUseRxAndCoroutines}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}>{{/doNotUseRxAndCoroutines}} {{/operation}} } diff --git a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/headerParams.mustache b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/headerParams.mustache index edc9034..9258aee 100644 --- a/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/headerParams.mustache +++ b/lib/src/main/resources/kotlin-client/libraries/jvm-retrofit2/headerParams.mustache @@ -1 +1 @@ -{{#isHeaderParam}}@Header("{{baseName}}") {{#removeMinusTextInHeaderProperty}}{{#lambda.removeMinusText}}{{paramName}}{{/lambda.removeMinusText}}{{/removeMinusTextInHeaderProperty}}{{^removeMinusTextInHeaderProperty}}{{paramName}}{{/removeMinusTextInHeaderProperty}}: {{{dataType}}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}@Header("{{baseName}}") {{#removeMinusTextInHeaderProperty}}{{#lambda.removeMinusText}}{{paramName}}{{/lambda.removeMinusText}}{{/removeMinusTextInHeaderProperty}}{{^removeMinusTextInHeaderProperty}}{{paramName}}{{/removeMinusTextInHeaderProperty}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isHeaderParam}} \ No newline at end of file From 1cb175e5755eb7234bccfccd3a9ceb5a0db4291c Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:06:59 +0200 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=90=9B=20Disable=20gradle=20plugin?= =?UTF-8?q?=20autopublish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/build.gradle.kts | 83 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index c801823..70c309b 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -16,6 +16,10 @@ dependencies { testImplementation(Dependencies.TestLibs.kotest) } +gradlePlugin { + isAutomatedPublishing = false +} + tasks.withType { kotlinOptions { jvmTarget = "1.8" @@ -47,56 +51,55 @@ gradlePlugin { } } -afterEvaluate { - publishing { - publications { - create("release") { - artifactId = Artifact.artifactId - from(components["java"]) - artifact(sourcesJar) - artifact(dokkaHtmlJar) - - pom { - name.set("Swagger Codegen") - description.set("A fork of the swagger-codegen by eMan") - url.set("https://github.com/eManPrague/swagger-codegen") - - licenses { - license { - name.set("MIT License") - url.set("https://opensource.org/licenses/MIT") - } +publishing { + publications { + create("release") { + groupId = Artifact.groupId + artifactId = Artifact.artifactId + from(components["java"]) + artifact(sourcesJar) + artifact(dokkaHtmlJar) + + pom { + name.set("Swagger Codegen") + description.set("A fork of the swagger-codegen by eMan") + url.set("https://github.com/eManPrague/swagger-codegen") + + licenses { + license { + name.set("MIT License") + url.set("https://opensource.org/licenses/MIT") } + } - developers { - developer { - name.set("eMan a.s.") - email.set("info@eman.cz") - } + developers { + developer { + name.set("eMan a.s.") + email.set("info@eman.cz") } + } - scm { - connection.set("scm:git:git://github.com/eManPrague/swagger-codegen.git") - developerConnection.set("scm:git:ssh://git@github.com/eManPrague/swagger-codegen.git") - url.set("https://github.com/eManPrague/swagger-codegen") - } + scm { + connection.set("scm:git:git://github.com/eManPrague/swagger-codegen.git") + developerConnection.set("scm:git:ssh://git@github.com/eManPrague/swagger-codegen.git") + url.set("https://github.com/eManPrague/swagger-codegen") + } - issueManagement { - system.set("GitHub Issues") - url.set("https://github.com/eManPrague/swagger-codegen/issues") - } + issueManagement { + system.set("GitHub Issues") + url.set("https://github.com/eManPrague/swagger-codegen/issues") } } } + } - repositories { - maven(url = "https://nexus.eman.cz/repository/maven-public") { - name = "Nexus" + repositories { + maven(url = "https://nexus.eman.cz/repository/maven-public") { + name = "Nexus" - credentials { - username = findPropertyOrNull("nexus.username") - password = findPropertyOrNull("nexus.password") - } + credentials { + username = findPropertyOrNull("nexus.username") + password = findPropertyOrNull("nexus.password") } } } From e102f611bc8b9a3715f348be2bf8677048dab25e Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:11:19 +0200 Subject: [PATCH 09/14] =?UTF-8?q?=F0=9F=90=9B=20Fix=20gradle=20plugin=20au?= =?UTF-8?q?topublish=20disable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/build.gradle.kts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 70c309b..e9088f0 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -17,7 +17,7 @@ dependencies { } gradlePlugin { - isAutomatedPublishing = false + } tasks.withType { @@ -45,10 +45,12 @@ val dokkaHtmlJar by tasks.creating(Jar::class) { gradlePlugin { plugins { register("swagger-codegen-plugin") { - id = "swagger-codegen" + group = Artifact.groupId + id = Artifact.artifactId implementationClass = "cz.eman.swagger.codegen.SwaggerCodeGenPlugin" } } + isAutomatedPublishing = false } publishing { From 09d8061d85b20ee17df914d9b4a621e0b6e1e59a Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:11:59 +0200 Subject: [PATCH 10/14] =?UTF-8?q?=E2=9E=96=20Remove=20mavenLocal=20depende?= =?UTF-8?q?ncy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 915b6a4..2aa7aa9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,6 @@ buildscript { repositories { mavenCentral() - mavenLocal() // TODO: remove - dev only maven("https://nexus.eman.cz/repository/maven-public") } @@ -15,7 +14,6 @@ buildscript { allprojects { repositories { mavenCentral() - mavenLocal() // TODO: remove - dev only maven("https://nexus.eman.cz/repository/maven-public") } From ae2509148a98ff923355bdfe4b004b50ac5ecec2 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:13:33 +0200 Subject: [PATCH 11/14] =?UTF-8?q?=F0=9F=93=9D=20Update=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a1a89f9..a76c6ba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OpenApi 3 Codegen / Swagger -[ ![Download](https://api.bintray.com/packages/emanprague/maven/cz.eman.swagger.codegen/images/download.svg?version=2.2.2) ](https://bintray.com/emanprague/maven/cz.eman.swagger.codegen/2.2.2/link) +[ ![Download](https://nexus.eman.cz/repository/maven-public/cz/eman/swagger/swagger-codegen/2.3.0/swagger-codegen-2.3.0.jar) ](https://nexus.eman.cz/#browse/browse:maven-public:cz%2Feman%2Fswagger%2Fswagger-codegen) The Swagger codegen contains a template-driven engine to generate documentation, code for Java, Kotlin and Android such like Retrofit and Room. It is a fork of the https://github.com/OpenAPITools/openapi-generator with modifications @@ -17,7 +17,7 @@ buildscript { // Kotlin Gradle DSL dependencies { - classpath("cz.eman.swagger:swagger-codegen:2.2.2") + classpath("cz.eman.swagger:swagger-codegen:2.3.0") } } ``` @@ -83,7 +83,6 @@ configure { - `dateLibrary` - By this property you can set date library used to serialize dates and times. - `enumPropertyNaming` - By this property you can change enum property naming style. ("camelCase", "PascalCase", "snake_case", "original", "UPPERCASE") - `generateInfrastructure` - By this property you can enable to generate API infrastructure. - - `collectionType` - By this property cou can change collection type. - `emptyDataClasses` - By this property you can enable empty data classes being generated. (Note: it should not pass Kotlin compilation.) - `generateAliasAsModel` - By this property you can generate alias (array, map) as model. - `composedArrayAsAny` - By this property array of composed is changed to array of object (kotlin.Any). @@ -104,6 +103,6 @@ Other options can be found [here](https://github.com/OpenAPITools/openapi-genera If your OpenApi contains some specific objects for parsing JSON, .... You need add the Moshi dependencies ```kotlin -implementation("com.squareup.moshi:moshi-kotlin:1.9.2") -implementation("com.squareup.moshi:moshi-adapters:1.9.2") +implementation("com.squareup.moshi:moshi-kotlin:1.12.0") +implementation("com.squareup.moshi:moshi-adapters:1.12.0") ``` \ No newline at end of file From 65a7c3532bbf167e1618b41291c6cd24b049dfb8 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:20:19 +0200 Subject: [PATCH 12/14] =?UTF-8?q?=F0=9F=93=9D=20Update=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 441bd5a..e6beb3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ Change Log ========== -## 2.3.0 (TBD) +## 2.3.1 (TBD) + +## 2.3.0 (2021-08-17) ### Updated: - All dependencies. +- OpenApiCodegen to 5.2.1 (https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.2.1) - Gradle to 7.1.1. ### Added: From 5ce364d2635c6a401c5cd69d9b0a6838f54acb9e Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 11:21:20 +0200 Subject: [PATCH 13/14] =?UTF-8?q?=F0=9F=94=A5=20Remove=20unused=20gradlePl?= =?UTF-8?q?ugin=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/build.gradle.kts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index e9088f0..9042de1 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -16,10 +16,6 @@ dependencies { testImplementation(Dependencies.TestLibs.kotest) } -gradlePlugin { - -} - tasks.withType { kotlinOptions { jvmTarget = "1.8" From 23075ba3204251c00ebfce6c577cecd04e151a69 Mon Sep 17 00:00:00 2001 From: David Sucharda Date: Tue, 17 Aug 2021 13:02:51 +0200 Subject: [PATCH 14/14] =?UTF-8?q?=F0=9F=90=9B=20Fix=20compile=20version=20?= =?UTF-8?q?to=201.8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/build.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 9042de1..d2c035f 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -22,6 +22,11 @@ tasks.withType { } } +tasks.withType { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" +} + tasks.withType { useJUnitPlatform() }