Skip to content

Commit 66a4ee2

Browse files
committed
style(crystal): use kwargs when calling @api_client
1 parent 221f862 commit 66a4ee2

5 files changed

Lines changed: 308 additions & 220 deletions

File tree

modules/openapi-generator/src/main/resources/crystal/api.mustache

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,23 @@ module {{moduleName}}
165165
# auth_names
166166
auth_names = {{#authMethods}}{{#-first}}[{{/-first}}"{{name}}"{{^-last}}, {{/-last}}{{#-last}}]{{/-last}}{{/authMethods}}{{^authMethods}}[] of String{{/authMethods}}
167167

168-
data, status_code, headers = @api_client.call_api(:{{httpMethod}},
169-
local_var_path,
170-
:"{{classname}}.{{operationId}}",
171-
return_type,
172-
post_body,
173-
auth_names,
174-
header_params,
175-
query_params,
176-
cookie_params,
177-
form_params)
168+
data, status_code, headers = @api_client.call_api(
169+
http_method: :{{httpMethod}},
170+
path: local_var_path,
171+
operation: :"{{classname}}.{{operationId}}",
172+
return_type: return_type,
173+
post_body: post_body,
174+
auth_names: auth_names,
175+
header_params: header_params,
176+
query_params: query_params,
177+
cookie_params: cookie_params,
178+
form_params: form_params
179+
)
180+
178181
if @api_client.config.debugging
179182
Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
180183
end
184+
181185
return {{#returnType}}{{{.}}}.from_json(data){{/returnType}}{{^returnType}}nil{{/returnType}}, status_code, headers
182186
end
183187
{{^-last}}

samples/client/petstore/crystal/src/petstore/api/fake_api.cr

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,23 @@ module Petstore
8989
# auth_names
9090
auth_names = [] of String
9191

92-
data, status_code, headers = @api_client.call_api(:GET,
93-
local_var_path,
94-
:"FakeApi.get_parameter_name_mapping",
95-
return_type,
96-
post_body,
97-
auth_names,
98-
header_params,
99-
query_params,
100-
cookie_params,
101-
form_params)
92+
data, status_code, headers = @api_client.call_api(
93+
http_method: :GET,
94+
path: local_var_path,
95+
operation: :"FakeApi.get_parameter_name_mapping",
96+
return_type: return_type,
97+
post_body: post_body,
98+
auth_names: auth_names,
99+
header_params: header_params,
100+
query_params: query_params,
101+
cookie_params: cookie_params,
102+
form_params: form_params
103+
)
104+
102105
if @api_client.config.debugging
103106
Log.debug {"API called: FakeApi#get_parameter_name_mapping\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
104107
end
108+
105109
return nil, status_code, headers
106110
end
107111
end

samples/client/petstore/crystal/src/petstore/api/pet_api.cr

Lines changed: 112 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,23 @@ module Petstore
6666
# auth_names
6767
auth_names = ["petstore_auth"]
6868

69-
data, status_code, headers = @api_client.call_api(:POST,
70-
local_var_path,
71-
:"PetApi.add_pet",
72-
return_type,
73-
post_body,
74-
auth_names,
75-
header_params,
76-
query_params,
77-
cookie_params,
78-
form_params)
69+
data, status_code, headers = @api_client.call_api(
70+
http_method: :POST,
71+
path: local_var_path,
72+
operation: :"PetApi.add_pet",
73+
return_type: return_type,
74+
post_body: post_body,
75+
auth_names: auth_names,
76+
header_params: header_params,
77+
query_params: query_params,
78+
cookie_params: cookie_params,
79+
form_params: form_params
80+
)
81+
7982
if @api_client.config.debugging
8083
Log.debug {"API called: PetApi#add_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
8184
end
85+
8286
return Pet.from_json(data), status_code, headers
8387
end
8488

@@ -128,19 +132,23 @@ module Petstore
128132
# auth_names
129133
auth_names = ["petstore_auth"]
130134

131-
data, status_code, headers = @api_client.call_api(:DELETE,
132-
local_var_path,
133-
:"PetApi.delete_pet",
134-
return_type,
135-
post_body,
136-
auth_names,
137-
header_params,
138-
query_params,
139-
cookie_params,
140-
form_params)
135+
data, status_code, headers = @api_client.call_api(
136+
http_method: :DELETE,
137+
path: local_var_path,
138+
operation: :"PetApi.delete_pet",
139+
return_type: return_type,
140+
post_body: post_body,
141+
auth_names: auth_names,
142+
header_params: header_params,
143+
query_params: query_params,
144+
cookie_params: cookie_params,
145+
form_params: form_params
146+
)
147+
141148
if @api_client.config.debugging
142149
Log.debug {"API called: PetApi#delete_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
143150
end
151+
144152
return nil, status_code, headers
145153
end
146154

@@ -192,19 +200,23 @@ module Petstore
192200
# auth_names
193201
auth_names = ["petstore_auth"]
194202

195-
data, status_code, headers = @api_client.call_api(:GET,
196-
local_var_path,
197-
:"PetApi.find_pets_by_status",
198-
return_type,
199-
post_body,
200-
auth_names,
201-
header_params,
202-
query_params,
203-
cookie_params,
204-
form_params)
203+
data, status_code, headers = @api_client.call_api(
204+
http_method: :GET,
205+
path: local_var_path,
206+
operation: :"PetApi.find_pets_by_status",
207+
return_type: return_type,
208+
post_body: post_body,
209+
auth_names: auth_names,
210+
header_params: header_params,
211+
query_params: query_params,
212+
cookie_params: cookie_params,
213+
form_params: form_params
214+
)
215+
205216
if @api_client.config.debugging
206217
Log.debug {"API called: PetApi#find_pets_by_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
207218
end
219+
208220
return Array(Pet).from_json(data), status_code, headers
209221
end
210222

@@ -256,19 +268,23 @@ module Petstore
256268
# auth_names
257269
auth_names = ["petstore_auth"]
258270

259-
data, status_code, headers = @api_client.call_api(:GET,
260-
local_var_path,
261-
:"PetApi.find_pets_by_tags",
262-
return_type,
263-
post_body,
264-
auth_names,
265-
header_params,
266-
query_params,
267-
cookie_params,
268-
form_params)
271+
data, status_code, headers = @api_client.call_api(
272+
http_method: :GET,
273+
path: local_var_path,
274+
operation: :"PetApi.find_pets_by_tags",
275+
return_type: return_type,
276+
post_body: post_body,
277+
auth_names: auth_names,
278+
header_params: header_params,
279+
query_params: query_params,
280+
cookie_params: cookie_params,
281+
form_params: form_params
282+
)
283+
269284
if @api_client.config.debugging
270285
Log.debug {"API called: PetApi#find_pets_by_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
271286
end
287+
272288
return Array(Pet).from_json(data), status_code, headers
273289
end
274290

@@ -319,19 +335,23 @@ module Petstore
319335
# auth_names
320336
auth_names = ["api_key"]
321337

322-
data, status_code, headers = @api_client.call_api(:GET,
323-
local_var_path,
324-
:"PetApi.get_pet_by_id",
325-
return_type,
326-
post_body,
327-
auth_names,
328-
header_params,
329-
query_params,
330-
cookie_params,
331-
form_params)
338+
data, status_code, headers = @api_client.call_api(
339+
http_method: :GET,
340+
path: local_var_path,
341+
operation: :"PetApi.get_pet_by_id",
342+
return_type: return_type,
343+
post_body: post_body,
344+
auth_names: auth_names,
345+
header_params: header_params,
346+
query_params: query_params,
347+
cookie_params: cookie_params,
348+
form_params: form_params
349+
)
350+
332351
if @api_client.config.debugging
333352
Log.debug {"API called: PetApi#get_pet_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
334353
end
354+
335355
return Pet.from_json(data), status_code, headers
336356
end
337357

@@ -384,19 +404,23 @@ module Petstore
384404
# auth_names
385405
auth_names = ["petstore_auth"]
386406

387-
data, status_code, headers = @api_client.call_api(:PUT,
388-
local_var_path,
389-
:"PetApi.update_pet",
390-
return_type,
391-
post_body,
392-
auth_names,
393-
header_params,
394-
query_params,
395-
cookie_params,
396-
form_params)
407+
data, status_code, headers = @api_client.call_api(
408+
http_method: :PUT,
409+
path: local_var_path,
410+
operation: :"PetApi.update_pet",
411+
return_type: return_type,
412+
post_body: post_body,
413+
auth_names: auth_names,
414+
header_params: header_params,
415+
query_params: query_params,
416+
cookie_params: cookie_params,
417+
form_params: form_params
418+
)
419+
397420
if @api_client.config.debugging
398421
Log.debug {"API called: PetApi#update_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
399422
end
423+
400424
return Pet.from_json(data), status_code, headers
401425
end
402426

@@ -449,19 +473,23 @@ module Petstore
449473
# auth_names
450474
auth_names = ["petstore_auth"]
451475

452-
data, status_code, headers = @api_client.call_api(:POST,
453-
local_var_path,
454-
:"PetApi.update_pet_with_form",
455-
return_type,
456-
post_body,
457-
auth_names,
458-
header_params,
459-
query_params,
460-
cookie_params,
461-
form_params)
476+
data, status_code, headers = @api_client.call_api(
477+
http_method: :POST,
478+
path: local_var_path,
479+
operation: :"PetApi.update_pet_with_form",
480+
return_type: return_type,
481+
post_body: post_body,
482+
auth_names: auth_names,
483+
header_params: header_params,
484+
query_params: query_params,
485+
cookie_params: cookie_params,
486+
form_params: form_params
487+
)
488+
462489
if @api_client.config.debugging
463490
Log.debug {"API called: PetApi#update_pet_with_form\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
464491
end
492+
465493
return nil, status_code, headers
466494
end
467495

@@ -516,19 +544,23 @@ module Petstore
516544
# auth_names
517545
auth_names = ["petstore_auth"]
518546

519-
data, status_code, headers = @api_client.call_api(:POST,
520-
local_var_path,
521-
:"PetApi.upload_file",
522-
return_type,
523-
post_body,
524-
auth_names,
525-
header_params,
526-
query_params,
527-
cookie_params,
528-
form_params)
547+
data, status_code, headers = @api_client.call_api(
548+
http_method: :POST,
549+
path: local_var_path,
550+
operation: :"PetApi.upload_file",
551+
return_type: return_type,
552+
post_body: post_body,
553+
auth_names: auth_names,
554+
header_params: header_params,
555+
query_params: query_params,
556+
cookie_params: cookie_params,
557+
form_params: form_params
558+
)
559+
529560
if @api_client.config.debugging
530561
Log.debug {"API called: PetApi#upload_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
531562
end
563+
532564
return ApiResponse.from_json(data), status_code, headers
533565
end
534566
end

0 commit comments

Comments
 (0)