Skip to content

Commit

Permalink
Make required query parameters required.
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrrrl committed Jul 31, 2015
1 parent 7042f22 commit c9da9f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/google/apis/generator/model.rb
Expand Up @@ -75,6 +75,16 @@ def query_parameters
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
Expand Down
6 changes: 3 additions & 3 deletions lib/google/apis/generator/templates/_method.tmpl
@@ -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) %>
Expand All @@ -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) %>
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit c9da9f3

Please sign in to comment.