Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1434 added repeatable prompt for output path of OpenApi generation #1445

Merged
merged 8 commits into from
Dec 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ private <T extends GenerableArtifact> Tuple<List<Object>, List<T>> preprocess(Co
boolean isJavaInput = extension.endsWith(".java");
boolean isOpenApiInput = extension.endsWith(".yaml") || extension.endsWith(".yml");

// checks for OpenApi input file, output root path and project root being detectable
if (isOpenApiInput && this.outputRootPath == null
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved
&& MavenUtil.getProjectRoot(inputFile.toPath(), false) == null) {

LOG.info(
"No output directory was found. Please specify an output path or just press enter to generate your files to this directory: {}",
inputFile.getAbsoluteFile().getParent());

String userInput = getUserInput();
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved

File preprocessedFile = Paths.get(userInput).toFile();

if (!userInput.isEmpty()) {
while (!ValidationUtils.isOutputRootPathValid(preprocessedFile)) {
File userFolder = Paths.get(getUserInput()).toFile();
preprocessedFile = preprocessInputFile(userFolder);
}
this.outputRootPath = preprocessedFile;
LOG.info("Your output directory was successfully set to: {}",
Paths.get(this.outputRootPath.getAbsolutePath()).toString());
} else {
setOutputRootPath(inputFile.toPath().toAbsolutePath().getParent());
}
}

try {
Object input = cg.read(inputFile.toPath(), StandardCharsets.UTF_8);
List<T> matching = (List<T>) (isIncrements ? cg.getMatchingIncrements(input) : cg.getMatchingTemplates(input));
Expand Down Expand Up @@ -294,7 +319,7 @@ private void setOutputRootPath(Path inputProject) {
"As you did not specify where the code will be generated, we will use the project of your current Input file.");
LOG.debug("Generating to: {}", inputProject);

this.outputRootPath = inputProject.toFile();
this.outputRootPath = inputProject.toFile().getAbsoluteFile();
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down