Skip to content

Commit 161f34b

Browse files
committed
Use project root dir to find inputBaseDir
1 parent 8c8f6ca commit 161f34b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
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;
@@ -41,7 +42,8 @@ private Path getInputBaseDir(final Path sourceDir, final Config config) {
4142
.map(inputBaseDir -> {
4243
int srcIndex = sourceDir.toString().lastIndexOf("src");
4344
return Path.of(sourceDir.toString().substring(0, srcIndex), inputBaseDir);
44-
}).orElse(Path.of(sourceDir.toString(), "openapi"));
45+
})
46+
.orElse(sourceDir.resolve("openapi"));
4547
}
4648

4749
@Override
@@ -54,9 +56,19 @@ public boolean shouldRun(Path sourceDir, Config config) {
5456
return specIsPresent;
5557
}
5658

59+
@Override
60+
public Path getInputDirectory() {
61+
return CodeGenProvider.super.getInputDirectory();
62+
}
63+
5764
@Override
5865
public boolean trigger(CodeGenContext context) throws CodeGenException {
59-
final Path openApiDir = getInputBaseDir(context.inputDir(), context.config());
66+
67+
Path projectRoot = findProjectRoot(context.outDir());
68+
69+
final Path openApiDir = projectRoot != null
70+
? getInputBaseDir(projectRoot.resolve("src/main/resources"), context.config())
71+
: getInputBaseDir(context.inputDir(), context.config());
6072

6173
validateOpenApiDir(context, openApiDir);
6274

@@ -122,4 +134,21 @@ private File convertToJSON(Path yamlPath) throws CodeGenException {
122134
throw new CodeGenException("Error converting YAML to JSON", e);
123135
}
124136
}
137+
138+
private static Path findProjectRoot(Path outputDirectory) {
139+
Path currentPath = outputDirectory;
140+
do {
141+
if (Files.exists(currentPath.resolve(Paths.get("src", "main")))
142+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.properties")))
143+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yaml")))
144+
|| Files.exists(currentPath.resolve(Paths.get("config", "application.yml")))) {
145+
return currentPath.normalize();
146+
}
147+
if (currentPath.getParent() != null && Files.exists(currentPath.getParent())) {
148+
currentPath = currentPath.getParent();
149+
} else {
150+
return null;
151+
}
152+
} while (true);
153+
}
125154
}

0 commit comments

Comments
 (0)