Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump generator versions and add support for --name-mappings #149

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 @@ -119,6 +126,7 @@ class Openapi {
required this.generatorName,
this.outputDirectory,
this.typeMappings,
this.nameMappings,
this.importMappings,
this.reservedWordsMappings,
this.inlineSchemaNameMappings,
Expand Down Expand Up @@ -521,14 +529,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;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes? have they been removed from the latest generator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they are removed

/// 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 @@ -541,9 +541,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 @@ -580,18 +578,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 @@ -70,6 +70,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 @@ -89,6 +92,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 @@ -167,6 +171,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
Loading