Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alevinetx opened this issue Sep 26, 2019 · 5 comments
Open

Comments

@alevinetx
Copy link

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 :)

@auto-labeler
Copy link

auto-labeler bot commented Sep 26, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@alevinetx
Copy link
Author

@nickmeinhold : any chance you have any thoughts on this? I am looking through the source, and coming up empty.

@nickmeinhold
Copy link
Contributor

@alevinetx you probably know more about it than I do, I haven't had to work with oneOf/anyOf yet.

Stumbling around trying to be helpful - I generated libraries for the oneOf.yaml and anyOf.yaml test files and they seemed to be valid Dart - I didn't do any testing but maybe those test files could be helpful?

In the spec docs the syntax is different to what you used - just wondering if there could be any issue with contents of the yaml file. I did some searching for the bodyText keyword and didn't find anything there. If you have time, maybe create the minimal repro file and link to a gist or something, it's helpful to be definitely looking at the same thing.

Hope that's helpful, if not maybe try the Slack, the core team are often responsive there.

@fajarvm
Copy link

fajarvm commented Mar 6, 2020

Hey all.

I've been following this issue for a while now—the past couple of months. Unfortunately, there seems to be no solid solution for the "anyOf" issue for Dart generators (dart and dart-dio) as of yet.

Tried using openapi-generator version 4.2.x and even 5.0.x. Alas, it still produce invalid code.
For example, the dart generator produces something like this:
AnyOf&lt;string,string,TransactionTypeEnum&gt;.listFromJson(json['values']);
(&lt; and &gt; is not a valid code)

as for dart-dio generator:
BuiltList<AnyOf<string, string, TransactionTypeEnum>> get values;
(there is no 'AnyOf' class being generated. So, that piece of code is not usable)

For now, I'll have to avoid using 'anyOf', 'oneOf' and 'allOf' for Dart and have to write type mappings for the concerned entities.

If there's anyone who has a (temporary) solution for this, I would gladly like to know.

@noriHanda
Copy link

Is this issue still valid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants