OpenAPITools / OpenAPITools/openapi-generator

[BUG][dart-dio] Model generated with $ even if not abstract

Open
#17,517 0 comments 3 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

This issue exists in the latest version and it doesn't seem to be a regression bug according to my understanding

Imagine the following class is a request in any of the api calls

Pet:
  type: object
  required:
    - id
    - name
  properties:
    id:
      type: integer
      format: int64
    name:
      type: string
    tag:
      type: string

Then we have a response defined as following

PetResponse:
  description: |
    Pet Response
  allOf:
    - $ref: '#/components/schemas/Pet'
    - type: object
      properties:
        referenceId:
          type: string

They only way in dart to instantiate the Pet Model class is to use the $PetModel. The reason is that the flag
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_header.mustache#L12

x-is-parent

is set https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java#L447

This happens as soon as allOf is used https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java#L347

Expected behaviour would be when the class used in allOf is also used as request or response somewhere else is not marked as instantiable: false as this is not correct. Class should be instantiable.

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

Reproduce the provided Pet and PetResponse schemas with the dart-dio generator, then inspect DartDioClientCodegen.java around lines 347 and 447 and class_header.mustache around line 12. Trace how allOf sets x-is-parent and instantiable, and consider the case where the parent model is also used in a request or response. Done means Pet can be instantiated directly without the generated $PetModel workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.