Skip to content

[Dart2] Fix a bug when asking to upload a MultipartFile as body.#7736

Merged
wing328 merged 6 commits intoOpenAPITools:masterfrom
noordawod:feature/multipart-file-request
Nov 4, 2020
Merged

[Dart2] Fix a bug when asking to upload a MultipartFile as body.#7736
wing328 merged 6 commits intoOpenAPITools:masterfrom
noordawod:feature/multipart-file-request

Conversation

@noordawod
Copy link
Copy Markdown
Contributor

@noordawod noordawod commented Oct 17, 2020

The current generator produces code that won't work when trying to upload a file not part of a multipart-form data.

As an example, the generated code for an API endpoint with a file which is not part of a multipart-form request is as follows:

Future uploadFile(MultipartFile image) {
  // ...
}

However, invokeAPI() doesn't take that into account and only checks for a MultipartRequest. This pr adds support for sending a single file when uploading non-multipart form data.

plus, added some tlc to the QueryParam class :)

@ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09) @athornz (2019/12) @amondnet (2019/12) @agilob @wing328 @sbu-WBT

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

case 'DELETE': return await _client.delete(url, headers: nullableHeaderParams,);
case 'PATCH': return await _client.patch(url, headers: nullableHeaderParams, body: msgBody,);
case 'HEAD': return await _client.head(url, headers: nullableHeaderParams,);
case 'GET': return await _client.get(url, headers: nullableHeaderParams,);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some use dartfmt to reformat the generated code, this would make it look nicer for them. Same below.

@agilob
Copy link
Copy Markdown
Contributor

agilob commented Oct 17, 2020

Are you available on slack or gitter? can you msg me there?

Would be nice to have some tests for it.

@noordawod
Copy link
Copy Markdown
Contributor Author

Are you available on slack or gitter? can you msg me there?

Would be nice to have some tests for it.

I'm on Slack. If there's a Slack channel for openapi, then I'm not on it yet. Invite? (email is on my profile page)

@agilob
Copy link
Copy Markdown
Contributor

agilob commented Oct 17, 2020

Copy link
Copy Markdown
Contributor

@agilob agilob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change? 3bfc021

What's the difference between before and after?

@noordawod
Copy link
Copy Markdown
Contributor Author

Can you explain this change? 3bfc021

What's the difference between before and after?

Yes, of course.

With this change, we no longer need to define a helper class (extending MultipartRequest) and we can reuse the existing StreamedRequest class that comes with Dart. Simple and efficient.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Nov 2, 2020

If no one has further feedback on this change, I'll merge it tomorrow (Tue)

@wing328 wing328 merged commit aff1af7 into OpenAPITools:master Nov 4, 2020
@noordawod noordawod deleted the feature/multipart-file-request branch November 4, 2020 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants