Skip to content

Commit

Permalink
🔀 Update Codegen to new OpenApiCodegen 5.2.1 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
smidf authored Aug 17, 2021
2 parents 0603dd1 + 23075ba commit c459e71
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 199 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change Log
==========
## 2.2.4 (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:
- Support for Kotlin Multiplatform `kotlinx.datetime` date library
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")
}
}
```
Expand Down Expand Up @@ -83,7 +83,6 @@ configure<SwaggerCodeGenConfig> {
- `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).
Expand All @@ -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")
```
10 changes: 4 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
buildscript {
repositories {
jcenter()
mavenCentral()
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()
maven("https://nexus.eman.cz/repository/maven-public")
}

group = Artifact.groupId
Expand Down
3 changes: 1 addition & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ plugins {
`kotlin-dsl`
}
repositories {
jcenter()
mavenCentral()
}

22 changes: 10 additions & 12 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/* ============================= 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.5.0"

const val openApiCodegen = "4.3.0"
const val openApiCodegen = "5.2.1"

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 swaggerCodeGen = "2.2.0"
const val retrofit = "2.9.0"
const val moshi = "1.12.0"
const val swaggerCodeGen = "2.3.0"
}

/* ============================= BUILD-PLUGINS ======================= */

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 ============================= */
Expand Down Expand Up @@ -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}"
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx1536m

version=2.2.4
version=2.3.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
71 changes: 28 additions & 43 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import com.jfrog.bintray.gradle.BintrayExtension
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-gradle-plugin")
kotlin("jvm")
id("org.jetbrains.dokka")
id("maven-publish")
id("com.jfrog.bintray")
}

dependencies {
Expand All @@ -16,7 +13,7 @@ dependencies {
implementation(Dependencies.Libs.openApiCodegen)

testImplementation(Dependencies.TestLibs.junit)
testImplementation(Dependencies.TestLibs.kotlinTest)
testImplementation(Dependencies.TestLibs.kotest)
}

tasks.withType<KotlinCompile> {
Expand All @@ -25,19 +22,21 @@ tasks.withType<KotlinCompile> {
}
}

val dokka by tasks.getting(DokkaTask::class) {
outputFormat = "html"
outputDirectory = "$buildDir/dokka/html"
configuration {
moduleName = Artifact.artifactId
}
tasks.withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

tasks.withType<Test> {
useJUnitPlatform()
}

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)
Expand All @@ -47,16 +46,18 @@ 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
}

val releasePublication = "release"
publishing {
publications {
create<MavenPublication>(releasePublication) {
create<MavenPublication>("release") {
groupId = Artifact.groupId
artifactId = Artifact.artifactId
from(components["java"])
artifact(sourcesJar)
Expand Down Expand Up @@ -86,39 +87,23 @@ publishing {
developerConnection.set("scm:git:ssh://[email protected]/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" }
}
}
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<BintrayExtension.PackageConfig> {
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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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. ([email protected])
* @author eMan a.s. ([email protected])
*/
open class SwaggerCodeGenConfig : CodegenConfigurator(), Cloneable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
Expand Down Expand Up @@ -51,7 +51,12 @@ open class SwaggerCodeGenPlugin : Plugin<Project> {
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)
}
}
Expand All @@ -70,7 +75,11 @@ open class SwaggerCodeGenPlugin : Plugin<Project> {
* @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) {
Expand All @@ -81,7 +90,12 @@ open class SwaggerCodeGenPlugin : Plugin<Project> {
}
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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,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() {
Expand All @@ -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()

/**
Expand Down Expand Up @@ -62,12 +64,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) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit c459e71

Please sign in to comment.