OpenAPITools / OpenAPITools/openapi-generator

[BUG] [dart-dio] OpenAPI Generator Missing Builder Factories for Nested Generic Types. Error: No builder factory for BuiltList..

Open
#22,196 1 comment 1 reaction 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?
  • 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)

openapi-generator version: 7.16.0

Description

The dart-dio generator fails to create necessary builder factories for nested generic types when using additionalProperties with array items, causing runtime deserialization errors.

When an OpenAPI schema defines additionalProperties with array items (resulting in Map<String, List<T>>), the generator creates a BuiltMap<String, BuiltList<T>> type in the model but does not create the required builder factory for BuiltList<T> in serializers.dart.

This causes runtime deserialization failures with:

Error: Deserializing to 'TestItem' failed due to: Deserializing to 'NestedData' failed due to: 
Deserializing to 'BuiltMap<String, BuiltList<FileInfo>>' failed due to: 
Deserializing to 'BuiltList<FileInfo>' failed due to: 
Bad state: No builder factory for BuiltList<FileInfo>. 
Fix by adding one, see SerializersBuilder.addBuilderFactory.

Minimal Reproduction

OpenAPI Spec (test_openapi_minimal.yaml):

openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0
paths: {}
components:
  schemas:
    FileInfo:
      type: object
      properties:
        filename:
          type: string
        size:
          type: integer
        path:
          type: string
    
    NestedData:
      type: object
      properties:
        created_at:
          type: string
          format: date-time
        files_by_category:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/FileInfo'

Generate client:

npx @openapitools/openapi-generator-cli generate \
    -i test_openapi_minimal.yaml \
    -g dart-dio \
    -o test_client \
    --additional-properties=pubName=test_client

Generated serializers.dart (missing factories):

@SerializersFor([
  FileInfo,
  NestedData,
  TestItem,
])
Serializers serializers = (_$serializers.toBuilder()
      ..addBuilderFactory(
        const FullType(BuiltList, [FullType(TestItem)]),
        () => ListBuilder<TestItem>(),
      )
      // ❌ MISSING: BuiltList<FileInfo>
      // ❌ MISSING: BuiltMap<String, BuiltList<FileInfo>>
    ).build();

Attempt to deserialize:

final jsonString = '''
{
  "id": 1,
  "name": "Test Item",
  "nested_data": {
    "created_at": "2025-10-20T12:00:00Z",
    "files_by_category": {
      "documents": [
        {"filename": "doc1.pdf", "size": 1024, "path": "/docs/doc1.pdf"}
      ]
    }
  }
}
''';

final jsonData = jsonDecode(jsonString);
final testItem = standardSerializers.deserializeWith(
  TestItem.serializer,
  jsonData,
); 

Runtime error:

Error: Deserializing to 'TestItem' failed due to: Deserializing to 'NestedData' failed due to: 
Deserializing to 'BuiltMap<String, BuiltList<FileInfo>>' failed due to: 
Deserializing to 'BuiltList<FileInfo>' failed due to: 
Bad state: No builder factory for BuiltList<FileInfo>. 
Fix by adding one, see SerializersBuilder.addBuilderFactory.

Stack trace:
#0      BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:189:11)
#1      BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:125:18)
#2      BuiltJsonSerializers.deserializeWith (package:built_value/src/built_json_serializers.dart:42:12)

Expected Behavior

The generator should automatically detect and add builder factories for nested generic types used in models. At minimum, the following factory is required to fix the error:

Serializers serializers = (_$serializers.toBuilder()
      ..addBuilderFactory(
        const FullType(BuiltList, [FullType(TestItem)]),
        () => ListBuilder<TestItem>(),
      )
      // REQUIRED: Add factory for BuiltList<FileInfo>
      ..addBuilderFactory(
        const FullType(BuiltList, [FullType(FileInfo)]),
        () => ListBuilder<FileInfo>(),
      )
      // OPTIONAL BUT RECOMMENDED: Add factory for the full nested type
      ..addBuilderFactory(
        const FullType(BuiltMap, [
          FullType(String),
          FullType(BuiltList, [FullType(FileInfo)])
        ]),
        () => MapBuilder<String, BuiltList<FileInfo>>(),
      )
    ).build();

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 generating the dart-dio client from the supplied test_openapi_minimal.yaml and inspect the generated serializers.dart. Trace how nested additionalProperties arrays become BuiltMap<String, BuiltList> and where builder factories are emitted. Done means the required nested factories are generated and the shown deserialization no longer reports a missing BuiltList factory.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.