From 28ae74514571e5add2a58bb42b97e81cfc9151dc Mon Sep 17 00:00:00 2001 From: raviu Date: Tue, 8 Nov 2022 16:34:10 +1100 Subject: [PATCH 1/4] Removes khttp --- build.gradle.kts | 1 - .../gradle/plugin/OpenApiGeneratorTask.kt | 24 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ca6a6f0..122c49c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,7 +46,6 @@ publishing { dependencies { implementation(kotlin("reflect")) - implementation("khttp:khttp:1.0.0") implementation("com.google.code.gson:gson:2.8.6") implementation("org.awaitility:awaitility-kotlin:4.0.3") implementation("com.github.psxpaul:gradle-execfork-plugin:0.2.0") diff --git a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt index 19ab113..403a664 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -2,7 +2,6 @@ package org.springdoc.openapi.gradle.plugin import com.google.gson.GsonBuilder import com.google.gson.JsonObject -import khttp.responses.Response import org.awaitility.Durations import org.awaitility.core.ConditionTimeoutException import org.awaitility.kotlin.* @@ -15,6 +14,8 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import java.net.ConnectException +import java.net.HttpURLConnection +import java.net.URL import java.time.Duration import java.time.temporal.ChronoUnit.SECONDS @@ -63,19 +64,28 @@ open class OpenApiGeneratorTask : DefaultTask() { private fun generateApiDocs(url: String, fileName: String) { try { + val isYaml = url.toLowerCase().matches(Regex(".+[./]yaml(/.+)*")) await ignoreException ConnectException::class withPollInterval Durations.ONE_SECOND atMost Duration.of( waitTimeInSeconds.get().toLong(), SECONDS ) until { - val statusCode = khttp.get(url).statusCode + val url = URL(url) + val connection: HttpURLConnection = url.openConnection() as HttpURLConnection + connection.requestMethod = "GET" + connection.connect() + val statusCode = connection.responseCode logger.trace("apiDocsUrl = {} status code = {}", url, statusCode) statusCode < MAX_HTTP_STATUS_CODE } logger.info("Generating OpenApi Docs..") - val response: Response = khttp.get(url) + val url = URL(url) + val connection: HttpURLConnection = url.openConnection() as HttpURLConnection + connection.requestMethod = "GET" + connection.connect() - val isYaml = url.toLowerCase().matches(Regex(".+[./]yaml(/.+)*")) - val apiDocs = if (isYaml) response.text else prettifyJson(response) + val response = String(connection.inputStream.readAllBytes(), Charsets.UTF_8) + + val apiDocs = if (isYaml) response else prettifyJson(response) val outputFile = outputDir.file(fileName).get().asFile outputFile.writeText(apiDocs) @@ -85,9 +95,9 @@ open class OpenApiGeneratorTask : DefaultTask() { } } - private fun prettifyJson(response: Response): String { + private fun prettifyJson(response: String): String { val gson = GsonBuilder().setPrettyPrinting().create() - val googleJsonObject = gson.fromJson(response.text, JsonObject::class.java) + val googleJsonObject = gson.fromJson(response, JsonObject::class.java) return gson.toJson(googleJsonObject) } } From ffcd50ef203b1455484cfc51b257416f32f6efd9 Mon Sep 17 00:00:00 2001 From: Ravi Undupitiya Date: Wed, 9 Nov 2022 07:41:26 +1100 Subject: [PATCH 2/4] Update src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt Shadowing of local variables should generally be avoided Co-authored-by: PascalPensa <88730686+PascalPensa@users.noreply.github.com> --- .../springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt index 403a664..92ee23a 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -69,8 +69,7 @@ open class OpenApiGeneratorTask : DefaultTask() { waitTimeInSeconds.get().toLong(), SECONDS ) until { - val url = URL(url) - val connection: HttpURLConnection = url.openConnection() as HttpURLConnection + val connection: HttpURLConnection = URL(url).openConnection() as HttpURLConnection connection.requestMethod = "GET" connection.connect() val statusCode = connection.responseCode From 9a7db22b8c5ccaf8e8aca48f3778613bd75acc03 Mon Sep 17 00:00:00 2001 From: Ravi Undupitiya Date: Wed, 9 Nov 2022 07:41:37 +1100 Subject: [PATCH 3/4] Update src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt Shadowing of local variables should generally be avoided Co-authored-by: PascalPensa <88730686+PascalPensa@users.noreply.github.com> --- .../springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt index 92ee23a..462ba4d 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -77,8 +77,7 @@ open class OpenApiGeneratorTask : DefaultTask() { statusCode < MAX_HTTP_STATUS_CODE } logger.info("Generating OpenApi Docs..") - val url = URL(url) - val connection: HttpURLConnection = url.openConnection() as HttpURLConnection + val connection: HttpURLConnection = URL(url).openConnection() as HttpURLConnection connection.requestMethod = "GET" connection.connect() From 2c48609a03188414d17e8b9a39834b77c6ff1e29 Mon Sep 17 00:00:00 2001 From: "Badr.NassLahsen" Date: Sat, 12 Nov 2022 14:52:51 +0100 Subject: [PATCH 4/4] Prepare for next release --- README.md | 6 +++--- build.gradle.kts | 2 +- .../springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt | 2 +- .../openapi/gradle/plugin/OpenApiGradlePluginTest.kt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 330570e..65f2ee1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Gradle Groovy DSL ```groovy plugins { id "org.springframework.boot" version "2.7.0" - id "org.springdoc.openapi-gradle-plugin" version "1.4.0" + id "org.springdoc.openapi-gradle-plugin" version "1.5.0" } ``` @@ -35,7 +35,7 @@ Gradle Kotlin DSL ```groovy plugins { id("org.springframework.boot") version "2.7.0" - id("org.springdoc.openapi-gradle-plugin") version "1.4.0" + id("org.springdoc.openapi-gradle-plugin") version "1.5.0" } ``` @@ -133,7 +133,7 @@ The `groupedApiMappings` customization allows you to specify multiple URLs/file 2. Update the version for the plugin to match the current version found in `build.gradle.kts` ``` - id("org.springdoc.openapi-gradle-plugin") version "1.4.0" + id("org.springdoc.openapi-gradle-plugin") version "1.5.0" ``` 3. Add the following to the spring boot apps `settings.gradle` diff --git a/build.gradle.kts b/build.gradle.kts index 122c49c..f35ed5c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.springdoc" -version = "1.4.0" +version = "1.5.0" sonarqube { properties { diff --git a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt index 462ba4d..957ff86 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -81,7 +81,7 @@ open class OpenApiGeneratorTask : DefaultTask() { connection.requestMethod = "GET" connection.connect() - val response = String(connection.inputStream.readAllBytes(), Charsets.UTF_8) + val response = String(connection.inputStream.readBytes(), Charsets.UTF_8) val apiDocs = if (isYaml) response else prettifyJson(response) diff --git a/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt b/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt index 1d5f5e9..4aae9dd 100644 --- a/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt +++ b/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt @@ -43,7 +43,7 @@ class OpenApiGradlePluginTest { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springdoc:springdoc-openapi-webmvc-core:1.4.0' + implementation 'org.springdoc:springdoc-openapi-webmvc-core:1.6.12' } """.trimIndent()