[BUG] [Dart] additional properties of type: object doesn't generate with mapCastOfType
Created by: 0xNF
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
The additionalProperties
field, which specified a Map<T1, T2>
in Dart, doesn't generate properly by fields defined by
schema:
type: string
additionalProperties:
type: object
openapi-generator version
6.0.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: "1.1"
title: Dart MappedValue Fail
servers:
- url: 'localhost'
variables:
host:
default: localhost
components:
schemas:
ItemGood:
type: object
properties:
mappedProps:
type: string
additionalProperties:
type: string
ItemBad:
type: object
properties:
mappedProps:
type: string
additionalProperties:
type: object
paths:
/items:
get:
operationId: GetItems
responses:
"200":
description: A list of Items
content:
application/json:
schema:
$ref: '#/components/schemas/ItemGood'
Generation Details
java -jar ..\openapi-generator\modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i .\shadowspec.yaml -g dart -o mapped
Steps to reproduce
After generation, see the ./mapped/lib/model/item_good.dart
and ./mapped/lib/model/item_bad.dart
files.
ItemGood, defined as
ItemGood:
type: object
properties:
mappedProps:
type: string
additionalProperties:
type: string
generates correctly with
return ItemGood(
mappedProps: mapCastOfType<String, String>(json, r'mappedProps') ?? const {},
);
However, ItemBad, defined as
ItemBad:
type: object
properties:
mappedProps:
type: string
additionalProperties:
type: object
generates incorrectly, using mapValueOfType
instead of mapCastOfType
:
return ItemBad(
mappedProps: mapValueOfType<Map<String, Object>>(json, r'mappedProps') ?? const {},
);
Related issues/PRs
Suggest a fix
Maps should try to generate with mapValueOfType in as many situations as possible