mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 15:51:38 +00:00
Add schema mappings (#12600)
* add option schema mappings * add schema mapping support, update tests * minor fix * update other generators, tests
This commit is contained in:
@@ -71,6 +71,9 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
|
||||
@Option(name = {"--import-mappings"}, title = "import mappings", description = "displays the default import mappings (types and aliases, and what imports they will pull into the template)")
|
||||
private Boolean importMappings;
|
||||
|
||||
@Option(name = {"--schema-mappings"}, title = "schema mappings", description = "display the schema mappings (none)")
|
||||
private Boolean schemaMappings;
|
||||
|
||||
@Option(name = {"--inline-schema-name-mappings"}, title = "inline schema name mappings", description = "displays the inline schema name mappings (none)")
|
||||
private Boolean inlineSchemaNameMappings;
|
||||
|
||||
@@ -455,6 +458,18 @@ public class ConfigHelp extends OpenApiGeneratorCommand {
|
||||
sb.append(newline);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(schemaMappings)) {
|
||||
sb.append(newline).append("SCHEMA MAPPING").append(newline).append(newline);
|
||||
Map<String, String> map = config.schemaMapping()
|
||||
.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, "Scheme", "Mapped to");
|
||||
sb.append(newline);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(inlineSchemaNameMappings)) {
|
||||
sb.append(newline).append("INLINE SCHEMA NAME MAPPING").append(newline).append(newline);
|
||||
Map<String, String> map = config.inlineSchemaNameMapping()
|
||||
|
||||
@@ -159,6 +159,13 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
+ " You can also have multiple occurrences of this option.")
|
||||
private List<String> importMappings = new ArrayList<>();
|
||||
|
||||
@Option(
|
||||
name = {"--schema-mappings"},
|
||||
title = "schema mappings",
|
||||
description = "specifies mappings between the schema and the new name in the format of schema_a=Cat,schema_b=Bird."
|
||||
+ " You can also have multiple occurrences of this option.")
|
||||
private List<String> schemaMappings = new ArrayList<>();
|
||||
|
||||
@Option(
|
||||
name = {"--inline-schema-name-mappings"},
|
||||
title = "inline schema name mappings",
|
||||
@@ -437,6 +444,7 @@ public class Generate extends OpenApiGeneratorCommand {
|
||||
}
|
||||
applyInstantiationTypesKvpList(instantiationTypes, configurator);
|
||||
applyImportMappingsKvpList(importMappings, configurator);
|
||||
applySchemaMappingsKvpList(schemaMappings, configurator);
|
||||
applyInlineSchemaNameMappingsKvpList(inlineSchemaNameMappings, configurator);
|
||||
applyInlineSchemaNameDefaultsKvpList(inlineSchemaNameDefaults, configurator);
|
||||
applyTypeMappingsKvpList(typeMappings, configurator);
|
||||
|
||||
Reference in New Issue
Block a user