OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Dart] additional properties: fromJson with field of type List<Map<String, Object>> does not generate correctly
Nobody has claimed this yet.
- 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
Incorrect code generation from spec leading to error when attempting to use generated dart code
currently details generates as type List<Map<String, Object>> but then tries to do return Foo(bar: Map.listFromJson(...)) ?? const[] in Foo fromJson(...){...} which throws build error as defined below
Expected details: (json[r'details'] as List).map((e) => e as Map<String, Object>).toList(),
openapi-generator version
6.0.1
OpenAPI declaration file content or url
Ran into an issue with Dart generation from api spec here
"details": {
"additionalProperties": true,
"description": "Further error details",
"type": "object"
},
which generated from the OpenAPI Dart template here and the java generator here
details: Map.listFromJson(json[r'details']) ?? const [],
Understandably, since there is no listFromJson method for the native Map<K, V>, dart throws the following error on build
Error: Member not found: 'Map.listFromJson'.
Generation Details
dart () {
echo "Generating Dart..."
dir="clients/${PROJECT}/dart"
rm -rf "$dir" || true
mkdir -p "$dir"
openapi-generator-cli version-manager set 6.0.1
openapi-generator-cli generate -i "${SPEC_FILE}" \
-g dart \
-o "$dir" \
--git-user-id ory \
--git-repo-id sdk \
--git-host github.com \
-c ./config/client/dart.yml.proc.yml
cp "LICENSE" "clients/${PROJECT}/dart"
}
Steps to reproduce
Generate Ory SDK or any other other spec with addition properties for object
Related issues/PRs
Yes! https://github.com/OpenAPITools/openapi-generator/issues/8029 and https://github.com/OpenAPITools/openapi-generator/issues/12165
Suggest a fix
Not the most confident, but I think it will be a relatively simple fix of the moustache -- not sure why https://github.com/OpenAPITools/openapi-generator/pull/12426 didn't find the issue given the spec in the PR
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the native_class.mustache template and AbstractDartCodegen.java referenced in the issue, then reproduce the generated Dart using the linked Ory specification and the provided generation command. Confirm that fields typed as List<Map<String, Object>> no longer generate a Map.listFromJson call and that the generated Dart builds successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 40/100