From 11c26d84ba3ad987fd10f0a6d4fda14d9b546b42 Mon Sep 17 00:00:00 2001 From: westse <10818305+westse@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:25:01 -0600 Subject: [PATCH 1/7] Publish sources --- build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index cf775f1..7b3657c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -87,6 +87,8 @@ val jvmVersion: JavaLanguageVersion = JavaLanguageVersion.of(8) java { toolchain.languageVersion.set(jvmVersion) + // Recommended by https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_packaging + withSourcesJar() } tasks.withType { From 8a59f5e0e46fcd5257a8219b5910290364a1c6b8 Mon Sep 17 00:00:00 2001 From: Badr NASS LAHSEN Date: Tue, 22 Aug 2023 13:09:57 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9b06ed..d22d5bd 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ openApi { |----------------------|-------------------------------------------------------------------------------------------------------------------------------------|----------|--------------------------------------| | `apiDocsUrl` | The URL from where the OpenAPI doc can be downloaded | No | http://localhost:8080/v3/api-docs | | `outputDir` | The output directory for the generated OpenAPI file | No | $buildDir - Your project's build dir | -| `outputFileName` | Specifies the output file name and format. Use extension `.yaml` for YAML output, `.json` for JSON output | No | openapi.json | +| `outputFileName` | Specifies the output file name. | No | openapi.json | | `waitTimeInSeconds` | Time to wait in seconds for your Spring Boot application to start, before we make calls to `apiDocsUrl` to download the OpenAPI doc | No | 30 seconds | | `groupedApiMappings` | A map of URLs (from where the OpenAPI docs can be downloaded) to output file names | No | [] | | `customBootRun` | Any bootRun property that you would normal need to start your spring boot application. | No | (N/A) | From 361acfd95106238d6deeb824e91f709d81085739 Mon Sep 17 00:00:00 2001 From: Badr NASS LAHSEN Date: Tue, 22 Aug 2023 13:11:28 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d22d5bd..543ed59 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ openApi { | Parameter | Description | Required | Default | |----------------------|-------------------------------------------------------------------------------------------------------------------------------------|----------|--------------------------------------| -| `apiDocsUrl` | The URL from where the OpenAPI doc can be downloaded | No | http://localhost:8080/v3/api-docs | + | `apiDocsUrl` | The URL from where the OpenAPI doc can be downloaded. If the url ends with `.yaml`, output will YAML format. | No | http://localhost:8080/v3/api-docs | | `outputDir` | The output directory for the generated OpenAPI file | No | $buildDir - Your project's build dir | | `outputFileName` | Specifies the output file name. | No | openapi.json | | `waitTimeInSeconds` | Time to wait in seconds for your Spring Boot application to start, before we make calls to `apiDocsUrl` to download the OpenAPI doc | No | 30 seconds | From fff1285081defcf4864f4c7ec1007ff551b08f4e Mon Sep 17 00:00:00 2001 From: "Badr.NassLahsen" Date: Tue, 22 Aug 2023 13:13:47 +0200 Subject: [PATCH 4/7] docs update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 543ed59..35cdd78 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ openApi { | Parameter | Description | Required | Default | |----------------------|-------------------------------------------------------------------------------------------------------------------------------------|----------|--------------------------------------| - | `apiDocsUrl` | The URL from where the OpenAPI doc can be downloaded. If the url ends with `.yaml`, output will YAML format. | No | http://localhost:8080/v3/api-docs | +| `apiDocsUrl` | The URL from where the OpenAPI doc can be downloaded. If the url ends with `.yaml`, output will YAML format. | No | http://localhost:8080/v3/api-docs | | `outputDir` | The output directory for the generated OpenAPI file | No | $buildDir - Your project's build dir | | `outputFileName` | Specifies the output file name. | No | openapi.json | | `waitTimeInSeconds` | Time to wait in seconds for your Spring Boot application to start, before we make calls to `apiDocsUrl` to download the OpenAPI doc | No | 30 seconds | From 05f50a83ff61b67498fec69503309b8bd45c0e6e Mon Sep 17 00:00:00 2001 From: Clemens Grabmann Date: Tue, 22 Aug 2023 16:49:21 +0200 Subject: [PATCH 5/7] Make task properties completely lazy and move the default values to the conventions of the extension properties. Fixes #117 --- .../openapi/gradle/plugin/OpenApiExtension.kt | 10 ++++++++ .../gradle/plugin/OpenApiGeneratorTask.kt | 23 ++++--------------- .../gradle/plugin/OpenApiGradlePluginTest.kt | 21 +++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiExtension.kt b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiExtension.kt index 136ecb9..47eb8c5 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiExtension.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiExtension.kt @@ -3,6 +3,7 @@ package org.springdoc.openapi.gradle.plugin import org.gradle.api.Action import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.ProjectLayout import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty @@ -11,6 +12,7 @@ import javax.inject.Inject open class OpenApiExtension @Inject constructor( objects: ObjectFactory, + layout: ProjectLayout ) { val apiDocsUrl: Property = objects.property(String::class.java) val outputFileName: Property = objects.property(String::class.java) @@ -21,6 +23,14 @@ open class OpenApiExtension @Inject constructor( val customBootRun: CustomBootRunAction = objects.newInstance(CustomBootRunAction::class.java) + init { + apiDocsUrl.convention(DEFAULT_API_DOCS_URL) + outputFileName.convention(DEFAULT_OPEN_API_FILE_NAME) + outputDir.convention(layout.buildDirectory) + waitTimeInSeconds.convention(DEFAULT_WAIT_TIME_IN_SECONDS) + groupedApiMappings.convention(emptyMap()) + } + fun customBootRun(action: Action) { action.execute(customBootRun) } 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 1a7d6f5..583d099 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -23,7 +23,6 @@ import java.net.HttpURLConnection import java.net.URL import java.time.Duration import java.time.temporal.ChronoUnit.SECONDS -import java.util.* private const val MAX_HTTP_STATUS_CODE = 299 @@ -50,23 +49,11 @@ open class OpenApiGeneratorTask : DefaultTask() { val extension: OpenApiExtension = project.extensions.getByName(EXTENSION_NAME) as OpenApiExtension - // set a default value if not provided - val defaultOutputDir = project.objects.directoryProperty() - defaultOutputDir.set(project.buildDir) - - apiDocsUrl.convention(extension.apiDocsUrl.getOrElse(DEFAULT_API_DOCS_URL)) - outputFileName.convention( - extension.outputFileName.getOrElse( - DEFAULT_OPEN_API_FILE_NAME - ) - ) - groupedApiMappings.convention(extension.groupedApiMappings.getOrElse(emptyMap())) - outputDir.convention(extension.outputDir.getOrElse(defaultOutputDir.get())) - waitTimeInSeconds.convention( - extension.waitTimeInSeconds.getOrElse( - DEFAULT_WAIT_TIME_IN_SECONDS - ) - ) + apiDocsUrl.convention(extension.apiDocsUrl) + outputFileName.convention(extension.outputFileName) + groupedApiMappings.convention(extension.groupedApiMappings) + outputDir.convention(extension.outputDir) + waitTimeInSeconds.convention(extension.waitTimeInSeconds) } @TaskAction 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 192e7b1..805d3c3 100644 --- a/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt +++ b/src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt @@ -102,6 +102,27 @@ class OpenApiGradlePluginTest { assertOpenApiJsonFile(1, specialOutputJsonFileName) } + @Test + fun `accessing the task does not break later configuration`() { + val specialOutputDir = File(projectTestDir, "specialDir") + specialOutputDir.mkdirs() + + buildFile.writeText( + """$baseBuildGradle + tasks.withType(org.springdoc.openapi.gradle.plugin.OpenApiGeneratorTask.class) { + dependsOn("clean") + } + + openApi{ + outputDir = file("${specialOutputDir.toURI().path}") + } + """.trimMargin() + ) + + assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome) + assertOpenApiJsonFile(1, buildDir = specialOutputDir) + } + @Test fun `using properties`() { buildFile.writeText( From b5e25101b059dd4eb6255df3cf4323bc74897329 Mon Sep 17 00:00:00 2001 From: westse <10818305+westse@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:33:09 -0600 Subject: [PATCH 6/7] Allow set waitTimeInSeconds --- .../springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 1a7d6f5..bd24aaf 100644 --- a/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt +++ b/src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt @@ -16,6 +16,7 @@ import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import java.net.ConnectException @@ -40,7 +41,8 @@ open class OpenApiGeneratorTask : DefaultTask() { @get:OutputDirectory val outputDir: DirectoryProperty = project.objects.directoryProperty() - private val waitTimeInSeconds: Property = + @get:Internal + val waitTimeInSeconds: Property = project.objects.property(Int::class.java) init { From 0fa88bcd432317c8de3a192cc50bd3c7d531f315 Mon Sep 17 00:00:00 2001 From: "Badr.NassLahsen" Date: Mon, 16 Oct 2023 16:08:39 +0200 Subject: [PATCH 7/7] prepare for the next release --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7b3657c..c2143fc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.springdoc" -version = "1.7.0" +version = "1.8.0" sonarqube { properties {