-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathapi.mustache
More file actions
189 lines (169 loc) · 9.55 KB
/
api.mustache
File metadata and controls
189 lines (169 loc) · 9.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}}
require "uri"
module {{moduleName}}
{{#operations}}
class {{classname}}
property api_client : ApiClient
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
{{#operation}}
{{#summary}}
# {{{.}}}
{{/summary}}
{{#notes}}
# {{{.}}}
{{/notes}}
{{#allParams}}
{{#required}}
# @param {{paramName}} [{{{dataType}}}{{^required}}?{{/required}}] {{description}}
{{/required}}
{{/allParams}}
# @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
def {{operationId}}({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
{{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
{{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}}
end
{{#summary}}
# {{.}}
{{/summary}}
{{#notes}}
# {{.}}
{{/notes}}
{{#allParams}}
{{#required}}
# @param {{paramName}} [{{{dataType}}}{{^required}}?{{/required}}] {{description}}
{{/required}}
{{/allParams}}
# @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
def {{operationId}}_with_http_info({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
if @api_client.config.debugging
Log.debug {"Calling API: {{classname}}.{{operationId}} ..."}
end
{{#allParams}}
{{^isNullable}}
{{#required}}
# verify the required parameter "{{paramName}}" is set
if @api_client.config.client_side_validation && {{{paramName}}}.nil?
raise ArgumentError.new("Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}")
end
{{#isEnum}}
{{^isContainer}}
# verify enum value
allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
if @api_client.config.client_side_validation && !allowable_values.includes?({{{paramName}}})
raise ArgumentError.new("invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}")
end
{{/isContainer}}
{{/isEnum}}
{{/required}}
{{/isNullable}}
{{^required}}
{{#isEnum}}
{{#collectionFormat}}
allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
if @api_client.config.client_side_validation && {{{paramName}}} && {{{paramName}}}.all? { |item| allowable_values.includes?(item) }
raise ArgumentError.new("invalid value for \"{{{paramName}}}\", must include one of #{allowable_values}")
end
{{/collectionFormat}}
{{^collectionFormat}}
allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
if @api_client.config.client_side_validation && {{{paramName}}} && !allowable_values.includes?({{{paramName}}})
raise ArgumentError.new("invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}")
end
{{/collectionFormat}}
{{/isEnum}}
{{/required}}
{{#hasValidation}}
{{#maxLength}}
if @api_client.config.client_side_validation && {{^required}}!{{{paramName}}}.nil? && {{/required}}{{{paramName}}}.to_s.size > {{{maxLength}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.")
end
{{/maxLength}}
{{#minLength}}
if @api_client.config.client_side_validation && {{^required}}!{{{paramName}}}.nil? && {{/required}}{{{paramName}}}.to_s.size < {{{minLength}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, the character length must be greater than or equal to {{{minLength}}}.")
end
{{/minLength}}
{{#maximum}}
if @api_client.config.client_side_validation && {{^required}}!{{{paramName}}}.nil? && {{/required}}{{{paramName}}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.")
end
{{/maximum}}
{{#minimum}}
if @api_client.config.client_side_validation && {{^required}}!{{{paramName}}}.nil? && {{/required}}{{{paramName}}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.")
end
{{/minimum}}
{{#pattern}}
pattern = Regexp.new({{{pattern}}})
if @api_client.config.client_side_validation && {{^required}}{{{paramName}}}.nil? && {{/required}}{{{paramName}}} !~ pattern
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern #{pattern}.")
end
{{/pattern}}
{{#maxItems}}
if @api_client.config.client_side_validation && {{^required}}{{{paramName}}}.nil? && {{/required}}{{{paramName}}}.size > {{{maxItems}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{{maxItems}}}.")
end
{{/maxItems}}
{{#minItems}}
if @api_client.config.client_side_validation && {{^required}}{{{paramName}}}.nil? && {{/required}}{{{paramName}}}.size < {{{minItems}}}
raise ArgumentError.new("invalid value for \"{{{paramName}}}\" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{{minItems}}}.")
end
{{/minItems}}
{{/hasValidation}}
{{/allParams}}
# resource path
local_var_path = "{{{path}}}"{{#pathParams}}.sub("{" + "{{baseName}}" + "}", URI.encode_path({{paramName}}.to_s){{^strictSpecBehavior}}.gsub("%2F", "/"){{/strictSpecBehavior}}){{/pathParams}}
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters
query_params = Hash(String, String | Array(String)).new
{{#queryParams}}
query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}) unless {{{paramName}}}.nil?{{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}}
{{/queryParams}}
# header parameters
header_params = Hash(String, String).new
{{#hasProduces}}
# HTTP header "Accept" (if needed)
header_params["Accept"] = @api_client.select_header_accept([{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}])
{{/hasProduces}}
{{#hasConsumes}}
# HTTP header "Content-Type"
header_params["Content-Type"] = @api_client.select_header_content_type([{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}])
{{/hasConsumes}}
{{#headerParams}}
header_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}}
{{/headerParams}}
# form parameters
form_params = Hash(Symbol, (String | ::File)).new
{{#formParams}}
form_params[:"{{baseName}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}} unless {{{paramName}}}.nil?{{/collectionFormat}}
{{/formParams}}
# http body (model)
post_body = {{#bodyParam}}{{{paramName}}}.to_json{{/bodyParam}}{{^bodyParam}}nil{{/bodyParam}}
# return_type
return_type = {{#returnType}}"{{{.}}}"{{/returnType}}{{^returnType}}nil{{/returnType}}
# auth_names
auth_names = {{#authMethods}}{{#-first}}[{{/-first}}"{{name}}"{{^-last}}, {{/-last}}{{#-last}}]{{/-last}}{{/authMethods}}{{^authMethods}}[] of String{{/authMethods}}
data, status_code, headers = @api_client.call_api(:{{httpMethod}},
local_var_path,
:"{{classname}}.{{operationId}}",
return_type,
post_body,
auth_names,
header_params,
query_params,
cookie_params,
form_params)
if @api_client.config.debugging
Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
end
return {{#returnType}}{{{.}}}.from_json(data){{/returnType}}{{^returnType}}nil{{/returnType}}, status_code, headers
end
{{^-last}}
{{/-last}}
{{/operation}}
end
{{/operations}}
end