All Downloads are FREE. Search and download functionalities are using the official Maven repository.

python-legacy.api.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
# coding: utf-8

{{>partial_header}}

from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from {{packageName}}.api_client import ApiClient
from {{packageName}}.exceptions import (  # noqa: F401
    ApiTypeError,
    ApiValueError
)


{{#operations}}
class {{classname}}(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client
{{#operation}}

    def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):  # noqa: E501
        """{{{summary}}}{{^summary}}{{operationId}}{{/summary}}  # noqa: E501

{{#notes}}
        {{{.}}}  # noqa: E501
{{/notes}}
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

{{#sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
        >>> result = thread.get()

{{#allParams}}
        :param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
        :type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: {{returnType}}{{^returnType}}None{{/returnType}}
        """
        kwargs['_return_http_data_only'] = True
        return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)  # noqa: E501

    def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):  # noqa: E501
        """{{{summary}}}{{^summary}}{{operationId}}{{/summary}}  # noqa: E501

{{#notes}}
        {{{.}}}  # noqa: E501
{{/notes}}
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

{{#sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
{{^sortParamsByRequiredFlag}}
        >>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True)
{{/sortParamsByRequiredFlag}}
        >>> result = thread.get()

{{#allParams}}
        :param {{paramName}}:{{#description}} {{{.}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
        :type {{paramName}}: {{dataType}}{{#optional}}, optional{{/optional}}
{{/allParams}}
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _return_http_data_only: response data without head status code
                                       and headers
        :type _return_http_data_only: bool, optional
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :type _preload_content: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: {{#returnType}}tuple({{.}}, status_code(int), headers(HTTPHeaderDict)){{/returnType}}{{^returnType}}None{{/returnType}}
        """

        {{#servers.0}}
        local_var_hosts = [
{{#servers}}
            '{{{url}}}'{{^-last}},{{/-last}}
{{/servers}}
        ]
        local_var_host = local_var_hosts[0]
        if kwargs.get('_host_index'):
            _host_index = int(kwargs.get('_host_index'))
            if _host_index < 0 or _host_index >= len(local_var_hosts):
                raise ApiValueError(
                    "Invalid host index. Must be 0 <= index < %s"
                    % len(local_var_host)
                )
            local_var_host = local_var_hosts[_host_index]
        {{/servers.0}}
        local_var_params = locals()

        all_params = [
{{#allParams}}
            '{{paramName}}'{{^-last}},{{/-last}}
{{/allParams}}
        ]
        all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type'
            ]
        )

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params{{#servers.0}} and key != "_host_index"{{/servers.0}}:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method {{operationId}}" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']
{{#allParams}}
{{^isNullable}}
{{#required}}
        # verify the required parameter '{{paramName}}' is set
        if self.api_client.client_side_validation and ('{{paramName}}' not in local_var_params or  # noqa: E501
                                                        local_var_params['{{paramName}}'] is None):  # noqa: E501
            raise ApiValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`")  # noqa: E501
{{/required}}
{{/isNullable}}
{{/allParams}}

{{#allParams}}
{{#hasValidation}}
    {{#maxLength}}
        if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and  # noqa: E501
                                                        len(local_var_params['{{paramName}}']) > {{maxLength}}):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`")  # noqa: E501
    {{/maxLength}}
    {{#minLength}}
        if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and  # noqa: E501
                                                        len(local_var_params['{{paramName}}']) < {{minLength}}):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`")  # noqa: E501
    {{/minLength}}
    {{#maximum}}
        if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`")  # noqa: E501
    {{/maximum}}
    {{#minimum}}
        if self.api_client.client_side_validation and '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}:  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`")  # noqa: E501
    {{/minimum}}
    {{#pattern}}
        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
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`")  # noqa: E501
    {{/pattern}}
    {{#maxItems}}
        if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and  # noqa: E501
                                                        len(local_var_params['{{paramName}}']) > {{maxItems}}):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`")  # noqa: E501
    {{/maxItems}}
    {{#minItems}}
        if self.api_client.client_side_validation and ('{{paramName}}' in local_var_params and  # noqa: E501
                                                        len(local_var_params['{{paramName}}']) < {{minItems}}):  # noqa: E501
            raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`")  # noqa: E501
    {{/minItems}}
{{/hasValidation}}
{{#-last}}
{{/-last}}
{{/allParams}}
        collection_formats = {}

        path_params = {}
{{#pathParams}}
        if '{{paramName}}' in local_var_params:
            path_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}}  # noqa: E501
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}}  # noqa: E501
{{/pathParams}}

        query_params = []
{{#queryParams}}
        if '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] is not None:  # noqa: E501
            query_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{#isArray}}  # noqa: E501
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}}  # noqa: E501
{{/queryParams}}

        header_params = {}
{{#headerParams}}
        if '{{paramName}}' in local_var_params:
            header_params['{{baseName}}'] = local_var_params['{{paramName}}']{{#isArray}}  # noqa: E501
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}}  # noqa: E501
{{/headerParams}}

        form_params = []
        local_var_files = {}
{{#formParams}}
        if '{{paramName}}' in local_var_params:
            {{^isFile}}form_params.append(('{{baseName}}', local_var_params['{{paramName}}'])){{/isFile}}{{#isFile}}local_var_files['{{baseName}}'] = local_var_params['{{paramName}}']{{/isFile}}{{#isArray}}  # noqa: E501
            collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isArray}}  # noqa: E501
{{/formParams}}

        body_params = None
{{#bodyParam}}
        if '{{paramName}}' in local_var_params:
            body_params = local_var_params['{{paramName}}']
{{/bodyParam}}
        {{#hasProduces}}
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            [{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}])  # noqa: E501

        {{/hasProduces}}
        {{#hasConsumes}}
        # HTTP header `Content-Type`
        header_params['Content-Type'] = local_var_params.get('_content_type',
            self.api_client.select_header_content_type(
                [{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}],
                '{{httpMethod}}', body_params))  # noqa: E501

        {{/hasConsumes}}
        # Authentication setting
        auth_settings = [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}]  # noqa: E501

        {{#returnType}}
        {{#responses}}
        {{#-first}}
        response_types_map = {
        {{/-first}}
            {{^isWildcard}}
            {{code}}: {{#dataType}}"{{.}}"{{/dataType}}{{^dataType}}None{{/dataType}},
            {{/isWildcard}}
        {{#-last}}
        }
        {{/-last}}
        {{/responses}}
        {{/returnType}}
        {{^returnType}}
        response_types_map = {}
        {{/returnType}}

        return self.api_client.call_api(
            '{{{path}}}', '{{httpMethod}}',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_types_map=response_types_map,
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            {{#servers.0}}
            _host=local_var_host,
            {{/servers.0}}
            collection_formats=collection_formats,
            _request_auth=local_var_params.get('_request_auth'))
{{/operation}}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy