OpenAPITools / OpenAPITools/openapi-generator

[BUG][DART] oneOf dart code generation: wrong types and html-encoded code

Open
#3,965 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • [ Y] Have you provided a full/minimal spec to reproduce the issue?
  • [ Y] Have you validated the input using an OpenAPI validator (example)?
  • [ Y] What's the version of OpenAPI Generator used?
  • [Y ] Have you search for related issues/PRs?
  • [ Y] What's the actual output vs expected output?
  • [ -] [Optional] Bounty to sponsor the fix ([example]
Description

When using oneOf, with options for String or int, the generated dart code produces the class model with a few errors:

1: OneOf<string, integer> : where "string" should be "String", and "integer" should be "int". These are produced as expected (String or int) with other simple entries.

part of openapi.api;
class Pet {
  OneOf<string,integer> bodyText = null;

2: The generated code has encoded the "<>" symbols in html form (&lt;, &gt;)

    if (json['bodyText'] == null) {
      bodyText = null;
    } else {
      bodyText = OneOf&lt;string,integer&gt;.fromJson(json['bodyText']);
openapi-generator version

$ openapi-generator version
4.1.2

OpenAPI declaration file content or url

openapi: 3.0.1

    Blob:
      required:
      - name
      type: object
      properties:
        bodyText:
          oneOf:
            - type: string
            - type: integer
Command line used for generation

openapi-generator generate -i oneof.yaml -g dart -o oneof-out3a -p browserClient=false,supportDart2=true,generateAliasAsModel=true

Steps to reproduce

1: Use the default pet store model at https://editor.swagger.io/
2: Add these 4 lines to a model's properties:

        bodyText:
          oneOf:
            - type: string
            - type: integer

3: Generate code in the manner shown above
4: Observe lib/model/.dart code

Related issues/PRs

#3884

Suggest a fix

If I knew, I'd drop a PR :)

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 by reproducing the issue with the provided oneof.yaml and the openapi-generator generate command, then inspect the generated lib/model/.dart file. Compare the oneOf<String, int> declaration and deserialization output with the reported HTML-encoded version. Done means the generated Dart model uses String and int and emits unencoded angle brackets.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, openapi
Domain
api, 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.