Skip to content

Commit

Permalink
feat(annotations): fixed issue with DioSerializationLibrary and updat…
Browse files Browse the repository at this point in the history
…ed tests

fixes #152
  • Loading branch information
gibahjoe committed Nov 4, 2024
1 parent b0340df commit f2be6b6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ class InputSpec {
const InputSpec.yaml({bool shortExtension = false})
: this(path: 'openapi.y${shortExtension ? '' : 'a'}ml');

Map<String, dynamic> toJsonMap() => {'path': path};

InputSpec.fromMap(Map<String, dynamic> map) : this(path: map['path']);
}

Expand Down Expand Up @@ -545,6 +543,12 @@ class DioAltProperties extends AdditionalProperties {

/// Anything in this will be split on a command added to the dependencies section of your generated code.
/// pubspec-dependencies
///
/// this allows a user to specify additional dependencies required for this artifact, it spits
/// the comma separated list into a proper list, removing empty ones and makes it available in the appropriate
/// vendor-prefix to allow the mustache template to pick it up.
///
/// dependencies should be comma separated
final String? pubspecDependencies;

/// pubspec-dev-dependencies
Expand Down Expand Up @@ -668,8 +672,10 @@ class EnumTransformer {
static DioSerializationLibrary? dioSerializationLibrary(String? name) {
switch (name) {
case 'json_serializable':
case 'jsonSerializable':
return DioSerializationLibrary.jsonSerializable;
case 'built_value':
case 'builtValue':
return DioSerializationLibrary.builtValue;
}
return null;
Expand Down
21 changes: 19 additions & 2 deletions openapi-generator/test/generator_arguments_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ void main() {
expect(args.additionalProperties?.useEnumExtension, isTrue);
expect((args.additionalProperties as DioProperties?)?.nullableFields,
isTrue);
expect((args.additionalProperties as DioProperties).dateLibrary,
DioDateLibrary.core);
expect(
(args.additionalProperties as DioProperties).serializationLibrary,
DioSerializationLibrary.jsonSerializable);

expect(await args.jarArgs, [
'generate',
'-o=${args.outputDirectory}',
Expand Down Expand Up @@ -275,6 +281,16 @@ void main() {
expect(args.shouldGenerateSources, isTrue);
expect(args.updateAnnotatedFile, isTrue);
expect(args.additionalProperties?.useEnumExtension, isTrue);
expect(
(args.additionalProperties as DioAltProperties).pubspecDependencies,
'path: 1.0.0');
expect(
(args.additionalProperties as DioAltProperties)
.pubspecDevDependencies,
'pedantic: 1.0.0');
expect((await args.jarArgs).last, contains('path: 1.0.0'));
expect((await args.jarArgs).last, contains('pedantic: 1.0.0'));
expect(args.additionalProperties.runtimeType, DioAltProperties);

expect(await args.jarArgs, [
'generate',
Expand All @@ -290,8 +306,9 @@ void main() {
'--import-mappings=${args.importMappings!.entries.fold('', foldStringMap())}',
if (args.typeMappings?.isNotEmpty ?? false)
'--type-mappings=${args.typeMappings!.entries.fold('', foldStringMap())}',
if (args.additionalProperties != null)
'--additional-properties=${args.additionalProperties!.toMap().entries.fold('', foldStringMap(keyModifier: convertToPropertyKey))}'
if (args.additionalProperties != null) ...[
'--additional-properties=${(args.additionalProperties as DioAltProperties).toMap().entries.fold('', foldStringMap(keyModifier: convertToPropertyKey))}'
]
]);
});
test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
importMappings: {'package': 'test'},
reservedWordsMappings: {'const': 'final'},
additionalProperties: DioAltProperties(
wrapper: Wrapper.fvm, useEnumExtension: true, pubAuthor: 'test author'),
wrapper: Wrapper.fvm,
useEnumExtension: true,
pubAuthor: 'test author',
pubspecDependencies: 'path: 1.0.0',
pubspecDevDependencies: 'pedantic: 1.0.0',
),
inlineSchemaNameMappings: {'200resp': 'OkResp'},
projectPubspecPath: './test/specs/dart_pubspec.test.yaml',
updateAnnotatedFile: true,
Expand Down
2 changes: 2 additions & 0 deletions openapi-generator/test/specs/dio_properties_test_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
wrapper: Wrapper.fvm,
useEnumExtension: true,
pubAuthor: 'test author',
dateLibrary: DioDateLibrary.core,
serializationLibrary: DioSerializationLibrary.jsonSerializable,
nullableFields: true),
inlineSchemaNameMappings: {'200resp': 'OkResp'},
projectPubspecPath: './test/specs/dart_pubspec.test.yaml',
Expand Down

0 comments on commit f2be6b6

Please sign in to comment.