forked from loafle/openapi-generator-original
[ci][cli] Allow invoking generate-samples.sh with single file + args (#6609)
This commit is contained in:
parent
28387a09bc
commit
0cb080d5f1
@ -6,21 +6,61 @@ declare cwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
declare root="$(cd "$cwd" && cd ../ && pwd)"
|
||||
declare executable="${root}/modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
echo "# START SCRIPT: $0"
|
||||
echo "This script generates all configs under bin/configs by default."
|
||||
echo "You may generate a targeted script or set of scripts using glob patterns."
|
||||
echo "For example: $0 bin/configs/java-*"
|
||||
echo ""
|
||||
echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
|
||||
|
||||
sleep 5
|
||||
if [ ! -f "$executable" ]; then
|
||||
(cd "${root}" && mvn -B --no-snapshot-updates clean package -DskipTests=true -Dmaven.javadoc.skip=true -Djacoco.skip=true)
|
||||
fi
|
||||
|
||||
export JAVA_OPTS="${JAVA_OPTS} -server -Duser.timezone=UTC"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -ea -server -Duser.timezone=UTC"
|
||||
|
||||
configs=${@:-"${root}"/bin/configs/*.yaml}
|
||||
files=()
|
||||
args=()
|
||||
end_option=false
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
if [ "--" == "$key" ]; then
|
||||
end_option=true
|
||||
else
|
||||
if [[ "$end_option" = true ]]; then
|
||||
args+=("$1")
|
||||
else
|
||||
files+=("$1")
|
||||
fi
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
header="# START SCRIPT: $0
|
||||
This script generates all configs under bin/configs by default.
|
||||
You may generate a targeted script or set of scripts using glob patterns.
|
||||
|
||||
For example:
|
||||
$0 bin/configs/java-*
|
||||
|
||||
You may generate a single config with additional options if you use -- to
|
||||
separate the single config file from the generator arguments.
|
||||
|
||||
For example:
|
||||
$0 bin/configs/java-vertx.yaml -- --global-property debugModels=true
|
||||
|
||||
"
|
||||
|
||||
echo "$header"
|
||||
|
||||
if [[ ${#files[@]} -eq 1 && "${files[0]}" != *'*'* ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2068
|
||||
java ${JAVA_OPTS} -jar "$executable" generate -c ${files[0]} ${args[@]}
|
||||
else
|
||||
echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
|
||||
|
||||
sleep 5
|
||||
|
||||
if [ ${#files[@]} -eq 0 ]; then
|
||||
files=("${root}"/bin/configs/*.yaml)
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2068
|
||||
java ${JAVA_OPTS} -jar "$executable" batch --includes-base-dir "${root}" --fail-fast -- ${files[@]}
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
java $JAVA_OPTS -jar "$executable" batch --includes-base-dir "${root}" --fail-fast -- $configs
|
||||
|
@ -8,11 +8,8 @@ declare root="$(cd "$cwd" && cd ../../ && pwd)"
|
||||
declare executable="${root}/modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
echo "# START SCRIPT: $0"
|
||||
|
||||
echo "IMPORTANT: this script should be run by the CI (e.g. Shippable) to ensure that the 'samples/' folder is up to date."
|
||||
echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
|
||||
|
||||
sleep 5
|
||||
echo ""
|
||||
|
||||
"${root}/bin/generate-samples.sh"
|
||||
|
||||
|
@ -29,6 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.slf4j.Logger;
|
||||
@ -52,8 +53,8 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
description = "where to write the generated files (current dir by default)")
|
||||
private String output = "";
|
||||
|
||||
@Option(name = {"-i", "--input-spec"}, title = "spec file", required = true,
|
||||
description = "location of the OpenAPI spec, as URL or file (required)")
|
||||
@Option(name = {"-i", "--input-spec"}, title = "spec file",
|
||||
description = "location of the OpenAPI spec, as URL or file (required if not loaded via config using -c)")
|
||||
private String spec;
|
||||
|
||||
@Option(name = {"-t", "--template-dir"}, title = "template directory",
|
||||
@ -264,6 +265,10 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
if (configFile != null && configFile.length() > 0) {
|
||||
// attempt to load from configFile
|
||||
configurator = CodegenConfigurator.fromFile(configFile);
|
||||
} else if (StringUtils.isEmpty(spec)) {
|
||||
// if user doesn't pass configFile and does not pass spec, we can fail immediately because one of these two is required to run.
|
||||
System.err.println("[error] Required option '-i' is missing");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// if a config file wasn't specified, or we were unable to read it
|
||||
@ -295,11 +300,9 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
configurator.setInputSpec(spec);
|
||||
}
|
||||
|
||||
// Generator name should not be validated here, as it's validated in toClientOptInput
|
||||
if (isNotEmpty(generatorName)) {
|
||||
configurator.setGeneratorName(generatorName);
|
||||
} else {
|
||||
System.err.println("[error] A generator name (--generator-name / -g) is required.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if (isNotEmpty(output)) {
|
||||
|
@ -466,7 +466,7 @@ public class CodegenConfigurator {
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public Context<?> toContext() {
|
||||
Validate.notEmpty(generatorName, "language/generatorName must be specified");
|
||||
Validate.notEmpty(generatorName, "generator name must be specified");
|
||||
Validate.notEmpty(inputSpec, "input spec must be specified");
|
||||
|
||||
if (isEmpty(templatingEngineName)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user