diff --git a/lib/google/apis/generator/model.rb b/lib/google/apis/generator/model.rb index eca79e1cf..5441166ed 100644 --- a/lib/google/apis/generator/model.rb +++ b/lib/google/apis/generator/model.rb @@ -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 diff --git a/lib/google/apis/generator/templates/_method.tmpl b/lib/google/apis/generator/templates/_method.tmpl index 347f9a132..eb4e370ec 100644 --- a/lib/google/apis/generator/templates/_method.tmpl +++ b/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) %> @@ -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?