openapi_dart icon indicating copy to clipboard operation
openapi_dart copied to clipboard

Using additionalProperties:true results in type error in generated code

Open timalenustmf opened this issue 2 years ago • 0 comments

I have a schema Parent.yml as follows:

type: object
properties:
  test:
    type: object
    additionalProperties: true

After running the build_runner this results in a type error in the generated class ParentTest implements OpenApiContent in the file *.api.openapi.dart

The type error from my IDE reads as follows: The argument type 'Iterable<MapEntry<String, dynamic>>' can't be assigned to the parameter type 'Iterable<MapEntry<String, Object>>'

class ParentTest implements OpenApiContent {
  ParentTest();

  factory ParentTest.fromJson(Map<String, dynamic> jsonMap) =>
      _$PersonGroupsFromJson(jsonMap)
        .._additionalProperties.addEntries(
            jsonMap.entries.where((e) => !const <String>{}.contains(e.key)));

  final Map<String, Object> _additionalProperties = <String, Object>{};

}

This can be solved by changing the type of _additionalProperties to Map<String, dynamic>

timalenustmf avatar May 10 '23 18:05 timalenustmf