diff --git a/modules/openapi-generator/src/main/resources/ruby-client/api_client_typhoeus_partial.mustache b/modules/openapi-generator/src/main/resources/ruby-client/api_client_typhoeus_partial.mustache index 39792eb732b..f55f9804372 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/api_client_typhoeus_partial.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/api_client_typhoeus_partial.mustache @@ -4,7 +4,8 @@ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -145,17 +146,15 @@ chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/api_client.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/api_client.rb index bfd4b840b52..5fe10d513b4 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/api_client.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/api_client.rb @@ -49,7 +49,8 @@ module OpenapiClient # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -188,19 +189,17 @@ module OpenapiClient chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME. diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/api_client.rb b/samples/client/petstore/ruby-autoload/lib/petstore/api_client.rb index d8de2cce497..266143c2f88 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/api_client.rb @@ -49,7 +49,8 @@ module Petstore # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -188,19 +189,17 @@ module Petstore chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME. diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index d8de2cce497..266143c2f88 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -49,7 +49,8 @@ module Petstore # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -188,19 +189,17 @@ module Petstore chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME. diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb b/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb index c4ba5a771d6..4d4dee47765 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb +++ b/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb @@ -49,7 +49,8 @@ module XAuthIDAlias # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -188,19 +189,17 @@ module XAuthIDAlias chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME. diff --git a/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb b/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb index 87a3e30b3cb..4e6ee7e368a 100644 --- a/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb +++ b/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb @@ -49,7 +49,8 @@ module DynamicServers # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -187,19 +188,17 @@ module DynamicServers chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME. diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb index e90022250c4..033af38e53f 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb @@ -49,7 +49,8 @@ module Petstore # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) - tempfile = download_file(request) if opts[:return_type] == 'File' + tempfile = nil + (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File' response = request.run if @config.debugging @@ -187,19 +188,17 @@ module Petstore chunk.force_encoding(encoding) tempfile.write(chunk) end - # run the request to ensure the tempfile is created successfully before returning it - request.run - if tempfile + request.on_complete do + if !tempfile + fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + end tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" - else - fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") + yield tempfile if block_given? end - - tempfile end # Check if the given MIME is a JSON MIME.