forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin' into 7.0.x
This commit is contained in:
@@ -125,7 +125,7 @@
|
||||
<dependency>
|
||||
<groupId>io.airlift</groupId>
|
||||
<artifactId>airline</artifactId>
|
||||
<version>0.8</version>
|
||||
<version>0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.lambdaj</groupId>
|
||||
@@ -135,12 +135,12 @@
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.10</version>
|
||||
<version>1.2.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.janino</groupId>
|
||||
<artifactId>janino</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
|
||||
@@ -80,6 +80,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
|
||||
@Option(name = {"--inline-schema-name-defaults"}, title = "inline schema name defaults", description = "default values used when naming inline schema name")
|
||||
private Boolean inlineSchemaNameDefaults;
|
||||
|
||||
@Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)")
|
||||
private Boolean openapiNormalizer;
|
||||
|
||||
@Option(name = {"--metadata"}, title = "metadata", description = "displays the generator metadata like the help txt for the generator and generator type etc")
|
||||
private Boolean metadata;
|
||||
|
||||
@@ -494,6 +497,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
|
||||
sb.append(newline);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(openapiNormalizer)) {
|
||||
sb.append(newline).append("OPENAPI NORMALIZER RULES").append(newline).append(newline);
|
||||
Map<String, String> map = config.openapiNormalizer()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> {
|
||||
throw new IllegalStateException(String.format(Locale.ROOT, "Duplicated options! %s and %s", a, b));
|
||||
}, TreeMap::new));
|
||||
writePlainTextFromMap(sb, map, optIndent, optNestedIndent, "OpenAPI normalizer rule", "Set to");
|
||||
sb.append(newline);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(instantiationTypes)) {
|
||||
sb.append(newline).append("INSTANTIATION TYPES").append(newline).append(newline);
|
||||
Map<String, String> map = config.instantiationTypes()
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.stream.Stream;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.config.MergedSpecBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -57,6 +58,13 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
description = "location of the OpenAPI spec, as URL or file (required if not loaded via config using -c)")
|
||||
private String spec;
|
||||
|
||||
@Option(name = "--input-spec-root-directory", title = "Folder with spec(s)",
|
||||
description = "Local root folder with spec file(s)")
|
||||
private String inputSpecRootDirectory;
|
||||
|
||||
@Option(name = "--merged-spec-filename", title = "Name of resulted merged specs file (used along with --input-spec-root-directory option)")
|
||||
private String mergedFileName;
|
||||
|
||||
@Option(name = {"-t", "--template-dir"}, title = "template directory",
|
||||
description = "folder containing the template files")
|
||||
private String templateDir;
|
||||
@@ -177,9 +185,16 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
name = {"--inline-schema-name-defaults"},
|
||||
title = "inline schema name defaults",
|
||||
description = "specifies the default values used when naming inline schema as such array items in the format of arrayItemSuffix=_inner,mapItemSuffix=_value. "
|
||||
+ " ONLY arrayItemSuffix, mapItemSuffix at the moment.")
|
||||
+ " ONLY arrayItemSuffix, mapItemSuffix are supported at the moment. `SKIP_SCHEMA_REUSE=true` is a special value to skip reusing inline schemas.")
|
||||
private List<String> inlineSchemaNameDefaults = new ArrayList<>();
|
||||
|
||||
@Option(
|
||||
name = {"--openapi-normalizer"},
|
||||
title = "OpenAPI normalizer rules",
|
||||
description = "specifies the rules to be enabled in OpenAPI normalizer in the form of RULE_1=true,RULE_2=original."
|
||||
+ " You can also have multiple occurrences of this option.")
|
||||
private List<String> openapiNormalizer = new ArrayList<>();
|
||||
|
||||
@Option(
|
||||
name = {"--server-variables"},
|
||||
title = "server variables",
|
||||
@@ -276,6 +291,12 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
if (StringUtils.isNotBlank(inputSpecRootDirectory)) {
|
||||
spec = new MergedSpecBuilder(inputSpecRootDirectory, StringUtils.isBlank(mergedFileName) ? "_merged_spec" : mergedFileName)
|
||||
.buildMergedSpec();
|
||||
System.out.println("Merge input spec would be used - " + spec);
|
||||
}
|
||||
|
||||
if (logToStderr != null) {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
Stream.of(Logger.ROOT_LOGGER_NAME, "io.swagger", "org.openapitools")
|
||||
@@ -447,6 +468,7 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
applySchemaMappingsKvpList(schemaMappings, configurator);
|
||||
applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator);
|
||||
applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator);
|
||||
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
|
||||
applyTypeMappingsKvpList(typeMappings, configurator);
|
||||
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
|
||||
applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator);
|
||||
|
||||
@@ -52,6 +52,10 @@ public class OptionUtilsTest {
|
||||
doTupleListTest("a=1,=,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
|
||||
doTupleListTest("", emptyPairList());
|
||||
doTupleListTest(null, emptyPairList());
|
||||
doTupleListTest("a=1,b=2,c=\"3,4,5\"",
|
||||
asList(Pair.of("a", "1"), Pair.of("b", "2"),
|
||||
Pair.of("c", "\"3,4,5\"")));
|
||||
|
||||
}
|
||||
|
||||
private static void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
|
||||
|
||||
Reference in New Issue
Block a user