Add enum name mapping to Java generators (#17018)

* add enum name mapping to java generators

* update doc

* update description
This commit is contained in:
William Cheng
2023-11-13 10:53:50 +08:00
committed by GitHub
parent 7e529926a6
commit ec3c484ce9
17 changed files with 163 additions and 2 deletions

View File

@@ -89,6 +89,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
@Option(name = {"--model-name-mappings"}, title = "model name mappings", description = "displays the model name mappings (none)")
private Boolean modelNameMappings;
@Option(name = {"--enum-name-mappings"}, title = "enum name mappings", description = "displays the enum name mappings (none)")
private Boolean enumNameMappings;
@Option(name = {"--openapi-normalizer"}, title = "openapi normalizer rules", description = "displays the OpenAPI normalizer rules (none)")
private Boolean openapiNormalizer;
@@ -542,6 +545,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
sb.append(newline);
}
if (Boolean.TRUE.equals(enumNameMappings)) {
sb.append(newline).append("ENUM NAME MAPPING").append(newline).append(newline);
Map<String, String> map = config.enumNameMapping()
.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, "enum name", "Mapped to");
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()

View File

@@ -209,6 +209,13 @@ public class Generate extends OpenApiGeneratorCommand {
+ " You can also have multiple occurrences of this option.")
private List<String> modelNameMappings = new ArrayList<>();
@Option(
name = {"--enum-name-mappings"},
title = "enum name mappings",
description = "specifies mappings between the enum name and the new name in the format of enum_name=AnotherName,enum_name2=OtherName2."
+ " You can also have multiple occurrences of this option.")
private List<String> enumNameMappings = new ArrayList<>();
@Option(
name = {"--openapi-normalizer"},
title = "OpenAPI normalizer rules",
@@ -492,6 +499,7 @@ public class Generate extends OpenApiGeneratorCommand {
applyNameMappingsKvpList(nameMappings, configurator);
applyParameterNameMappingsKvpList(parameterNameMappings, configurator);
applyModelNameMappingsKvpList(modelNameMappings, configurator);
applyEnumNameMappingsKvpList(enumNameMappings, configurator);
applyOpenAPINormalizerKvpList(openapiNormalizer, configurator);
applyTypeMappingsKvpList(typeMappings, configurator);
applyAdditionalPropertiesKvpList(additionalProperties, configurator);