Make required query parameters required.

This commit is contained in:
Steven Bazyl 2015-07-30 17:05:05 -07:00
parent 7042f2272c
commit c9da9f38d1
2 changed files with 13 additions and 3 deletions

View File

@ -75,6 +75,16 @@ module Google
return [] if parameters.nil?
parameters.values.select { |param| param.location == 'query' }
end
def required_parameters
return [] if parameter_order.nil? || parameters.nil?
parameter_order.map { |name| parameters[name] }.select { |param| param.location == 'path' || param.required }
end
def optional_query_parameters
query_parameters.select { |param| param.required != true }
end
end
class RestResource

View File

@ -1,6 +1,6 @@
# <%= block_comment(api_method.description, 0, 1) %>
<% for param in api_method.path_parameters -%>
<% for param in api_method.required_parameters -%>
# @param [<% if param.repeated? %>Array<<%= param.generated_type %>>, <% end %><%= param.generated_type %>] <%= param.generated_name %>
<% if param.description -%>
# <%= block_comment(param.description, 0, 3) %>
@ -9,7 +9,7 @@
<% if api_method.request -%>
# @param [<%= api.schemas[api_method.request._ref].generated_type %>] <%= api.schemas[api_method.request._ref].generated_name %>_object
<% end -%>
<% for param in api_method.query_parameters -%>
<% for param in api_method.optional_query_parameters -%>
# @param [<% if param.repeated? %>Array<<%= param.generated_type %>>, <% end %><%= param.generated_type %>] <%= param.generated_name %>
<% if param.description -%>
# <%= block_comment(param.description, 0, 3) %>
@ -49,7 +49,7 @@
# @raise [Google::Apis::ServerError] An error occurred on the server and the request can be retried
# @raise [Google::Apis::ClientError] The request is invalid and should not be retried without modification
# @raise [Google::Apis::AuthorizationError] Authorization is required
def <%= api_method.generated_name %>(<% for param in api_method.path_parameters %><%= param.generated_name %>, <% end %><% if api_method.request %><%= api.schemas[api_method.request._ref].generated_name %>_object = nil, <% end %><% for param in api_method.query_parameters %><%= param.generated_name %>: nil, <% end %><% for param in api.parameters.values.reject {|p| p.name == 'key'} %><%= param.generated_name %>: nil, <% end %><% if api_method.supports_media_upload? %>upload_source: nil, content_type: nil, <% elsif api_method.supports_media_download? %>download_dest: nil, <% end %>options: nil, &block)
def <%= api_method.generated_name %>(<% for param in api_method.required_parameters %><%= param.generated_name %>, <% end %><% if api_method.request %><%= api.schemas[api_method.request._ref].generated_name %>_object = nil, <% end %><% for param in api_method.optional_query_parameters %><%= param.generated_name %>: nil, <% end %><% for param in api.parameters.values.reject {|p| p.name == 'key'} %><%= param.generated_name %>: nil, <% end %><% if api_method.supports_media_upload? %>upload_source: nil, content_type: nil, <% elsif api_method.supports_media_download? %>download_dest: nil, <% end %>options: nil, &block)
path = '<%= api_method.path %>'
<% if api_method.supports_media_upload? -%>
if upload_source.nil?