Skip to content

Commit

Permalink
Merge pull request #149 from DmitrySboychakov/master
Browse files Browse the repository at this point in the history
fix: Bump generator versions and add support for --name-mappings
  • Loading branch information
gibahjoe authored Nov 1, 2024
2 parents 639cf5b + f5c6aed commit 2ff3b99
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Openapi {
/// --type-mappings
final Map<String, String>? typeMappings;

/// sets mappings between OpenAPI spec properties name and generated code
/// var/param/model in the format of OpenAPIName=generatedName.
/// For example: update=updatable,_=underscore.
/// --name-mappings
final Map<String, String>? nameMappings;

/// specifies mappings between a given class and the import that should
/// be used for that class in the format of type=import,type=import. You
/// can also have multiple occurrences of this option.
Expand Down Expand Up @@ -129,6 +136,7 @@ class Openapi {
this.outputDirectory,
this.cleanSubOutputDirectory,
this.typeMappings,
this.nameMappings,
this.importMappings,
this.reservedWordsMappings,
this.inlineSchemaNameMappings,
Expand Down Expand Up @@ -532,14 +540,6 @@ class DioProperties extends AdditionalProperties {
}

class DioAltProperties extends AdditionalProperties {
/// Changes the minimum version of Dart to 2.12 and generate null safe code
final bool? nullSafe;

/// nullSafe-array-default
/// Makes even arrays that are not listed as being required in your OpenAPI "required"
/// but making them always generate a default value of []
final bool? nullSafeArrayDefault;

/// This will turn off AnyOf support. This would be a bit weird, but you can do it if you want.
final bool? listAnyOf;

Expand All @@ -552,9 +552,7 @@ class DioAltProperties extends AdditionalProperties {
final String? pubspecDevDependencies;

const DioAltProperties(
{this.nullSafe,
this.nullSafeArrayDefault,
this.pubspecDependencies,
{this.pubspecDependencies,
this.pubspecDevDependencies,
this.listAnyOf,
bool allowUnicodeIdentifiers = false,
Expand Down Expand Up @@ -591,18 +589,13 @@ class DioAltProperties extends AdditionalProperties {
wrapper: wrapper);

DioAltProperties.fromMap(Map<String, dynamic> map)
: nullSafe = map['nullSafe'],
nullSafeArrayDefault = map['nullSafeArrayDefault'],
listAnyOf = map['listAnyOf'],
: listAnyOf = map['listAnyOf'],
pubspecDependencies = map['pubspecDependencies'],
pubspecDevDependencies = map['pubspecDevDependencies'],
super.fromMap(map);

Map<String, dynamic> toMap() => Map.from(super.toMap())
..addAll({
if (nullSafe != null) 'nullSafe': nullSafe,
if (nullSafeArrayDefault != null)
'nullSafeArrayDefault': nullSafeArrayDefault,
if (listAnyOf != null) 'listAnyOf': listAnyOf,
if (pubspecDependencies != null)
'pubspecDependencies': pubspecDependencies,
Expand Down
Binary file modified openapi-generator-cli/lib/openapi-generator.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-cli</artifactId>
<version>7.2.0</version>
<version>7.7.0</version>
</dependency>

<dependency>
<groupId>com.bluetrainsoftware.maven</groupId>
<artifactId>openapi-dart-generator</artifactId>
<version>7.2</version>
<version>8.1</version>
</dependency>
</dependencies>
</project>
Expand Down
6 changes: 6 additions & 0 deletions openapi-generator/lib/src/models/generator_arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class GeneratorArguments {
/// Defines mappings between OpenAPI spec types and generated types.
final Map<String, String>? typeMappings;

/// Defines mappings between OpenAPI spec var/param/model and generated code.
final Map<String, String>? nameMappings;

/// Adds reserved words mappings.
///
/// Supported by [Generator.dio] & [Generator.dioAlt] generators.
Expand All @@ -97,6 +100,7 @@ class GeneratorArguments {
generator =
annotations.readPropertyOrDefault('generatorName', Generator.dart),
typeMappings = annotations.readPropertyOrNull('typeMappings'),
nameMappings = annotations.readPropertyOrNull('nameMappings'),
importMappings = annotations.readPropertyOrNull('importMappings'),
reservedWordsMappings =
annotations.readPropertyOrNull('reservedWordsMappings'),
Expand Down Expand Up @@ -179,6 +183,8 @@ class GeneratorArguments {
'--import-mappings=${importMappings!.entries.fold('', foldStringMap())}',
if (typeMappings?.isNotEmpty ?? false)
'--type-mappings=${typeMappings!.entries.fold('', foldStringMap())}',
if (nameMappings?.isNotEmpty ?? false)
'--name-mappings=${nameMappings!.entries.fold('', foldStringMap())}',
if (inlineSchemaOptions != null)
'--inline-schema-options=${inlineSchemaOptions!.toMap().entries.fold('', foldStringMap(keyModifier: convertToPropertyKey))}',
if (additionalProperties != null)
Expand Down

0 comments on commit 2ff3b99

Please sign in to comment.