Add new option to customize inline model naming convention (#12562)

* temp fix

* add support to customize inline schema naming convention

* Revert "temp fix"

This reverts commit e3bca56bfb.

* minor fix, add tests

* update description
This commit is contained in:
William Cheng
2022-06-11 09:12:22 +08:00
committed by GitHub
parent aeb40ab0ae
commit ee9b9843db
14 changed files with 177 additions and 6 deletions

View File

@@ -74,6 +74,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
@Option(name = {"--inline-schema-name-mappings"}, title = "inline schema name mappings", description = "displays the inline schema name mappings (none)")
private Boolean inlineSchemaNameMappings;
@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 = {"--metadata"}, title = "metadata", description = "displays the generator metadata like the help txt for the generator and generator type etc")
private Boolean metadata;
@@ -464,6 +467,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
sb.append(newline);
}
if (Boolean.TRUE.equals(inlineSchemaNameDefaults)) {
sb.append(newline).append("INLINE SCHEMA NAME DEFAULTS").append(newline).append(newline);
Map<String, String> map = config.inlineSchemaNameDefault()
.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, "Inline scheme naming convention", "Defaulted 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()

View File

@@ -166,6 +166,13 @@ public class Generate extends OpenApiGeneratorCommand {
+ " You can also have multiple occurrences of this option.")
private List<String> inlineSchemaNameMappings = new ArrayList<>();
@Option(
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.")
private List<String> inlineSchemaNameDefaults = new ArrayList<>();
@Option(
name = {"--server-variables"},
title = "server variables",
@@ -431,6 +438,7 @@ public class Generate extends OpenApiGeneratorCommand {
applyInstantiationTypesKvpList(instantiationTypes, configurator);
applyImportMappingsKvpList(importMappings, configurator);
applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator);
applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator);
applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
applyLanguageSpecificPrimitivesCsvList(languageSpecificPrimitives, configurator);