Add option to force passing alt=json for some APIs that return xml by default

This commit is contained in:
Steve Bazyl 2016-01-14 10:48:40 -08:00
parent 64c1eb0941
commit 2533098484
3 changed files with 11 additions and 0 deletions

View File

@ -90,6 +90,10 @@ module Google
@path.reduce('') { |a, e| a + '/' + e }
end
def option(opt_name)
@names[sprintf('%s?%s', key, opt_name)]
end
private
# For RPC style methods, pick a name based off the request objects.
@ -184,6 +188,7 @@ module Google
value.constant = constantize_scope(key)
end
end
@rest_description.force_alt_json = @names.option('force_alt_json')
@rest_description.parameters.reject! { |k, _v| PARAMETER_BLACKLIST.include?(k) }
annotate_parameters(@rest_description.parameters)
annotate_resource(@rest_description.name, @rest_description)

View File

@ -99,6 +99,9 @@ module Google
end
class RestDescription
attr_accessor :force_alt_json
alias_method :force_alt_json?, :force_alt_json
def version
ActiveSupport::Inflector.camelize(@version.gsub(/\W/, '-')).gsub(/-/, '_')
end

View File

@ -73,6 +73,9 @@ def <%= api_method.generated_name %>(<% for param in api_method.required_paramet
command.request_object = <%= api.schemas[api_method.request._ref].generated_name %>_object
<% end -%>
<% if api_method.response -%>
<% if api.force_alt_json? -%>
command.query['alt'] = 'json'
<% end -%>
command.response_representation = <%= api.schemas[api_method.response._ref].generated_type %>::Representation
command.response_class = <%= api.schemas[api_method.response._ref].generated_type %>
<% end -%>