Skip to content

Pass opts argument to api client in ruby-client #2754

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

Merged
merged 5 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module {{moduleName}}
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}

# query parameters
query_params = {}
query_params = opts[:query_params] || {}
{{#queryParams}}
{{#required}}
query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
Expand All @@ -139,7 +139,7 @@ module {{moduleName}}
{{/queryParams}}

# header parameters
header_params = {}
header_params = opts[:header_params] || {}
{{#hasProduces}}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
Expand All @@ -160,7 +160,7 @@ module {{moduleName}}
{{/headerParams}}

# form parameters
form_params = {}
form_params = opts[:form_params] || {}
{{#formParams}}
{{#required}}
form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
Expand All @@ -173,20 +173,24 @@ module {{moduleName}}
{{/formParams}}

# http body (model)
{{^bodyParam}}
post_body = nil
{{/bodyParam}}
{{#bodyParam}}
post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
{{/bodyParam}}
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path,
post_body = opts[:body] {{#bodyParam}}|| @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) {{/bodyParam}}

# return_type
return_type = opts[:return_type] {{#returnType}}|| '{{{returnType}}}' {{/returnType}}

# auth_names
auth_names = opts[:auth_names] || [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]

new_options = opts.merge(
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names{{#returnType}},
:return_type => '{{{returnType}}}'{{/returnType}})
:auth_names => auth_names,
:return_type => return_type
)

data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
Expand Down
23 changes: 16 additions & 7 deletions samples/client/petstore/ruby/lib/petstore/api/another_fake_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,37 @@ def call_123_test_special_tags_with_http_info(body, opts = {})
local_var_path = '/another-fake/dummy'

# query parameters
query_params = {}
query_params = opts[:query_params] || {}

# header parameters
header_params = {}
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])

# form parameters
form_params = {}
form_params = opts[:form_params] || {}

# http body (model)
post_body = @api_client.object_to_http_body(body)
auth_names = []
data, status_code, headers = @api_client.call_api(:PATCH, local_var_path,
post_body = opts[:body] || @api_client.object_to_http_body(body)

# return_type
return_type = opts[:return_type] || 'Client'

# auth_names
auth_names = opts[:auth_names] || []

new_options = opts.merge(
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => 'Client')
:return_type => return_type
)

data, status_code, headers = @api_client.call_api(:PATCH, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: AnotherFakeApi#call_123_test_special_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
Expand Down
Loading