Skip to content

[BUG] [dart-dio] Cannot serialize polymorphic request body #16708

@JakeThomson

Description

@JakeThomson
Description

Generated code has a bug when using oneOf for request bodies, you can instantiate the objects fine with their builders, but when passing them into the service for serialization, it throws the following error.

DioException [unknown]: null
Error: type '_Map<String, Object?>' is not a subtype of type 'Iterable<Object?>' in type cast
openapi-generator version

7.0.1

OpenAPI declaration file content or url

I have created a repo specifically to highlight the issue
https://github.com/JakeThomson/openapi-generator-dart-dio-issue

API spec is located here
https://github.com/JakeThomson/openapi-generator-dart-dio-issue/blob/main/api-spec.yaml

Generation Details

I run the following command from the project root
npx @openapitools/openapi-generator-cli generate -i api-spec.yaml -g dart-dio -o ./packages/openapi

Steps to reproduce
  1. Clone project linked above
  2. Run the test located in /tests/failing_test.dart
Related issues/PRs
Suggest a fix

I haven't been able to work out how to fix it, but on the line below is where the crash happens, we are casting a map to an Iterable.

https://github.com/JakeThomson/openapi-generator-dart-dio-issue/blob/4b6a916799e9b3ec20b099e73d181fd0baa6b466/packages/openapi/lib/src/model/test_request.dart#L102

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions