@@ -2,7 +2,6 @@ package org.springdoc.openapi.gradle.plugin
2
2
3
3
import com.google.gson.GsonBuilder
4
4
import com.google.gson.JsonObject
5
- import khttp.responses.Response
6
5
import org.awaitility.Durations
7
6
import org.awaitility.core.ConditionTimeoutException
8
7
import org.awaitility.kotlin.*
@@ -15,6 +14,8 @@ import org.gradle.api.tasks.Input
15
14
import org.gradle.api.tasks.OutputDirectory
16
15
import org.gradle.api.tasks.TaskAction
17
16
import java.net.ConnectException
17
+ import java.net.HttpURLConnection
18
+ import java.net.URL
18
19
import java.time.Duration
19
20
import java.time.temporal.ChronoUnit.SECONDS
20
21
@@ -63,19 +64,28 @@ open class OpenApiGeneratorTask : DefaultTask() {
63
64
64
65
private fun generateApiDocs (url : String , fileName : String ) {
65
66
try {
67
+ val isYaml = url.toLowerCase().matches(Regex (" .+[./]yaml(/.+)*" ))
66
68
await ignoreException ConnectException ::class withPollInterval Durations .ONE_SECOND atMost Duration .of(
67
69
waitTimeInSeconds.get().toLong(),
68
70
SECONDS
69
71
) until {
70
- val statusCode = khttp.get(url).statusCode
72
+ val url = URL (url)
73
+ val connection: HttpURLConnection = url.openConnection() as HttpURLConnection
74
+ connection.requestMethod = " GET"
75
+ connection.connect()
76
+ val statusCode = connection.responseCode
71
77
logger.trace(" apiDocsUrl = {} status code = {}" , url, statusCode)
72
78
statusCode < MAX_HTTP_STATUS_CODE
73
79
}
74
80
logger.info(" Generating OpenApi Docs.." )
75
- val response: Response = khttp.get(url)
81
+ val url = URL (url)
82
+ val connection: HttpURLConnection = url.openConnection() as HttpURLConnection
83
+ connection.requestMethod = " GET"
84
+ connection.connect()
76
85
77
- val isYaml = url.toLowerCase().matches(Regex (" .+[./]yaml(/.+)*" ))
78
- val apiDocs = if (isYaml) response.text else prettifyJson(response)
86
+ val response = String (connection.inputStream.readAllBytes(), Charsets .UTF_8 )
87
+
88
+ val apiDocs = if (isYaml) response else prettifyJson(response)
79
89
80
90
val outputFile = outputDir.file(fileName).get().asFile
81
91
outputFile.writeText(apiDocs)
@@ -85,9 +95,9 @@ open class OpenApiGeneratorTask : DefaultTask() {
85
95
}
86
96
}
87
97
88
- private fun prettifyJson (response : Response ): String {
98
+ private fun prettifyJson (response : String ): String {
89
99
val gson = GsonBuilder ().setPrettyPrinting().create()
90
- val googleJsonObject = gson.fromJson(response.text , JsonObject ::class .java)
100
+ val googleJsonObject = gson.fromJson(response, JsonObject ::class .java)
91
101
return gson.toJson(googleJsonObject)
92
102
}
93
103
}
0 commit comments