File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
src/main/kotlin/org/springdoc/openapi/gradle/plugin Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,21 @@ open class OpenApiGeneratorTask : DefaultTask() {
5959 }
6060 logger.info(" Generating OpenApi Docs.." )
6161 val response: Response = khttp.get(apiDocsUrl.get())
62- val gson = GsonBuilder ().setPrettyPrinting().create();
63- val googleJsonObject = gson.fromJson(response.jsonObject.toString(), JsonObject ::class .java)
62+
63+ val isYaml = apiDocsUrl.get().toLowerCase().endsWith(" .yaml" )
64+ val apiDocs = if (isYaml) response.text else prettifyJson(response)
6465
6566 val outputFile = outputDir.file(outputFileName.get()).get().asFile
66- outputFile.writeText(gson.toJson(googleJsonObject) )
67+ outputFile.writeText(apiDocs )
6768 } catch (e: ConditionTimeoutException ) {
6869 this .logger.error(" Unable to connect to ${apiDocsUrl.get()} waited for ${waitTimeInSeconds.get()} seconds" , e)
6970 throw GradleException (" Unable to connect to ${apiDocsUrl.get()} waited for ${waitTimeInSeconds.get()} seconds" )
7071 }
7172 }
7273
74+ private fun prettifyJson (response : Response ): String {
75+ val gson = GsonBuilder ().setPrettyPrinting().create();
76+ val googleJsonObject = gson.fromJson(response.jsonObject.toString(), JsonObject ::class .java)
77+ return gson.toJson(googleJsonObject)
78+ }
7379}
You can’t perform that action at this time.
0 commit comments