OpenAPITools / OpenAPITools/openapi-generator
[BUG][DART-DIO] Invalid generics for additionalProperties without type
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?
- 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
Model property with additionalProperties: {...} but without type: object producing BuildMap with a single type parameter rather than two, so the code does not compile:
Actual:
BuiltMap<String>? get mapField;
Expected (with explicit type: object):
BuiltMap<String, String>? get mapField;
openapi-generator version
7.21.0. I don't know if it's a regression, I just noticed it wasn't working.
OpenAPI declaration file content or url
openapi: 3.1.0
info:
version: 0.0.0
title: Dart bug
components:
schemas:
InvalidMap:
properties:
mapField:
#type: object
additionalProperties:
type: string
Generation Details
java -jar openapi-generator-cli-7.21.0.jar generate -g dart-dio -o out -i api.yaml
Steps to reproduce
See spec and generation details above.
Related issues/PRs
Suggest a fix
The problem appears to be that variable_type.mustache uses {{baseType}} and {{isMap}} (code). baseType appears to be derived from DefaultCodegen.getPrimitiveType, which returns "map", but isMap appears to be derived from IJsonSchemaValidationProperties.setTypeProperties, which goes down the isAnyType before isMapSchema (code). Adjusting the order in setTypeProperties to be consistent with getPrimitiveType probably fixes the problem.
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 modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/variable_type.mustache and IJsonSchemaValidationProperties.setTypeProperties, then compare that logic with DefaultCodegen.getPrimitiveType. Reproduce the issue using the provided api.yaml and dart-dio generation command. Done means the generated map uses two type parameters and compiles for additionalProperties without an explicit object type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100