Skip to content

Commit ede61e0

Browse files
committed
Merge branch 'hiddewie-up-to-date'
2 parents ebd3743 + 4ba8b4e commit ede61e0

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Running the task `generateOpenApiDocs` writes the OpenAPI spec into a `openapi.j
5656
in your project's build dir.
5757

5858
```bash
59-
gradle clean generateOpenApiDocs
59+
gradle generateOpenApiDocs
6060
```
6161

6262
When you run the gradle task **generateOpenApiDocs**, it starts your spring boot
@@ -132,7 +132,7 @@ openApi {
132132

133133
This allows for you to be able to just send in whatever you need when you generate docs.
134134

135-
`./gradlew clean generateOpenApiDocs -Dspring.profiles.active=special`
135+
`./gradlew generateOpenApiDocs -Dspring.profiles.active=special`
136136

137137
and as long as the config looks as follows that value will be passed into the forked
138138
spring boot application.

src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ open class OpenApiGradlePlugin : Plugin<Project> {
5959
fork.onlyIf { needToFork(bootRunTask, customBootRun, fork) }
6060
}
6161

62-
// This is my task. Before I can run it, I have to run the dependent tasks
6362
val openApiTask =
6463
tasks.named(OPEN_API_TASK_NAME, OpenApiGeneratorTask::class.java) {
64+
// This is my task. Before I can run it, I have to run the dependent tasks
6565
it.dependsOn(forkedSpringBoot)
66+
67+
// Ensure the task inputs match those of the original application
68+
it.inputs.files(bootRunTask.get().inputs.files)
6669
}
6770

6871
// The forked task need to be terminated as soon as my task is finished

src/test/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePluginTest.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,60 @@ class OpenApiGradlePluginTest {
386386
assertTrue(servers!!.any { s -> s.get("url").equals("http://$customHost:$customPort") })
387387
}
388388

389+
@Test
390+
fun `running the same build keeps the OpenAPI task up to date`() {
391+
buildFile.writeText(
392+
"""
393+
$baseBuildGradle
394+
openApi {}
395+
""".trimMargin()
396+
)
397+
398+
// Run the first build to generate the OpenAPI file
399+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
400+
assertOpenApiJsonFile(1)
401+
402+
// Rerunning the build does not regenerate the OpenAPI file
403+
assertEquals(TaskOutcome.UP_TO_DATE, openApiDocsTask(runTheBuild()).outcome)
404+
assertOpenApiJsonFile(1)
405+
}
406+
407+
@Test
408+
fun `changing the source code regenerates the OpenAPI`() {
409+
buildFile.writeText(
410+
"""
411+
$baseBuildGradle
412+
openApi {}
413+
""".trimMargin()
414+
)
415+
416+
// Run the first build to generate the OpenAPI file
417+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
418+
assertOpenApiJsonFile(1)
419+
420+
val addedFile = projectTestDir.resolve("src/main/java/com/example/demo/endpoints/AddedController.java")
421+
addedFile.createNewFile()
422+
addedFile.writeText("""
423+
package com.example.demo.endpoints;
424+
425+
import org.springframework.web.bind.annotation.GetMapping;
426+
import org.springframework.web.bind.annotation.RestController;
427+
428+
@RestController
429+
public class AddedController {
430+
431+
@GetMapping("/added")
432+
public String added() {
433+
return "Added file";
434+
}
435+
}
436+
""".trimIndent())
437+
438+
// Run the same build with added source file
439+
assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
440+
assertOpenApiJsonFile(2)
441+
}
442+
389443
private fun runTheBuild(vararg additionalArguments: String = emptyArray()) =
390444
GradleRunner.create()
391445
.withProjectDir(projectTestDir)

0 commit comments

Comments
 (0)