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

python.api.mustache Maven / Gradle / Ivy

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

{{>partial_header}}

import io
import warnings

from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any

try:
    from typing import Annotated
except ImportError:
    from typing_extensions import Annotated

{{#imports}}
{{import}}
{{/imports}}

from {{packageName}}.api_client import ApiClient
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.rest import RESTResponseType


{{#operations}}
class {{classname}}:
    """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) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client
{{#operation}}


    @validate_call
    {{#asyncio}}async {{/asyncio}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}
        response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        {{#asyncio}}await {{/asyncio}}response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    {{#asyncio}}async {{/asyncio}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}
        response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        {{#asyncio}}await {{/asyncio}}response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    {{#asyncio}}async {{/asyncio}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}
        response_data = {{#asyncio}}await {{/asyncio}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _{{operationId}}_serialize(
        self,
        {{#allParams}}
        {{paramName}},
        {{/allParams}}
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> Tuple:

        {{#servers.0}}
        _hosts = [{{#servers}}
            '{{{url}}}'{{^-last}},{{/-last}}{{/servers}}
        ]
        _host = _hosts[_host_index]
        {{/servers.0}}
        {{^servers.0}}
        _host = None
        {{/servers.0}}

        _collection_formats: Dict[str, str] = {
            {{#allParams}}{{#isArray}}
            '{{baseName}}': '{{collectionFormat}}',{{/isArray}}{{/allParams}}
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[str, str] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
{{#pathParams}}
        if {{paramName}} is not None:
            _path_params['{{baseName}}'] = {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}
{{/pathParams}}
        # process the query parameters
{{#queryParams}}
        if {{paramName}} is not None:
            {{#isDateTime}}
            if isinstance({{paramName}}, datetime):
                _query_params.append(
                    (
                        '{{baseName}}',
                        {{paramName}}.strftime(
                            self.api_client.configuration.datetime_format
                        )
                    )
                )
            else:
                _query_params.append(('{{baseName}}', {{paramName}}))
            {{/isDateTime}}
            {{#isDate}}
            if isinstance({{paramName}}, date):
                _query_params.append(
                    (
                        '{{baseName}}',
                        {{paramName}}.strftime(
                            self.api_client.configuration.date_format
                        )
                    )
                )
            else:
                _query_params.append(('{{baseName}}', {{paramName}}))
            {{/isDate}}
            {{^isDateTime}}{{^isDate}}
            _query_params.append(('{{baseName}}', {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}))
            {{/isDate}}{{/isDateTime}}
{{/queryParams}}
        # process the header parameters
{{#headerParams}}
        if {{paramName}} is not None:
            _header_params['{{baseName}}'] = {{paramName}}
{{/headerParams}}
        # process the form parameters
{{#formParams}}
        if {{paramName}} is not None:
            {{#isFile}}
            _files['{{{baseName}}}'] = {{paramName}}
            {{/isFile}}
            {{^isFile}}
            _form_params.append(('{{{baseName}}}', {{paramName}}))
            {{/isFile}}
{{/formParams}}
        # process the body parameter
{{#bodyParam}}
        if {{paramName}} is not None:
            {{#isBinary}}
            # convert to byte array if the input is a file name (str)
            if isinstance({{paramName}}, str):
                with io.open({{paramName}}, "rb") as _fp:
                    _body_params = _fp.read()
            else:
                _body_params = {{paramName}}
            {{/isBinary}}
            {{^isBinary}}
            _body_params = {{paramName}}
            {{/isBinary}}
{{/bodyParam}}

        {{#constantParams}}
        {{#isQueryParam}}
        # Set client side default value of Query Param "{{baseName}}".
        _query_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
        {{/isQueryParam}}
        {{#isHeaderParam}}
        # Set client side default value of Header Param "{{baseName}}".
        _header_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
        {{/isHeaderParam}}
        {{/constantParams}}

        {{#hasProduces}}
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            [{{#produces}}
                '{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}
            ]
        )
        {{/hasProduces}}

        {{#hasConsumes}}
        # set the HTTP header `Content-Type`
        if _content_type:
            _header_params['Content-Type'] = _content_type
        else:
            _default_content_type = (
                self.api_client.select_header_content_type(
                    [{{#consumes}}
                        '{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}
                    ]
                )
            )
            if _default_content_type is not None:
                _header_params['Content-Type'] = _default_content_type
        {{/hasConsumes}}

        # authentication setting
        _auth_settings: List[str] = [{{#authMethods}}
            '{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}
        ]

        return self.api_client.param_serialize(
            method='{{httpMethod}}',
            resource_path='{{{path}}}',
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth
        )


{{/operation}}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy