OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.89k stars 6.58k forks source link

[BUG] [dart-dio] Discriminator with multi-layered subclasses causes the subclasses to have error in discriminators #15467

Open felixmede opened 1 year ago

felixmede commented 1 year ago

Bug Report Checklist

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
  1. generate the library
  2. run flutter pub get && flutter pub run build_runner build
  3. 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

ahmednfwela commented 1 year ago

@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)