OpenAPITools / OpenAPITools/openapi-generator
[BUG] [dart-dio] Discriminator with multi-layered subclasses causes the subclasses to have error in discriminators
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
When using the dart-dio generator to generate an API with an specs file, which uses multilayered classes with a discriminator at the lowest layer with an discriminator, the generated code tries to map all the values in the middle layer class to all of the subclasses of the lowest layer class.
e.g. classes animal, bird, reptile, turtle, crocodile
The generator runs without an error but there are issues inside of the generated code.
The discriminator mapping inside of the animal class is working fine but the one at reptile uses the same as the one at the animal. This creates a bird and then return it as a bird. This is not allowed in this place because bird is not a subtype of reptile. Since this is an compile error, created by parts of code, which will never be executed, any app using the library is unable is unable to be started.
openapi-generator version
6.5.0, 6.6.0
OpenAPI declaration file content or url
https://gist.github.com/felixmede/058272bdad39fa14ee30f03e65dbd1df
Generation Details
openapi-generator generate -g dart-dio -i openAPI.json -o test
Steps to reproduce
- generate the library
- run flutter pub get && flutter pub run build_runner build
- open test/lib/src/reptile.dart and scroll to deserialise function or try to use the library in another project and try to start that one
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/15386
Suggest a fix
Filter discriminators of subclass to only contain those classes, which are implementing this subclass
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
Generate the library with the linked OpenAPI declaration using the dart-dio command, then inspect test/lib/src/reptile.dart and its deserialise function. Verify that the reptile discriminator mapping includes only valid reptile subclasses and that flutter pub get && flutter pub run build_runner build completes without a compile error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100