OpenAPITools / OpenAPITools/openapi-generator

[BUG][DART2] ApiClient deserialize result to type Map<String,Map<String,String>> throws exception

Open
#18,333 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

my swagger has return type of "Map<String,Map<String,String>>"
when using dart2 generate clientapi ,
it use such code to convert the response to Map<String,Map<String,String>>, but throw exception

api.mustache : line 182:

`return {{{returnType}}}.from(await apiClient.deserializeAsync(await _decodeBodyBytes(response), '{{{returnType}}}'),);

the exception is :
type '_Map<String, dynamic>' is not a subtype of type 'Map<String, String>' in type cast

here is minimal code to reproduce this exception :

void main() async {
  final client = ApiClient();
  var networkResponseMap = await client.deserializeAsync('{"k1":{ "k11":"v11","k12":"v12"},"k2":{ "k21":"v21","k22":"v22"}}', 'Map<String,Map<String,String>>');
  var apiResult =  Map<String, Map<String, String >>.from(networkResponseMap);
  print(apiResult);
}

`

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 api.mustache at line 182 and the ApiClient.deserializeAsync call shown in the issue. Run the minimal Dart reproduction using the nested Map<String,Map<String,String>> response, then inspect the generated conversion path. Done means the nested map response deserializes without the reported type-cast exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.