OpenAPITools / OpenAPITools/openapi-generator

[BUG] [dart] Syntax errors when using oneOf with Object datatype with no fields

Open
#16,715 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

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

Using the dart-generator with oneOf, and one of it's types being an object with no parameters, results in generation with syntax errors.

Trying the example yaml below, i would expect an error-free class with no parameters, but instead it results in a class filled with syntax errors.

While i know oneOf is not currently supported in dart, i think it should at least result in a class with no parameters, without syntax errors. or not be generated at all.

openapi-generator version

version 7.0.1

OpenAPI declaration file content or url

As i cannot share the original file as it is private and comes from a third-party service,
here is a simple example showing a reproduction of the issue.

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: http://localhost:8080
    description: Generated server url
paths:
  /api/v1/my-path:
    get:
      operationId: my-operation
      responses:
        '400':
          description: Bad Request
          content:
            '*/*':
              schema:
                oneOf:
                  - type: string
                  - type: object

generates the following file with multiple syntax errors:

class MyOperation400Response {
  /// Returns a new [MyOperation400Response] instance.
  MyOperation400Response({
  });

  @override
  bool operator ==(Object other) => identical(this, other) || other is MyOperation400Response &&

  @override
  int get hashCode =>
    // ignore: unnecessary_parenthesis

  @override
  String toString() => 'MyOperation400Response[]';

  // .....
}
Generation Details

Dart Generator
openapi-generator-cli generate -i openapi.yaml -g dart -o dart

Steps to reproduce

wrote the example yaml into an openapi.yaml file in a new empty folder. then ran the command in generation details section.

Related issues/PRs
Suggest a fix

While i know that oneOf is not currently supported in the dart generator, i would like to know any workaround to make the code not have syntax errors at the very least.
I would think that having the model class be empty should work fine.
I cannot edit the spec or the oneOf part as the issue originally comes from the spec of an external third party service.

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 openapi.yaml reproduction and run the documented openapi-generator-cli command using the dart generator. Inspect the generated MyOperation400Response class and trace the Dart generator path that handles the empty object in oneOf. Done means the generated Dart output is syntactically valid, with an empty model or another documented handling of the unsupported schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.