Skip to content

Commit 2262f83

Browse files
committed
Use project root dir to find inputBaseDir
1 parent 8c8f6ca commit 2262f83

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

server/deployment/src/main/java/io/quarkiverse/openapi/server/generator/deployment/codegen/ApicurioOpenApiServerCodegen.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.nio.file.Files;
55
import java.nio.file.Path;
6+
import java.nio.file.Paths;
67
import java.util.Arrays;
78

89
import org.eclipse.microprofile.config.Config;
@@ -42,6 +43,7 @@ private Path getInputBaseDir(final Path sourceDir, final Config config) {
4243
int srcIndex = sourceDir.toString().lastIndexOf("src");
4344
return Path.of(sourceDir.toString().substring(0, srcIndex), inputBaseDir);
4445
}).orElse(Path.of(sourceDir.toString(), "openapi"));
46+
4547
}
4648

4749
@Override
@@ -56,7 +58,12 @@ public boolean shouldRun(Path sourceDir, Config config) {
5658

5759
@Override
5860
public boolean trigger(CodeGenContext context) throws CodeGenException {
59-
final Path openApiDir = getInputBaseDir(context.inputDir(), context.config());
61+
62+
Path projectRoot = findProjectRoot(context.outDir());
63+
64+
final Path openApiDir = projectRoot != null
65+
? getInputBaseDir(projectRoot.resolve("src/main/resources"), context.config())
66+
: getInputBaseDir(context.inputDir(), context.config());
6067

6168
validateOpenApiDir(context, openApiDir);
6269

@@ -122,4 +129,21 @@ private File convertToJSON(Path yamlPath) throws CodeGenException {
122129
throw new CodeGenException("Error converting YAML to JSON", e);
123130
}
124131
}
132+
133+
private static Path findProjectRoot(Path outputDirectory) {
134+
Path currentPath = outputDirectory;
135+
do {
136+
if (Files.exists(currentPath.resolve(Paths.get("src", "main")))
137+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.properties")))
138+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yaml")))
139+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yml")))) {
140+
return currentPath.normalize();
141+
}
142+
if (currentPath.getParent() != null && Files.exists(currentPath.getParent())) {
143+
currentPath = currentPath.getParent();
144+
} else {
145+
return null;
146+
}
147+
} while (true);
148+
}
125149
}

0 commit comments

Comments
 (0)