Skip to content

Commit f5c6aed

Browse files
feat: add --name-mappings param support for generator
1 parent 72a509b commit f5c6aed

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class Openapi {
7979
/// --type-mappings
8080
final Map<String, String>? typeMappings;
8181

82+
/// sets mappings between OpenAPI spec properties name and generated code
83+
/// var/param/model in the format of OpenAPIName=generatedName.
84+
/// For example: update=updatable,_=underscore.
85+
86+
/// --name-mappings
87+
final Map<String, String>? nameMappings;
88+
8289
/// specifies mappings between a given class and the import that should
8390
/// be used for that class in the format of type=import,type=import. You
8491
/// can also have multiple occurrences of this option.
@@ -119,6 +126,7 @@ class Openapi {
119126
required this.generatorName,
120127
this.outputDirectory,
121128
this.typeMappings,
129+
this.nameMappings,
122130
this.importMappings,
123131
this.reservedWordsMappings,
124132
this.inlineSchemaNameMappings,
@@ -533,8 +541,7 @@ class DioAltProperties extends AdditionalProperties {
533541
final String? pubspecDevDependencies;
534542

535543
const DioAltProperties(
536-
{
537-
this.pubspecDependencies,
544+
{this.pubspecDependencies,
538545
this.pubspecDevDependencies,
539546
this.listAnyOf,
540547
bool allowUnicodeIdentifiers = false,

openapi-generator/lib/src/models/generator_arguments.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class GeneratorArguments {
7070
/// Defines mappings between OpenAPI spec types and generated types.
7171
final Map<String, String>? typeMappings;
7272

73+
/// Defines mappings between OpenAPI spec var/param/model and generated code.
74+
final Map<String, String>? nameMappings;
75+
7376
/// Adds reserved words mappings.
7477
///
7578
/// Supported by [Generator.dio] & [Generator.dioAlt] generators.
@@ -89,6 +92,7 @@ class GeneratorArguments {
8992
generator =
9093
annotations.readPropertyOrDefault('generatorName', Generator.dart),
9194
typeMappings = annotations.readPropertyOrNull('typeMappings'),
95+
nameMappings = annotations.readPropertyOrNull('nameMappings'),
9296
importMappings = annotations.readPropertyOrNull('importMappings'),
9397
reservedWordsMappings =
9498
annotations.readPropertyOrNull('reservedWordsMappings'),
@@ -167,6 +171,8 @@ class GeneratorArguments {
167171
'--import-mappings=${importMappings!.entries.fold('', foldStringMap())}',
168172
if (typeMappings?.isNotEmpty ?? false)
169173
'--type-mappings=${typeMappings!.entries.fold('', foldStringMap())}',
174+
if (nameMappings?.isNotEmpty ?? false)
175+
'--name-mappings=${nameMappings!.entries.fold('', foldStringMap())}',
170176
if (inlineSchemaOptions != null)
171177
'--inline-schema-options=${inlineSchemaOptions!.toMap().entries.fold('', foldStringMap(keyModifier: convertToPropertyKey))}',
172178
if (additionalProperties != null)

0 commit comments

Comments
 (0)