OpenAPITools / OpenAPITools/openapi-generator

[BUG][Dart][Dio] Deserialisation of Map<String, List<String>> fails with 'Unknown type on deserialization'

Open
#15,863 5 comments 4 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 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

In my json spec file, I have a map with lists as values. In the generated code, the list somehow loses his type and I get the error that the type is underspecified

openapi-generator version

6.6.0

OpenAPI declaration file content or url

This is the part of the spec file

"schema": {
    "type": "object",
    "additionalProperties": {
        "type": "array",
        "items": {
            "type": "string"
        }
    }
}

And this is the specific type in the generated dart code

specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltList)])
Suggest a fix

I debugged through the generated code and found that the cause of the error is in built_list_serializer.dart. In the deserialize method it checks if the type is underspecified by checking if the type has parameters (specifiedType.parameters.isEmpty), which is empty here. But in my opinion here should be a parameter FullType(String).
That's why I think the specific type of the list is just missing. I would expect something like this

specifiedType: const FullType(BuiltMap, [FullType(String), FullType(BuiltList, [FullType(String)])])
Related issues/PRs

This issue seems to be similar
https://github.com/OpenAPITools/openapi-generator/issues/15573

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 by reproducing the issue from the supplied OpenAPI schema with OpenAPI Generator 6.6.0, then inspect the generated Dart code and built_list_serializer.dart, especially deserialize and its specifiedType check. Compare the emitted FullType for BuiltMap with the expected nested FullType(BuiltList, [FullType(String)]); done means deserialization succeeds without the unknown-type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api
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.