gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
112 stars 29 forks source link

Using `useEnumExtension` flag causes a type error: type 'String' is not a subtype of type 'bool?' #110

Closed mkentos closed 9 months ago

mkentos commented 10 months ago

Description of the bug

Providing the useEnumExtension field to the DioProperties in the @Openapi annotation's field additionalProperties, causes the build_runner to return a type error:

type 'String' is not a subtype of type 'bool?'

It seems that convertToPropertyValue returns a string representation of the provided value (for boolean values, it converts the value to "true" or "false"). So, the map's type passed to the named constructor fromMap is Map<String, String>. In the base class's named constructor AdditionalProperties.fromMap it is expected that there is a boolean value, but there's a string representation. Boolean values should be treated in this constructor the same way as they are in the DioProperties subclass in the fromMap constructor.

Steps to reproduce

Add useEnumExtension: true to the package's example.

Expected behavior

The source generation runs successfully.

Logs

[SEVERE] openapi_generator on lib/api/gen_config.dart (cached):
- There was an error generating the spec.

type 'String' is not a subtype of type 'bool?'
package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart 421:53  new AdditionalProperties.fromMap
package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart 632:15  new DioAltProperties.fromMap
package:openapi_generator/src/extensions/type_methods.dart 130:33                         ReadProperty.readPropertyOrDefault
package:openapi_generator/src/models/generator_arguments.dart 152:44                      new GeneratorArguments
package:openapi_generator/src/openapi_generator_runner.dart 60:22                         OpenapiGenerator.generateForAnnotatedElement
package:source_gen/src/generator_for_annotation.dart 53:30                                GeneratorForAnnotation.generate
package:source_gen/src/builder.dart 355:33                                                _generate

Screenshots

No response

Platform

macOS

Library version

4.13.0

Flutter version

3.13.2

Flutter channel

stable

Additional context

No response

gibahjoe commented 10 months ago

Thank you for taking the time to investigate. I will look into this.

gibahjoe commented 10 months ago

version 4.13.1 has been published. Let me know if it fixes your issue.

mkentos commented 9 months ago

Yep, it works now! Thanks!