OpenAPITools / OpenAPITools/openapi-generator

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

Open
#16,708 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked api-spec.yaml and /tests/failing_test.dart, then inspect the generated packages/openapi/lib/src/model/test_request.dart around line 102. Reproduce the failure with the documented dart-dio generation command and verify that polymorphic request bodies serialize without the reported cast error.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.