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] Using multipart/form-data breaks on File.fromJson #7589

Closed
2 of 6 tasks
freshteapot opened this issue Oct 3, 2020 · 3 comments
Closed
2 of 6 tasks

[BUG] [DART] Using multipart/form-data breaks on File.fromJson #7589

freshteapot opened this issue Oct 3, 2020 · 3 comments

Comments

@freshteapot
Copy link

freshteapot commented Oct 3, 2020

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

The generated code.

  HttpAssetUploadRequestBody.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    sharedWith = json['shared_with'];
    file = (json['file'] == null) ?
      null :
      File.fromJson(json['file']);
  }

The problem "fromJson" is not a method on class "File", Also "file" is "MultipartFile", which possibly means "File" should be "MultipartFile". (I am sorry for file and File).

openapi-generator version
openapi-generator version
4.3.1
OpenAPI declaration file content or url

It should fail with the petstore yaml file

Your more than welcome to try against

https://gist.github.com/freshteapot/2e33445c0a2f88220a156e1f61589590

Generation Details

From what I can understand using the petstore example will trigger this to happen.

Working with https://gist.github.com/freshteapot/2e33445c0a2f88220a156e1f61589590.
Use

DART_POST_PROCESS_FILE="/usr/local/bin/dartfmt -w" \
openapi-generator generate -i /tmp/openapi/one/learnalist.yaml -g dart -o /tmp/openapi/dart \
--additional-properties ensureUniqueParams=false
Related issues/PRs

Will dig up things that remotely link.

Suggest a fix

Maybe not using fromJson and just treat "file" as filename.

file, in this case is "MultipartFile". The below code compiles, not 100% sure if it works, as I haven't used the new api in my flutter app.

HttpAssetUploadRequestBody.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
    sharedWith = json['shared_with'];
    file = (json['file'] == null)
        ? null
        : MultipartFile.fromString("file", json['file']);
  }

Possibly the issue is linked to

{{name}} = (json['{{baseName}}'] == null) ?
null :
{{complexType}}.fromJson(json['{{baseName}}']);
.

I suspect this might also effect toJson, as well. But at least it compiles.

@freshteapot freshteapot changed the title [BUG][DART] Using multipart/form-data breaks on File.fromJson [BUG] [DART] Using multipart/form-data breaks on File.fromJson Nov 5, 2020
@kuhnroyal
Copy link
Contributor

I fixed something related to this in 5.0.0 - can you test this again?

@sergiofigueras
Copy link

Hello there @kuhnroyal ,

I had the same issue in 4.3.1 , but its now fixed in 5.0.0 .

Thanks!

@kuhnroyal
Copy link
Contributor

@wing328 This can be closed

@wing328 wing328 closed this as completed Jan 22, 2021
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