github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/python/api.mustache (about) 1 # coding: utf-8 2 3 {{>partial_header}} 4 5 from __future__ import absolute_import 6 7 import re # noqa: F401 8 9 # python 2 and python 3 compatibility library 10 import six 11 12 from {{packageName}}.api_client import ApiClient 13 from {{packageName}}.exceptions import ( # noqa: F401 14 ApiTypeError, 15 ApiValueError 16 ) 17 18 19 {{#operations}} 20 class {{classname}}(object): 21 """NOTE: This class is auto generated by OpenAPI Generator 22 Ref: https://openapi-generator.tech 23 24 Do not edit the class manually. 25 """ 26 27 def __init__(self, api_client=None): 28 if api_client is None: 29 api_client = ApiClient() 30 self.api_client = api_client 31 {{#operation}} 32 33 def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501 34 """{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501 35 36 {{#notes}} 37 {{{notes}}} # noqa: E501 38 {{/notes}} 39 This method makes a synchronous HTTP request by default. To make an 40 asynchronous HTTP request, please pass async_req=True 41 {{#sortParamsByRequiredFlag}} 42 >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True) 43 {{/sortParamsByRequiredFlag}} 44 {{^sortParamsByRequiredFlag}} 45 >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True) 46 {{/sortParamsByRequiredFlag}} 47 >>> result = thread.get() 48 49 :param async_req bool: execute request asynchronously 50 {{#allParams}} 51 :param {{dataType}} {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}} 52 {{/allParams}} 53 :param _preload_content: if False, the urllib3.HTTPResponse object will 54 be returned without reading/decoding response 55 data. Default is True. 56 :param _request_timeout: timeout setting for this request. If one 57 number provided, it will be total request 58 timeout. It can also be a pair (tuple) of 59 (connection, read) timeouts. 60 :return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}} 61 If the method is called asynchronously, 62 returns the request thread. 63 """ 64 kwargs['_return_http_data_only'] = True 65 return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) # noqa: E501 66 67 def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501 68 """{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501 69 70 {{#notes}} 71 {{{notes}}} # noqa: E501 72 {{/notes}} 73 This method makes a synchronous HTTP request by default. To make an 74 asynchronous HTTP request, please pass async_req=True 75 {{#sortParamsByRequiredFlag}} 76 >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True) 77 {{/sortParamsByRequiredFlag}} 78 {{^sortParamsByRequiredFlag}} 79 >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True) 80 {{/sortParamsByRequiredFlag}} 81 >>> result = thread.get() 82 83 :param async_req bool: execute request asynchronously 84 {{#allParams}} 85 :param {{dataType}} {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/optional}} 86 {{/allParams}} 87 :param _return_http_data_only: response data without head status code 88 and headers 89 :param _preload_content: if False, the urllib3.HTTPResponse object will 90 be returned without reading/decoding response 91 data. Default is True. 92 :param _request_timeout: timeout setting for this request. If one 93 number provided, it will be total request 94 timeout. It can also be a pair (tuple) of 95 (connection, read) timeouts. 96 :return: {{#returnType}}tuple({{returnType}}, status_code(int), headers(HTTPHeaderDict)){{/returnType}}{{^returnType}}None{{/returnType}} 97 If the method is called asynchronously, 98 returns the request thread. 99 """ 100 101 {{#servers.0}} 102 local_var_hosts = [ 103 {{#servers}} 104 '{{{url}}}'{{^-last}},{{/-last}} 105 {{/servers}} 106 ] 107 local_var_host = local_var_hosts[0] 108 if kwargs.get('_host_index'): 109 _host_index = int(kwargs.get('_host_index')) 110 if _host_index < 0 or _host_index >= len(local_var_hosts): 111 raise ApiValueError( 112 "Invalid host index. Must be 0 <= index < %s" 113 % len(local_var_host) 114 ) 115 local_var_host = local_var_hosts[_host_index] 116 {{/servers.0}} 117 local_var_params = locals() 118 119 all_params = [ 120 {{#allParams}} 121 '{{paramName}}'{{^-last}},{{/-last}} 122 {{/allParams}} 123 ] 124 all_params.extend( 125 [ 126 'async_req', 127 '_return_http_data_only', 128 '_preload_content', 129 '_request_timeout' 130 ] 131 ) 132 133 for key, val in six.iteritems(local_var_params['kwargs']): 134 if key not in all_params{{#servers.0}} and key != "_host_index"{{/servers.0}}: 135 raise ApiTypeError( 136 "Got an unexpected keyword argument '%s'" 137 " to method {{operationId}}" % key 138 ) 139 local_var_params[key] = val 140 del local_var_params['kwargs'] 141 {{#allParams}} 142 {{^isNullable}} 143 {{#required}} 144 # verify the required parameter '{{paramName}}' is set 145 if self.api_client.client_side_validation and ('{{paramName}}' not in local_var_params or # noqa: E501 146 local_var_params['{{paramName}}'] is None): # noqa: E501 147 raise ApiValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501 148 {{/required}} 149 {{/isNullable}} 150 {{/allParams}} 151 152 {{#allParams}} 153 {{#hasValidation}} 154 {{#maxLength}} 155 if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501 156 len(local_var_params['{{paramName}}']) > {{maxLength}}): # noqa: E501 157 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501 158 {{/maxLength}} 159 {{#minLength}} 160 if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501 161 len(local_var_params['{{paramName}}']) < {{minLength}}): # noqa: E501 162 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501 163 {{/minLength}} 164 {{#maximum}} 165 if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501 166 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501 167 {{/maximum}} 168 {{#minimum}} 169 if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501 170 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501 171 {{/minimum}} 172 {{#pattern}} 173 if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and not re.search(r'{{{vendorExtensions.x-regex}}}', local_var_params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501 174 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`") # noqa: E501 175 {{/pattern}} 176 {{#maxItems}} 177 if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501 178 len(local_var_params['{{paramName}}']) > {{maxItems}}): # noqa: E501 179 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501 180 {{/maxItems}} 181 {{#minItems}} 182 if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and # noqa: E501 183 len(local_var_params['{{paramName}}']) < {{minItems}}): # noqa: E501 184 raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501 185 {{/minItems}} 186 {{/hasValidation}} 187 {{#-last}} 188 {{/-last}} 189 {{/allParams}} 190 collection_formats = {} 191 192 path_params = {} 193 {{#pathParams}} 194 if '{{paramName}}' in local_var_params: 195 path_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}} # noqa: E501 196 collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501 197 {{/pathParams}} 198 199 query_params = [] 200 {{#queryParams}} 201 if '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] is not None: # noqa: E501 202 query_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{#isArray}} # noqa: E501 203 collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501 204 {{/queryParams}} 205 206 header_params = {} 207 {{#headerParams}} 208 if '{{paramName}}' in local_var_params: 209 header_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}} # noqa: E501 210 collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501 211 {{/headerParams}} 212 213 form_params = [] 214 local_var_files = {} 215 {{#formParams}} 216 if '{{paramName}}' in local_var_params: 217 {{^isFile}}form_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{/isFile}}{{#isFile}}local_var_files['{{baseName}}'] = local_var_params['{{paramName}}']{{/isFile}}{{#isArray}} # noqa: E501 218 collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}} # noqa: E501 219 {{/formParams}} 220 221 body_params = None 222 {{#bodyParam}} 223 if '{{paramName}}' in local_var_params: 224 body_params = local_var_params['{{paramName}}'] 225 {{/bodyParam}} 226 {{#hasProduces}} 227 # HTTP header `Accept` 228 header_params['Accept'] = self.api_client.select_header_accept( 229 [{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) # noqa: E501 230 231 {{/hasProduces}} 232 {{#hasConsumes}} 233 # HTTP header `Content-Type` 234 header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 235 [{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]) # noqa: E501 236 237 {{/hasConsumes}} 238 # Authentication setting 239 auth_settings = [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] # noqa: E501 240 241 return self.api_client.call_api( 242 '{{{path}}}', '{{httpMethod}}', 243 path_params, 244 query_params, 245 header_params, 246 body=body_params, 247 post_params=form_params, 248 files=local_var_files, 249 response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}}, # noqa: E501 250 auth_settings=auth_settings, 251 async_req=local_var_params.get('async_req'), 252 _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 253 _preload_content=local_var_params.get('_preload_content', True), 254 _request_timeout=local_var_params.get('_request_timeout'), 255 {{#servers.0}} 256 _host=local_var_host, 257 {{/servers.0}} 258 collection_formats=collection_formats) 259 {{/operation}} 260 {{/operations}}