Skip to content

Commit ba62204

Browse files
Fix: Implement file watching for OpenAPI files in development mode (#1201)
Co-authored-by: Matheus Oliveira da Silva <[email protected]>
1 parent 613401d commit ba62204

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

moqu/deployment/src/main/java/io/quarkiverse/openapi/generator/MoquProjectProcessor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.quarkus.deployment.IsDevelopment;
2121
import io.quarkus.deployment.annotations.BuildProducer;
2222
import io.quarkus.deployment.annotations.BuildStep;
23+
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
2324
import io.quarkus.runtime.util.ClassPathUtils;
2425

2526
public class MoquProjectProcessor {
@@ -68,6 +69,16 @@ MoquProjectBuildItem generate(MoquConfig config) {
6869
}
6970
}
7071

72+
@BuildStep(onlyIf = { IsDevelopment.class })
73+
void watchOpenApiFiles(MoquConfig config, BuildProducer<HotDeploymentWatchedFileBuildItem> watchedPaths)
74+
throws IOException {
75+
ClassPathUtils.consumeAsPaths(config.resourceDir(), path -> {
76+
if (Files.exists(path)) {
77+
watchedPaths.produce(new HotDeploymentWatchedFileBuildItem(path.toString(), Files.isDirectory(path)));
78+
}
79+
});
80+
}
81+
7182
@BuildStep(onlyIf = { IsDevelopment.class })
7283
void consume(Optional<MoquProjectBuildItem> moquProject,
7384
BuildProducer<MoquBuildItem> moquMocks) {

moqu/deployment/src/test/java/io/quarkiverse/openapi/generator/MoquProjectProcessorTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
public class MoquProjectProcessorTest {
1111

12+
private static final String WIREMOCK_MAPPINGS_JSON_PATH = "/q/moqu/json/api/wiremock-mappings.json";
13+
1214
@RegisterExtension
1315
static final QuarkusDevModeTest unitTest = new QuarkusDevModeTest()
1416
.withApplicationRoot(javaArchive -> javaArchive
@@ -38,10 +40,27 @@ void testModeAsDownload() {
3840
@Test
3941
void testModeAsDownloadUsingJson() {
4042
RestAssured.given()
41-
.when().get("/q/moqu/json/api/wiremock-mappings.json")
43+
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
4244
.then()
4345
.statusCode(200)
4446
.body(Matchers.containsString("Alice"))
4547
.log().ifError();
4648
}
49+
50+
@Test
51+
void testDevModeWatchOpenApiFiles() {
52+
RestAssured.given()
53+
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
54+
.then()
55+
.statusCode(200)
56+
.body(Matchers.containsString("80"));
57+
58+
unitTest.modifyResourceFile("openapi/api.json", (content) -> content.replace("80", "77"));
59+
60+
RestAssured.given()
61+
.when().get(WIREMOCK_MAPPINGS_JSON_PATH)
62+
.then()
63+
.statusCode(200)
64+
.body(Matchers.containsString("77"));
65+
}
4766
}

0 commit comments

Comments
 (0)