From fdad456e99f34f1a6d5cdb2a040b9403f58db75d Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Thu, 24 Mar 2022 09:34:04 +0000 Subject: [PATCH] [API] Generator: Fixes order of arguments.clone When updating the code generator for 8.x, the order of `arguments.clone` in the generated code was changed. This would make it so that we would modify the arguments before cloning them, which is undesired. Addresses #1727 --- elasticsearch-api/utils/thor/templates/_method_setup.erb | 1 - elasticsearch-api/utils/thor/templates/method.erb | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/elasticsearch-api/utils/thor/templates/_method_setup.erb b/elasticsearch-api/utils/thor/templates/_method_setup.erb index 2ad4dc7ca8..6bcd79e63f 100644 --- a/elasticsearch-api/utils/thor/templates/_method_setup.erb +++ b/elasticsearch-api/utils/thor/templates/_method_setup.erb @@ -16,7 +16,6 @@ # specific language governing permissions and limitations # under the License. %> -<%= ' '*(@namespace_depth+4) %>arguments = arguments.clone <%- if @method_name == 'search' -%> arguments[:index] = UNDERSCORE_ALL if ! arguments[:index] && arguments[:type] <%- end -%> diff --git a/elasticsearch-api/utils/thor/templates/method.erb b/elasticsearch-api/utils/thor/templates/method.erb index 775a834832..ba49963edb 100644 --- a/elasticsearch-api/utils/thor/templates/method.erb +++ b/elasticsearch-api/utils/thor/templates/method.erb @@ -33,12 +33,14 @@ module Elasticsearch <%= ' '*(@namespace_depth+2) %>end <%- else -%> <%- if @method_name == 'get_field_mapping' %> + arguments = arguments.clone _fields = arguments.delete(:field) || arguments.delete(:fields) raise ArgumentError, "Required argument 'field' missing" unless _fields <%- else -%> <%- @required_parts.each do |required| %><%# Arguments -%> <%= ' '*(@namespace_depth+3) + "raise ArgumentError, \"Required argument '#{required}' missing\" unless arguments[:#{required}]" + "\n" -%> <%- end -%> + arguments = arguments.clone <%- end -%> headers = arguments.delete(:headers) || {} <%- #Body %>