OpenAPITools / OpenAPITools/openapi-generator
[BUG] [dart-dio] Cannot serialize polymorphic request body
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (https://github.com/OpenAPITools/openapi-generator/issues/6178)
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
- Clone project linked above
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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