From b3845bc048b854bf7002a3c795a7721b7264d090 Mon Sep 17 00:00:00 2001 From: Clemens Grabmann <6975408+cgrabmann@users.noreply.github.com> Date: Tue, 22 Aug 2023 17:09:40 +0200 Subject: [PATCH] minor: (#173) remove incorrect Json2YamlTask and make the output format configurable (#175) * minor: (#173) remove incorrect Json2YamlTask and make the output format configurable * update docs * add workaround for lazy task configuration of the `generateOpenApiDocs` task --------- Signed-off-by: Clemens Grabmann --- README.md | 32 ++++- .../gradle/api/NamedDomainObjectSetExt.kt | 14 -- .../gradle/api/tasks/TaskCollectionExt.kt | 23 +++- .../springdoc/openapi/Json2YamlTask.kt | 35 ----- .../SpringDocOpenApiConfigureExtension.kt | 12 ++ .../SpringDocOpenApiConfigurePlugin.kt | 121 ++++++++++-------- .../openapi/UnsupportedFormatException.kt | 3 + .../autoconfigure/util/PublicationSupport.kt | 23 ++-- .../springdocopenapi/simple-json/.gitignore | 37 ++++++ .../springdocopenapi/simple-json/build.gradle | 25 ++++ .../simple-json/settings.gradle | 1 + .../SpringDocOpenApiApplication.java | 22 ++++ .../springdocopenapi/simple/build.gradle | 4 - .../SpringDocOpenApiConfigurePluginTest.kt | 18 ++- 14 files changed, 249 insertions(+), 121 deletions(-) delete mode 100644 src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/NamedDomainObjectSetExt.kt delete mode 100644 src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/Json2YamlTask.kt create mode 100644 src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigureExtension.kt create mode 100644 src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/UnsupportedFormatException.kt create mode 100644 src/test/fixtures/springdocopenapi/simple-json/.gitignore create mode 100644 src/test/fixtures/springdocopenapi/simple-json/build.gradle create mode 100644 src/test/fixtures/springdocopenapi/simple-json/settings.gradle create mode 100644 src/test/fixtures/springdocopenapi/simple-json/src/main/java/io/cloudflight/springdocopenapi/SpringDocOpenApiApplication.java rename src/test/kotlin/io/cloudflight/gradle/autoconfigure/{springdocopenapi => springdoc/openapi}/SpringDocOpenApiConfigurePluginTest.kt (70%) diff --git a/README.md b/README.md index c0e9ca2..84ccec0 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,37 @@ plugins { } ``` -The plugin has to be applied to a module that provides a Spring Boot application which the plugin will try to start using a custom Spring Boot run configuration. +The plugin has to be applied to a module that provides a Spring Boot application which the plugin will try to start using a custom Spring Boot run configuration. +This custom run configuration will be started in a dummy working directory to work around a issue currently present in the springdoc plugin. You can find more information [here](https://github.com/cloudflightio/autoconfigure-gradle-plugin/issues/171). +The dummy working directory is created with a task called `createDummyForkedSpringBootWorkingDir`. Various other tasks are automatically configured to depend on this, since they access the dummy directory for some reason. + +
+If you run into some problems with the task, try adding it as a dependency to your task by adding the following. + +```groovy +tasks.named("your-task-name") { + dependsOn("createDummyForkedSpringBootWorkingDir") +} +``` + +If you have multiple tasks that need to depend on it you can do: + +```groovy +def taskList = ["your-task-1", "your-task-2"] +tasks.matching { taskList.contains(it.name) }.all { + dependsOn("createDummyForkedSpringBootWorkingDir") +} +``` +
+ +The springdoc plugin is automatically configured to generate the open-api spec in `YAML` format. If you prefer the `JSON` format you can easily change that by using our extension: +```groovy +import io.cloudflight.gradle.autoconfigure.springdoc.openapi.OpenApiFormat + +openApiConfigure { + fileFormat = OpenApiFormat.JSON +} +``` For generating the OpenAPI document the task `clfGenerateOpenApiDocumentation` has to be run. diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/NamedDomainObjectSetExt.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/NamedDomainObjectSetExt.kt deleted file mode 100644 index 05a0654..0000000 --- a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/NamedDomainObjectSetExt.kt +++ /dev/null @@ -1,14 +0,0 @@ -package io.cloudflight.gradle.autoconfigure.extentions.gradle.api - -import org.gradle.api.DomainObjectCollection -import org.gradle.api.NamedDomainObjectProvider -import org.gradle.api.NamedDomainObjectSet -import kotlin.reflect.KClass - -internal fun NamedDomainObjectSet.withType(klass: KClass): NamedDomainObjectSet = this.withType(klass.java) - -internal fun NamedDomainObjectSet.withType(klass: KClass, configuration: (it: S) -> Unit): DomainObjectCollection = this.withType(klass.java, configuration) - -internal fun NamedDomainObjectSet.named(name: String, klass: KClass): NamedDomainObjectProvider = this.named(name, klass.java) - -internal fun NamedDomainObjectSet.named(name: String, klass: KClass, configuration: (it: S) -> Unit): NamedDomainObjectProvider = this.named(name, klass.java, configuration) diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/tasks/TaskCollectionExt.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/tasks/TaskCollectionExt.kt index c84e770..17e4932 100644 --- a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/tasks/TaskCollectionExt.kt +++ b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/extentions/gradle/api/tasks/TaskCollectionExt.kt @@ -1,11 +1,32 @@ package io.cloudflight.gradle.autoconfigure.extentions.gradle.api.tasks +import org.gradle.api.DomainObjectCollection +import org.gradle.api.NamedDomainObjectProvider +import org.gradle.api.NamedDomainObjectSet import org.gradle.api.Task import org.gradle.api.tasks.TaskCollection import org.gradle.api.tasks.TaskProvider import kotlin.reflect.KClass + +/** + * @see TaskCollection.withType + */ +internal fun TaskCollection.withType(klass: KClass): NamedDomainObjectSet = this.withType(klass.java) + + +/** + * @see TaskCollection.withType + */ +internal fun TaskCollection.withType(klass: KClass, configuration: (it: S) -> Unit): DomainObjectCollection = this.withType(klass.java, configuration) + +/** + * @see TaskCollection.named + */ +internal fun TaskCollection.named(name: String, klass: KClass): TaskProvider = this.named(name, klass.java) + + /** * @see TaskCollection.named */ -internal fun TaskCollection.named(name: String, klass: KClass): TaskProvider = this.named(name, klass.java) \ No newline at end of file +internal fun TaskCollection.named(name: String, klass: KClass, configuration: (it: S) -> Unit): NamedDomainObjectProvider = this.named(name, klass.java, configuration) diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/Json2YamlTask.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/Json2YamlTask.kt deleted file mode 100644 index 83a6595..0000000 --- a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/Json2YamlTask.kt +++ /dev/null @@ -1,35 +0,0 @@ -package io.cloudflight.gradle.autoconfigure.springdoc.openapi - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.jsonObject -import org.gradle.api.DefaultTask -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction -import java.io.File - -abstract class Json2YamlTask : DefaultTask() { - @get:InputFile - val inputFile: RegularFileProperty = project.objects.fileProperty() - - @get:OutputFile - val outputFile: RegularFileProperty = project.objects.fileProperty() - - @TaskAction - fun convert() { - convert(inputFile.get().asFile, outputFile.get().asFile) - } - - internal fun convert(input: File, output: File) { - val json = Json.parseToJsonElement( - input.readText(Charsets.UTF_8) - ) - val jsonMap = json.jsonObject.toMap() - val yamlFactory = YAMLFactory() - val mapper = ObjectMapper(yamlFactory) - mapper.writeValue(output, jsonMap) - } -} diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigureExtension.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigureExtension.kt new file mode 100644 index 0000000..79e1911 --- /dev/null +++ b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigureExtension.kt @@ -0,0 +1,12 @@ +package io.cloudflight.gradle.autoconfigure.springdoc.openapi + +import org.gradle.api.provider.Property + +enum class OpenApiFormat(val extension: String) { + YAML("yaml"), + JSON("json") +} + +abstract class SpringDocOpenApiConfigureExtension { + abstract val fileFormat: Property +} diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePlugin.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePlugin.kt index d2cafe2..ce8fbcd 100644 --- a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePlugin.kt +++ b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePlugin.kt @@ -2,8 +2,8 @@ package io.cloudflight.gradle.autoconfigure.springdoc.openapi import com.github.psxpaul.task.JavaExecFork import io.cloudflight.gradle.autoconfigure.AutoConfigureGradlePlugin.Companion.TASK_GROUP -import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.named -import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.withType +import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.tasks.named +import io.cloudflight.gradle.autoconfigure.extentions.gradle.api.tasks.withType import io.cloudflight.gradle.autoconfigure.java.JavaConfigurePlugin import io.cloudflight.gradle.autoconfigure.util.addApiDocumentationPublication import org.gradle.api.Plugin @@ -14,6 +14,7 @@ import org.gradle.api.tasks.TaskProvider import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springdoc.openapi.gradle.plugin.OpenApiExtension +import org.springdoc.openapi.gradle.plugin.OpenApiGeneratorTask import org.springdoc.openapi.gradle.plugin.OpenApiGradlePlugin import org.springframework.boot.gradle.plugin.SpringBootPlugin import java.net.ServerSocket @@ -25,21 +26,16 @@ class SpringDocOpenApiConfigurePlugin : Plugin { target.plugins.apply(SpringBootPlugin::class.java) target.plugins.apply(OpenApiGradlePlugin::class.java) + val extension = target.extensions.create(EXTENSION_NAME, SpringDocOpenApiConfigureExtension::class.java) + extension.fileFormat.convention(OpenApiFormat.YAML); val openapi = target.extensions.getByType(OpenApiExtension::class.java) - configureOpenApiExtension(openapi, target, target.name) - val openApiTask = target.tasks.named("generateOpenApiDocs") - val json2Yaml: TaskProvider = - target.tasks.register("clfJsonToYaml", Json2YamlTask::class.java) { task -> - with(openapi) { - task.inputFile.set(outputDir.file(outputFileName)) - task.outputFile.set(outputDir.file(outputFileName.map { it.replace(".json", ".yaml") })) - task.dependsOn(openApiTask) - } - } + configureOpenApiExtension(openapi, extension, target, target.name) + val openApiTask = target.tasks.named("generateOpenApiDocs", OpenApiGeneratorTask::class) + makeOpenApiTaskReactive(openApiTask, openapi) val documentationTask = target.tasks.register("clfGenerateOpenApiDocumentation") { it.group = TASK_GROUP - it.dependsOn(json2Yaml) + it.dependsOn(openApiTask) } target.tasks.withType(GenerateMavenPom::class) { @@ -49,9 +45,25 @@ class SpringDocOpenApiConfigurePlugin : Plugin { `setupWorkaroundFor#171`(target, openapi) target.afterEvaluate { - configureJsonDocumentPublishing(openapi, target, openApiTask) - configureYamlDocumentPublishing(target, openapi, json2Yaml) + configureDocumentPublishing(openapi, target, openApiTask) + } + } + + private fun makeOpenApiTaskReactive(openApiTask: TaskProvider, openapi: OpenApiExtension) { + // for some reason the springdoc plugin reads the values from the extension during task initialization and uses that as convention for the task properties, + // which results in some values being incorrect. Because of that we reconfigure the properties conventions to directly use the extension properties. And + // add conventions to the extension properties to the expected default values see: https://github.com/springdoc/springdoc-openapi-gradle-plugin/blob/master/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt#L46 + openApiTask.configure { + it.apiDocsUrl.convention(openapi.apiDocsUrl) + it.outputFileName.convention(openapi.outputFileName) + it.groupedApiMappings.convention(openapi.groupedApiMappings) + it.outputDir.convention(openapi.outputDir) } + + openapi.apiDocsUrl.convention("http://localhost:8080/v3/api-docs") + openapi.outputFileName.convention("openapi.json") + openapi.groupedApiMappings.convention(emptyMap()) + openapi.outputDir.convention(openApiTask.flatMap { it.project.layout.buildDirectory }) } private fun `setupWorkaroundFor#171`(target: Project, openapi: OpenApiExtension) { @@ -72,7 +84,7 @@ class SpringDocOpenApiConfigurePlugin : Plugin { // these tasks also need to depend on the createDirTask since they somehow access the dummy folder as well val dependingTaskNames = setOf("resolveMainClassName", "processResources", "compileKotlin", "compileJava") - target.tasks.matching { dependingTaskNames.contains(it.name) }.configureEach { + target.tasks.matching { dependingTaskNames.contains(it.name) }.all { it.dependsOn(createDirTask) } @@ -83,26 +95,34 @@ class SpringDocOpenApiConfigurePlugin : Plugin { private fun configureOpenApiExtension( openapi: OpenApiExtension, + configureExtension: SpringDocOpenApiConfigureExtension, target: Project, basename: String ) { - with(openapi) { - val serverPort = freeServerSocketPort() - val managementPort = freeServerSocketPort() - - outputDir.set(target.layout.buildDirectory.dir("generated/resources/openapi")) - outputFileName.set("${basename}.json") - apiDocsUrl.set("http://localhost:${serverPort}/v3/api-docs") - customBootRun { - it.workingDir.set(target.layout.buildDirectory.dir("dummyForkedSpringBootWorkingDir")) + val serverPort = freeServerSocketPort() + val managementPort = freeServerSocketPort() + val outputFileName = configureExtension.fileFormat.map { "${basename}.${it.extension}" } + val docsUrl = openapi.outputFileName.map { + val basePath = "http://localhost:${serverPort}/v3/api-docs" + when { + it.endsWith(".${OpenApiFormat.JSON.extension}") -> basePath + it.endsWith(".${OpenApiFormat.YAML.extension}") -> "${basePath}.${OpenApiFormat.YAML.extension}" + else -> throw UnsupportedFormatException("The provided openapi filename '${it}' ends in an unsupported extension. Make sure you use 'yaml' or 'json'") } + } - mapOf( - "--server.port" to serverPort, - "--management.server.port" to managementPort - ).forEach { arg -> - customBootRun.args.add("${arg.key}=${arg.value}") - } + openapi.outputDir.set(target.layout.buildDirectory.dir("generated/resources/openapi")) + openapi.outputFileName.set(outputFileName) + openapi.apiDocsUrl.set(docsUrl) + openapi.customBootRun { + it.workingDir.set(target.layout.buildDirectory.dir("dummyForkedSpringBootWorkingDir")) + } + + mapOf( + "--server.port" to serverPort, + "--management.server.port" to managementPort + ).forEach { arg -> + openapi.customBootRun.args.add("${arg.key}=${arg.value}") } } @@ -113,37 +133,36 @@ class SpringDocOpenApiConfigurePlugin : Plugin { } } - private fun configureJsonDocumentPublishing( + private fun configureDocumentPublishing( openapi: OpenApiExtension, target: Project, - task: TaskProvider, + task: TaskProvider, ) { - addApiDocumentationPublication( - target, - task, - target.artifacts, - openapi.outputDir.get().toString(), - openapi.outputFileName.get().replace(".json", ""), - "json" - ) - } + val format = openapi.outputFileName.map { + if (it.endsWith(".${OpenApiFormat.YAML.extension}")) { + OpenApiFormat.YAML + } else if (it.endsWith(".${OpenApiFormat.JSON.extension}")) { + OpenApiFormat.JSON + } else { + throw UnsupportedFormatException("The provided openapi filename '${it}' ends in an unsupported extension. Make sure you use 'yaml' or 'json'") + } + } + + val basename = openapi.outputFileName.zip(format) { fileName, format -> + fileName.replace(".${format.extension}", "") + } - private fun configureYamlDocumentPublishing( - target: Project, - openapi: OpenApiExtension, - task: TaskProvider - ) { addApiDocumentationPublication( - target, task, target.artifacts, - openapi.outputDir.get().toString(), - openapi.outputFileName.get().replace(".json", ""), - "yaml" + openapi.outputDir, + basename, + format ) } companion object { + const val EXTENSION_NAME = "openApiConfigure" val logger: Logger = LoggerFactory.getLogger(SpringDocOpenApiConfigurePlugin::class.java) } } diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/UnsupportedFormatException.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/UnsupportedFormatException.kt new file mode 100644 index 0000000..1d519cf --- /dev/null +++ b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/UnsupportedFormatException.kt @@ -0,0 +1,3 @@ +package io.cloudflight.gradle.autoconfigure.springdoc.openapi + +class UnsupportedFormatException(message: String) : RuntimeException(message) diff --git a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/PublicationSupport.kt b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/PublicationSupport.kt index 8027c18..10a90da 100644 --- a/src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/PublicationSupport.kt +++ b/src/main/kotlin/io/cloudflight/gradle/autoconfigure/util/PublicationSupport.kt @@ -1,11 +1,13 @@ package io.cloudflight.gradle.autoconfigure.util +import io.cloudflight.gradle.autoconfigure.springdoc.openapi.OpenApiFormat import io.cloudflight.gradle.autoconfigure.swagger.SWAGGER_CLASSIFIER -import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.artifacts.PublishArtifact import org.gradle.api.artifacts.dsl.ArtifactHandler +import org.gradle.api.file.DirectoryProperty import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider internal fun addApiDocumentationPublication( @@ -27,20 +29,23 @@ internal fun addApiDocumentationPublication( } internal fun addApiDocumentationPublication( - project: Project, task: TaskProvider, artifacts: ArtifactHandler, - targetDir: String, - basename: String, - format: String + targetDir: DirectoryProperty, + basename: Provider, + format: Provider ): PublishArtifact { + val fileName = basename.zip(format) { name, format -> + "${name}.${format.extension}" + } + return artifacts.add( JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, - project.file("$targetDir/${basename}.${format}") + targetDir.file(fileName) ) { - it.name = basename + it.name = basename.get() it.classifier = SWAGGER_CLASSIFIER - it.type = format + it.type = format.get().extension it.builtBy(task.get()) } -} \ No newline at end of file +} diff --git a/src/test/fixtures/springdocopenapi/simple-json/.gitignore b/src/test/fixtures/springdocopenapi/simple-json/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/src/test/fixtures/springdocopenapi/simple-json/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/src/test/fixtures/springdocopenapi/simple-json/build.gradle b/src/test/fixtures/springdocopenapi/simple-json/build.gradle new file mode 100644 index 0000000..d369f41 --- /dev/null +++ b/src/test/fixtures/springdocopenapi/simple-json/build.gradle @@ -0,0 +1,25 @@ +import io.cloudflight.gradle.autoconfigure.springdoc.openapi.OpenApiFormat + +plugins { + id 'io.cloudflight.autoconfigure.springdoc-openapi-configure' +} + +group = 'io.cloudflight.gradle' +version = '1.0.0' + +repositories { + mavenCentral() +} + +openApiConfigure { + fileFormat = OpenApiFormat.JSON +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web:2.7.12' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.0' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/src/test/fixtures/springdocopenapi/simple-json/settings.gradle b/src/test/fixtures/springdocopenapi/simple-json/settings.gradle new file mode 100644 index 0000000..34f2f54 --- /dev/null +++ b/src/test/fixtures/springdocopenapi/simple-json/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'springdoc-openapi' diff --git a/src/test/fixtures/springdocopenapi/simple-json/src/main/java/io/cloudflight/springdocopenapi/SpringDocOpenApiApplication.java b/src/test/fixtures/springdocopenapi/simple-json/src/main/java/io/cloudflight/springdocopenapi/SpringDocOpenApiApplication.java new file mode 100644 index 0000000..7b4c37e --- /dev/null +++ b/src/test/fixtures/springdocopenapi/simple-json/src/main/java/io/cloudflight/springdocopenapi/SpringDocOpenApiApplication.java @@ -0,0 +1,22 @@ +package io.cloudflight.springdocopenapi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +public class SpringDocOpenApiApplication { + public static void main(String[] args) { + SpringApplication.run(SpringDocOpenApiApplication.class, args); + } + +} + +@RestController +class Controller { + @GetMapping("/") + public String hello() { + return "hello"; + } +} \ No newline at end of file diff --git a/src/test/fixtures/springdocopenapi/simple/build.gradle b/src/test/fixtures/springdocopenapi/simple/build.gradle index 888fbde..36794cc 100644 --- a/src/test/fixtures/springdocopenapi/simple/build.gradle +++ b/src/test/fixtures/springdocopenapi/simple/build.gradle @@ -17,7 +17,3 @@ dependencies { tasks.named('test') { useJUnitPlatform() } - -tasks.named("forkedSpringBootRun") { - doNotTrackState("We cannot track the state during the test since the working directory is already blocked by the test-executing gradle-process.") -} diff --git a/src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdocopenapi/SpringDocOpenApiConfigurePluginTest.kt b/src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePluginTest.kt similarity index 70% rename from src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdocopenapi/SpringDocOpenApiConfigurePluginTest.kt rename to src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePluginTest.kt index c353c33..183bcd7 100644 --- a/src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdocopenapi/SpringDocOpenApiConfigurePluginTest.kt +++ b/src/test/kotlin/io/cloudflight/gradle/autoconfigure/springdoc/openapi/SpringDocOpenApiConfigurePluginTest.kt @@ -1,4 +1,4 @@ -package io.cloudflight.gradle.autoconfigure.springdocopenapi +package io.cloudflight.gradle.autoconfigure.springdoc.openapi import io.cloudflight.gradle.autoconfigure.test.util.ProjectFixture import io.cloudflight.gradle.autoconfigure.test.util.normalizedOutput @@ -10,21 +10,27 @@ import org.junit.jupiter.api.Test class SpringDocOpenApiConfigurePluginTest { @Test - fun `the openapi document is created in a single module project`(): + fun `the openapi document is created in a single module project with the default configuration`(): Unit = springdocFixture("simple") { - val result = run("clfGenerateOpenApiDocumentation") + val result = run("clean", "clfGenerateOpenApiDocumentation") - assertThat(buildDir().resolve("generated/resources/openapi/springdoc-openapi.json")).exists() assertThat(buildDir().resolve("generated/resources/openapi/springdoc-openapi.yaml")).exists() } + @Test + fun `the openapi document is created in a single module project with the json configuration`(): + Unit = springdocFixture("simple-json") { + val result = run("clean", "clfGenerateOpenApiDocumentation") + + assertThat(buildDir().resolve("generated/resources/openapi/springdoc-openapi.json")).exists() + } + @Test fun `the openapi document is created in a multi module project`(): Unit = springdocFixture("kotlin-springboot-angular") { - val result = run("publishToMavenLocal") + val result = run("clean", "publishToMavenLocal") assertThat(buildDir("skeleton-server").resolve("generated/resources/openapi/custom-openapi.json")).exists() - assertThat(buildDir("skeleton-server").resolve("generated/resources/openapi/custom-openapi.yaml")).exists() } }