Skip to content

Using additionalProperties:true results in type error in generated code #12

Open
@timalenustmf

Description

@timalenustmf

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions