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

[ruby] Make File Downloads Threadsafe #16876

Merged
merged 3 commits into from
Oct 28, 2023

Conversation

dawson-conway
Copy link
Contributor

#16796

This makes the ApiClient threadsafe in ruby. I definitely need help testing this and following the process.

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.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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 (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@dawson-conway dawson-conway changed the title 16796 threadsafe ruby [ruby] Make File Downloads Threadsafe Oct 20, 2023
@dawson-conway
Copy link
Contributor Author

@cliffano (2017/07) @zlx (2017/09) @autopp (2019/02)

@wing328
Copy link
Member

wing328 commented Oct 23, 2023

please update the samples so that the CI can verify the change:

https://github.com/OpenAPITools/openapi-generator/actions/runs/6577707103/job/17937746453?pr=16876

let me know if you need any help.

@wing328 wing328 added this to the 7.1.0 milestone Oct 23, 2023
@wing328
Copy link
Member

wing328 commented Oct 25, 2023

the change looks good.

about testing the file download, can you please PM me via Slack when you've time?

@wing328
Copy link
Member

wing328 commented Oct 28, 2023

circleci failure not related to this change

@wing328 wing328 merged commit 244a3b4 into OpenAPITools:master Oct 28, 2023
15 of 16 checks passed
@lumpidu
Copy link
Contributor

lumpidu commented Dec 6, 2023

Since this MR, file downloading doesn't work anymore without patching the generated api_client.rb. I have tested this for Faraday, but also I couldn't download with Typheus.

The problem is an exception because of missing parameters, e.g.:

...
      if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
        data = deserialize_file(stream)
      elsif opts[:return_type]
...

Which should be

...
      if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
        data = deserialize_file(response, stream)
      elsif opts[:return_type]
...

and

def call_api(http_method, path, opts = {})
      stream = nil
      begin
        response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
          build_request(http_method, path, req, opts)
          stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
        end
...

Where the call to build_request() misses an assignment to a local request variable that is then used in the download_file() method.

Obviously, file downloading hasn't been tested at all.

@wing328
Copy link
Member

wing328 commented Dec 6, 2023

can you please file a PR with the suggested fix?

we can add a test in the echo API client to ensure the file download works as expected.

PM me via Slack if you need the details.

@wing328
Copy link
Member

wing328 commented Dec 6, 2023

FYI https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/echo_api/python/test/test_manual.py#L110 is how we test it in the Python Echo API client.

We need to add a similar test for the Ruby client.

lumpidu added a commit to lumpidu/openapi-generator that referenced this pull request Dec 6, 2023
In MR OpenAPITools#16876, a bug was introduced that causes file downloading to fail
for the Faraday adapter.

This commit fixes the obvious missing parameter for the method
call to download_file() and the missing variable `request` for saving the
response value of the call to build_request().

Signed-off-by: Daniel Schnell <dschnell@grammatek.com>
@lumpidu
Copy link
Contributor

lumpidu commented Dec 6, 2023

FYI https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/echo_api/python/test/test_manual.py#L110 is how we test it in the Python Echo API client.

We need to add a similar test for the Ruby client.

Well, in fact we would need to add 3 such tests for each of the supported clients (Faraday, Typhoeus, httpx). There is a httpx client, but it misses the manual tests you mentioned.

wing328 pushed a commit that referenced this pull request Dec 9, 2023
* Ruby Client for Faraday: fix file downloading

In MR #16876, a bug was introduced that causes file downloading to fail
for the Faraday adapter.

This commit fixes the obvious missing parameter for the method
call to download_file() and the missing variable `request` for saving the
response value of the call to build_request().

Signed-off-by: Daniel Schnell <dschnell@grammatek.com>

* Add automatically generated changes.

---------

Signed-off-by: Daniel Schnell <dschnell@grammatek.com>
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.

None yet

3 participants