Skip to content

Commit a022d10

Browse files
committed
[API] Generator: Count is POST/GET depending on the pressence of body
1 parent 4207e62 commit a022d10

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

elasticsearch-api/utils/thor/generate_source.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,31 @@ def __endpoint_parts
148148

149149
def __http_method
150150
return '_id ? Elasticsearch::API::HTTP_PUT : Elasticsearch::API::HTTP_POST' if @endpoint_name == 'index'
151+
return post_and_get if @endpoint_name == 'count'
151152

152153
default_method = @spec['url']['paths'].map { |a| a['methods'] }.flatten.first
153154
if @spec['body'] && default_method == 'GET'
154155
# When default method is GET and body is required, we should always use POST
155156
if @spec['body']['required']
156157
'Elasticsearch::API::HTTP_POST'
157158
else
158-
<<~SRC
159-
if arguments[:body]
160-
Elasticsearch::API::HTTP_POST
161-
else
162-
Elasticsearch::API::HTTP_GET
163-
end
164-
SRC
159+
post_and_get
165160
end
166161
else
167162
"Elasticsearch::API::HTTP_#{default_method}"
168163
end
169164
end
170165

166+
def post_and_get
167+
<<~SRC
168+
if arguments[:body]
169+
Elasticsearch::API::HTTP_POST
170+
else
171+
Elasticsearch::API::HTTP_GET
172+
end
173+
SRC
174+
end
175+
171176
def __http_path
172177
return "\"#{__parse_path(@paths.first)}\"" if @paths.size == 1
173178
return termvectors_path if @method_name == 'termvectors'
@@ -194,9 +199,9 @@ def __http_path
194199

195200
def __parse_path(path)
196201
path.gsub(/^\//, '')
197-
.gsub(/\/$/, '')
198-
.gsub('{', "\#{#{__utils}.__listify(_")
199-
.gsub('}', ')}')
202+
.gsub(/\/$/, '')
203+
.gsub('{', "\#{Utils.__listify(_")
204+
.gsub('}', ')}')
200205
end
201206

202207
def __path_variables

0 commit comments

Comments
 (0)