forked from loafle/openapi-generator-original
[Ruby] add file download tests (#17362)
* add new ruby echo api clients * add tests for ruby faraday file download * add file download test to ruby Typhoeus * add ruby workflow, add tests for ruby httpx * update * fix
This commit is contained in:
@@ -21,3 +21,5 @@
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
spec/api_client_spec.rb
|
||||
spec/configuration_spec.rb
|
||||
|
||||
@@ -47,6 +47,4 @@ lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_o
|
||||
lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb
|
||||
lib/openapi_client/version.rb
|
||||
openapi_client.gemspec
|
||||
spec/api_client_spec.rb
|
||||
spec/configuration_spec.rb
|
||||
spec/spec_helper.rb
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
=begin
|
||||
#Echo Server API
|
||||
|
||||
#Echo Server API
|
||||
|
||||
The version of the OpenAPI document: 0.1.0
|
||||
Contact: team@openapitools.org
|
||||
Generated by: https://openapi-generator.tech
|
||||
OpenAPI Generator version: 7.2.0-SNAPSHOT
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe OpenapiClient::ApiClient do
|
||||
context 'initialization' do
|
||||
context 'URL stuff' do
|
||||
context 'host' do
|
||||
it 'removes http from host' do
|
||||
OpenapiClient.configure { |c| c.host = 'http://example.com' }
|
||||
expect(OpenapiClient::Configuration.default.host).to eq('example.com')
|
||||
end
|
||||
|
||||
it 'removes https from host' do
|
||||
OpenapiClient.configure { |c| c.host = 'https://wookiee.com' }
|
||||
expect(OpenapiClient::ApiClient.default.config.host).to eq('wookiee.com')
|
||||
end
|
||||
|
||||
it 'removes trailing path from host' do
|
||||
OpenapiClient.configure { |c| c.host = 'hobo.com/v4' }
|
||||
expect(OpenapiClient::Configuration.default.host).to eq('hobo.com')
|
||||
end
|
||||
end
|
||||
|
||||
context 'base_path' do
|
||||
it "prepends a slash to base_path" do
|
||||
OpenapiClient.configure { |c| c.base_path = 'v4/dog' }
|
||||
expect(OpenapiClient::Configuration.default.base_path).to eq('/v4/dog')
|
||||
end
|
||||
|
||||
it "doesn't prepend a slash if one is already there" do
|
||||
OpenapiClient.configure { |c| c.base_path = '/v4/dog' }
|
||||
expect(OpenapiClient::Configuration.default.base_path).to eq('/v4/dog')
|
||||
end
|
||||
|
||||
it "ends up as a blank string if nil" do
|
||||
OpenapiClient.configure { |c| c.base_path = nil }
|
||||
expect(OpenapiClient::Configuration.default.base_path).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe '#deserialize' do
|
||||
it "handles Array<Integer>" do
|
||||
api_client = OpenapiClient::ApiClient.new
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '[12, 34]')
|
||||
data = api_client.deserialize(response, 'Array<Integer>')
|
||||
expect(data).to be_instance_of(Array)
|
||||
expect(data).to eq([12, 34])
|
||||
end
|
||||
|
||||
it 'handles Array<Array<Integer>>' do
|
||||
api_client = OpenapiClient::ApiClient.new
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
||||
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
||||
expect(data).to be_instance_of(Array)
|
||||
expect(data).to eq([[12, 34], [56]])
|
||||
end
|
||||
|
||||
it 'handles Hash<String, String>' do
|
||||
api_client = OpenapiClient::ApiClient.new
|
||||
headers = { 'Content-Type' => 'application/json' }
|
||||
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
||||
data = api_client.deserialize(response, 'Hash<String, String>')
|
||||
expect(data).to be_instance_of(Hash)
|
||||
expect(data).to eq(:message => 'Hello')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#object_to_hash" do
|
||||
it 'ignores nils and includes empty arrays' do
|
||||
# uncomment below to test object_to_hash for model
|
||||
# api_client = OpenapiClient::ApiClient.new
|
||||
# _model = OpenapiClient::ModelName.new
|
||||
# update the model attribute below
|
||||
# _model.id = 1
|
||||
# update the expected value (hash) below
|
||||
# expected = {id: 1, name: '', tags: []}
|
||||
# expect(api_client.object_to_hash(_model)).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_collection_param' do
|
||||
let(:param) { ['aa', 'bb', 'cc'] }
|
||||
let(:api_client) { OpenapiClient::ApiClient.new }
|
||||
|
||||
it 'works for csv' do
|
||||
expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
|
||||
end
|
||||
|
||||
it 'works for ssv' do
|
||||
expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
|
||||
end
|
||||
|
||||
it 'works for tsv' do
|
||||
expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
|
||||
end
|
||||
|
||||
it 'works for pipes' do
|
||||
expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
|
||||
end
|
||||
|
||||
it 'works for multi' do
|
||||
expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
|
||||
end
|
||||
|
||||
it 'fails for invalid collection format' do
|
||||
expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#json_mime?' do
|
||||
let(:api_client) { OpenapiClient::ApiClient.new }
|
||||
|
||||
it 'works' do
|
||||
expect(api_client.json_mime?(nil)).to eq false
|
||||
expect(api_client.json_mime?('')).to eq false
|
||||
|
||||
expect(api_client.json_mime?('application/json')).to eq true
|
||||
expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
|
||||
expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
|
||||
|
||||
expect(api_client.json_mime?('application/xml')).to eq false
|
||||
expect(api_client.json_mime?('text/plain')).to eq false
|
||||
expect(api_client.json_mime?('application/jsonp')).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#select_header_accept' do
|
||||
let(:api_client) { OpenapiClient::ApiClient.new }
|
||||
|
||||
it 'works' do
|
||||
expect(api_client.select_header_accept(nil)).to be_nil
|
||||
expect(api_client.select_header_accept([])).to be_nil
|
||||
|
||||
expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
|
||||
expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
||||
expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
||||
|
||||
expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
|
||||
expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#select_header_content_type' do
|
||||
let(:api_client) { OpenapiClient::ApiClient.new }
|
||||
|
||||
it 'works' do
|
||||
expect(api_client.select_header_content_type(nil)).to be_nil
|
||||
expect(api_client.select_header_content_type([])).to be_nil
|
||||
|
||||
expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
|
||||
expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
||||
expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
||||
expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
|
||||
expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sanitize_filename' do
|
||||
let(:api_client) { OpenapiClient::ApiClient.new }
|
||||
|
||||
it 'works' do
|
||||
expect(api_client.sanitize_filename('sun')).to eq('sun')
|
||||
expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
|
||||
expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,75 +0,0 @@
|
||||
=begin
|
||||
#Echo Server API
|
||||
|
||||
#Echo Server API
|
||||
|
||||
The version of the OpenAPI document: 0.1.0
|
||||
Contact: team@openapitools.org
|
||||
Generated by: https://openapi-generator.tech
|
||||
OpenAPI Generator version: 7.2.0-SNAPSHOT
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe OpenapiClient::Configuration do
|
||||
let(:config) { OpenapiClient::Configuration.default }
|
||||
|
||||
before(:each) do
|
||||
# uncomment below to setup host and base_path
|
||||
# require 'URI'
|
||||
# uri = URI.parse("http://localhost:3000")
|
||||
# OpenapiClient.configure do |c|
|
||||
# c.host = uri.host
|
||||
# c.base_path = uri.path
|
||||
# end
|
||||
end
|
||||
|
||||
describe '#base_url' do
|
||||
it 'should have the default value' do
|
||||
# uncomment below to test default value of the base path
|
||||
# expect(config.base_url).to eq("http://localhost:3000")
|
||||
end
|
||||
|
||||
it 'should remove trailing slashes' do
|
||||
[nil, '', '/', '//'].each do |base_path|
|
||||
config.base_path = base_path
|
||||
# uncomment below to test trailing slashes
|
||||
# expect(config.base_url).to eq("http://localhost:3000")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#configure' do
|
||||
let(:session) { HTTPX::Session.new }
|
||||
|
||||
before do
|
||||
module CustomPlugin
|
||||
module InstanceMethods; end
|
||||
end
|
||||
module AnotherCustomPlugin
|
||||
module InstanceMethods; end
|
||||
end
|
||||
|
||||
config.configure_session do |session|
|
||||
session.plugin(CustomPlugin)
|
||||
end
|
||||
end
|
||||
|
||||
it 'adds a block that will be used to configure the connection' do
|
||||
sess = config.configure(session)
|
||||
|
||||
expect(sess.class.ancestors).to include(CustomPlugin::InstanceMethods)
|
||||
end
|
||||
|
||||
it 'supports multiple configuration blocks' do
|
||||
config.configure_session do |session|
|
||||
session.plugin(AnotherCustomPlugin)
|
||||
end
|
||||
sess = config.configure(session)
|
||||
|
||||
expect(sess.class.ancestors).to include(CustomPlugin::InstanceMethods)
|
||||
expect(sess.class.ancestors).to include(AnotherCustomPlugin::InstanceMethods)
|
||||
end
|
||||
end
|
||||
end
|
||||
27
samples/client/echo_api/ruby-httpx/spec/manual_spec.rb
Normal file
27
samples/client/echo_api/ruby-httpx/spec/manual_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
=begin
|
||||
#Echo Server API
|
||||
|
||||
#Echo Server API
|
||||
|
||||
The version of the OpenAPI document: 0.1.0
|
||||
Contact: team@openapitools.org
|
||||
Generated by: https://openapi-generator.tech
|
||||
OpenAPI Generator version: 7.2.0-SNAPSHOT
|
||||
|
||||
=end
|
||||
|
||||
require 'spec_helper'
|
||||
require 'base64'
|
||||
|
||||
describe "Body API tests" do
|
||||
describe 'the test_binary_gif method' do
|
||||
let(:body_api_instance) { OpenapiClient::BodyApi.new }
|
||||
|
||||
it 'can return file response' do
|
||||
gif_base64 = "R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\n"
|
||||
response = body_api_instance.test_binary_gif()
|
||||
expect(Base64.encode64(File.read(response.path))).to eq(gif_base64)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user