OpenAPITools / OpenAPITools/openapi-generator

[BUG] dart-dio generator has basic deserialization issues

Open
#13,568 1 comment 2 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

Bug Report Checklist
  • 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 (example)
Description

As far as I can tell, the description of the /users/latest endpoint 200 response is correct, it's just the User model... and the generator can't deserialize it because it's basically trying to cast a Map into an Iterable

DioError [DioErrorType.other]: Deserializing '{id: ba2be130-dece-4a5c-ac94-771fe70f9f7e, firstName: test, lastName: test, i...' to 'User' failed due to: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<Object?>' in type cast #0 BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:178:11) #1 BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)

openapi-generator version

6.2.0

OpenAPI declaration file content or url
{"openapi":"3.0.0","paths":{"/users/latest":{"get":{"operationId":"UserController_getLatestUser","summary":"","description":"","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/User"}}}}},"tags":["Users"],"security":[{"bearer":[]}]}},"/users":{"post":{"operationId":"UserController_createUser","summary":"","description":"","parameters":[],"responses":{"201":{"description":""}},"tags":["Users"],"security":[{"bearer":[]}]}}},"info":{"title":"api","description":"","version":"0.0.1","contact":{}},"tags":[],"servers":[],"components":{"schemas":{"User":{"type":"object","properties":{"id":{"type":"string"},"firstName":{"type":"string"},"lastName":{"type":"string"},"isActive":{"type":"boolean"}},"required":["id","firstName","lastName","isActive"]}}}}
Generation Details
Steps to reproduce

openapi-generator generate -g dart-dio -i http://localhost:3000/swagger-ui-json -o generated

Related issues/PRs
Suggest a fix

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

Reproduce the issue with the supplied OpenAPI declaration and the openapi-generator generate -g dart-dio command. Inspect the generated Dart client's handling of the User response and the deserialization path referenced in built_json_serializers.dart; done means the object response deserializes without the Map-to-Iterable 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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.