OpenAPITools / OpenAPITools/openapi-generator
[BUG][dart-Dio] Inheritance properties are flattened/missing when using json_serializable
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
When generating a Dart Dio client with useJsonSerializable=true, models using inheritance (e.g., via allOf or parent/child relationships) fail to generate the correct constructor structure. Specifically, inherited properties are completely removed from the child model's property lists, preventing the generation of a proper super() call in the constructor.
openapi-generator version
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
- Define a parent model and a child model using allOf in the OpenAPI specification.
- Generate code using the dart-dio generator with the following properties: serializationLibrary=json_serializable and useJsonSerializable=true
- Observe that the child model constructor does not include parameters for parent properties and does not call super().
Related issues/PRs
Suggest a fix
The issue lies in how postProcessAllModels handles inheritance in DartDioClientCodegen.java. When inheritance support is active, the generator's internal property separation logic is failing for the Dart-Dio library:
- parentVars (the list for inherited properties) remains empty for child models.
- Inherited properties are incorrectly stripped from the local vars list without being moved to the parentVars list, leading to data loss in the generator's model state.
The fix requires a manual injection and separation of properties within the postProcessAllModels override to ensure the data structures satisfy Dart's constructor requirements.
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 in DartDioClientCodegen.java, especially the postProcessAllModels override and its inheritance property-separation logic. Reproduce with parent and child models joined by allOf using serializationLibrary=json_serializable and useJsonSerializable=true. Done means inherited properties remain available to the child model and its constructor includes them with a super() call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100