Skip to content

Commit 8dc22d2

Browse files
authored
Merge pull request #3228 from cliffano/master
[Ruby] Add params_encoding configuration to be passed to api_client's request options
2 parents a71c072 + af77d94 commit 8dc22d2

40 files changed

+123
-86
lines changed

modules/swagger-codegen/src/main/resources/ruby/api_client.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module {{moduleName}}
8686
:method => http_method,
8787
:headers => header_params,
8888
:params => query_params,
89+
:params_encoding => @config.params_encoding,
8990
:timeout => @config.timeout,
9091
:ssl_verifypeer => @config.verify_ssl,
9192
:sslcert => @config.cert_file,

modules/swagger-codegen/src/main/resources/ruby/api_client_spec.mustache

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ describe {{moduleName}}::ApiClient do
9090
end
9191
end
9292

93+
describe "params_encoding in #build_request" do
94+
let(:config) { {{moduleName}}::Configuration.new }
95+
let(:api_client) { {{moduleName}}::ApiClient.new(config) }
96+
97+
it "defaults to nil" do
98+
expect({{moduleName}}::Configuration.default.params_encoding).to eq(nil)
99+
expect(config.params_encoding).to eq(nil)
100+
101+
request = api_client.build_request(:get, '/test')
102+
expect(request.options[:params_encoding]).to eq(nil)
103+
end
104+
105+
it "can be customized" do
106+
config.params_encoding = :multi
107+
request = api_client.build_request(:get, '/test')
108+
expect(request.options[:params_encoding]).to eq(:multi)
109+
end
110+
end
111+
93112
describe "timeout in #build_request" do
94113
let(:config) { {{moduleName}}::Configuration.new }
95114
let(:api_client) { {{moduleName}}::ApiClient.new(config) }

modules/swagger-codegen/src/main/resources/ruby/configuration.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ module {{moduleName}}
7777
# @return [true, false]
7878
attr_accessor :verify_ssl
7979

80+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
81+
# Default to nil.
82+
#
83+
# @see The params_encoding option of Ethon. Related source code:
84+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
85+
attr_accessor :params_encoding
86+
8087
# Set this to customize the certificate file to verify the peer.
8188
#
8289
# @return [String] the path to the certificate file
@@ -103,6 +110,7 @@ module {{moduleName}}
103110
@api_key_prefix = {}
104111
@timeout = 0
105112
@verify_ssl = true
113+
@params_encoding = nil
106114
@cert_file = nil
107115
@key_file = nil
108116
@debugging = false

samples/client/petstore/ruby/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
88

99
- API version: 1.0.0
1010
- Package version: 1.0.0
11-
- Build date: 2016-06-26T19:08:46.043+08:00
11+
- Build date: 2016-06-28T15:19:55.521+10:00
1212
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
1313

1414
## Installation
@@ -148,12 +148,6 @@ Class | Method | HTTP request | Description
148148
## Documentation for Authorization
149149

150150

151-
### api_key
152-
153-
- **Type**: API key
154-
- **API key parameter name**: api_key
155-
- **Location**: HTTP header
156-
157151
### petstore_auth
158152

159153
- **Type**: OAuth
@@ -163,3 +157,9 @@ Class | Method | HTTP request | Description
163157
- write:pets: modify pets in your account
164158
- read:pets: read your pets
165159

160+
### api_key
161+
162+
- **Type**: API key
163+
- **API key parameter name**: api_key
164+
- **Location**: HTTP header
165+

samples/client/petstore/ruby/lib/petstore.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77

samples/client/petstore/ruby/lib/petstore/api/fake_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77

samples/client/petstore/ruby/lib/petstore/api/pet_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77

samples/client/petstore/ruby/lib/petstore/api/store_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77

samples/client/petstore/ruby/lib/petstore/api/user_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77

samples/client/petstore/ruby/lib/petstore/api_client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=begin
2-
Swagger Petstore
2+
#Swagger Petstore
33
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
55
66
OpenAPI spec version: 1.0.0
77
@@ -103,6 +103,7 @@ def build_request(http_method, path, opts = {})
103103
:method => http_method,
104104
:headers => header_params,
105105
:params => query_params,
106+
:params_encoding => @config.params_encoding,
106107
:timeout => @config.timeout,
107108
:ssl_verifypeer => @config.verify_ssl,
108109
:sslcert => @config.cert_file,

0 commit comments

Comments
 (0)