Skip to content

Commit

Permalink
Merge pull request #40437 from aloubyansky/sr-openapi-check-root-fs
Browse files Browse the repository at this point in the history
Check whether outputDirectory is the root of the file system before using its parent
  • Loading branch information
phillip-kruger authored May 3, 2024
2 parents 096f6a2 + f327ea0 commit 016bfb5
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -939,14 +938,19 @@ private void storeGeneratedSchema(SmallRyeOpenApiConfig openApiConfig, OutputTar
Path outputDirectory = out.getOutputDirectory();

if (!directory.isAbsolute() && outputDirectory != null) {
directory = Paths.get(outputDirectory.getParent().toString(), directory.toString());
var baseDir = outputDirectory.getParent();
// check if outputDirectory is the root of the filesystem
if (baseDir == null) {
baseDir = outputDirectory;
}
directory = baseDir.resolve(directory);
}

if (!Files.exists(directory)) {
Files.createDirectories(directory);
}

Path file = Paths.get(directory.toString(), "openapi." + format.toString().toLowerCase());
Path file = directory.resolve("openapi." + format.toString().toLowerCase());
if (!Files.exists(file)) {
Files.createFile(file);
}
Expand Down

0 comments on commit 016bfb5

Please sign in to comment.