OpenAPITools / OpenAPITools/openapi-generator

[BUG] dart-dio + polymorphism + json_serializable fails to produce polymorphic classes

Open
#21,318 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Using the schema from: https://github.com/OpenAPITools/openapi-generator/issues/21297 fails to produce polymorphic classes with

generate -i swagger.yaml -g dart-dio -o ./_swagger --additional-properties=sourceFolder=openapi/src,pubLibrary=flutter_common.openapi,pubName=flutter_common,serializationLibrary=json_serializable"

Produces:

@JsonSerializable(...)
class Dog { }

Should be:

@JsonSerializable(...)
class Dog extends Pet { }       // extends

Without json_serializable, Dog extends Pet is produced, but BuiltValue classes cause a variety of problems (they're immutable and have non-standard constructors making them not play nice with other code generators that expect plain old Dart objects, or legacy projects using -g dart and wanting add polymorphism, (which is not support with -g dart).

Would be happy to work on this if there's a guide to implementing generators.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dart-dio generator and its json_serializable option, using the schema referenced in issue 21297 to compare the generated Dog and Pet classes. Done means json_serializable output preserves the polymorphic relationship so Dog extends Pet, without switching to BuiltValue.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.