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

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

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

from typing import Dict, List  # noqa: F401
import importlib
import pkgutil

from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}}
import {{fastapiImplementationPackage}}

from fastapi import (  # noqa: F401
    APIRouter,
    Body,
    Cookie,
    Depends,
    Form,
    Header,
    Path,
    Query,
    Response,
    Security,
    status,
)

from {{modelPackage}}.extra_models import TokenModel  # noqa: F401
{{#imports}}
{{import}}
{{/imports}}
{{#securityImports.0}}from {{packageName}}.security_api import {{#securityImports}}get_token_{{.}}{{^-last}}, {{/-last}}{{/securityImports}}{{/securityImports.0}}

router = APIRouter()

ns_pkg = {{fastapiImplementationPackage}}
for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
    importlib.import_module(name)


{{#operations}}
{{#operation}}
@router.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(
    "{{path}}",
    responses={
        {{#responses}}
        {{code}}: {{=<% %>=}}{<%#dataType%>"model": <%dataType%>, "description": "<%message%>"<%/dataType%><%^dataType%>"description": "<%message%>"<%/dataType%>}<%={{ }}=%>,
        {{/responses}}
    },
    tags=[{{#tags}}"{{name}}"{{^-last}},{{/-last}}{{/tags}}],
    {{#summary}}
    summary="{{.}}",
    {{/summary}}
    {{#description}}
    description = "{{.}}",
    {{/description}}
    response_model_by_alias=True,
)
async def {{operationId}}(
    {{#allParams}}
    {{>endpoint_argument_definition}},
    {{/allParams}}
    {{#hasAuthMethods}}
    {{#authMethods}}
    token_{{name}}: TokenModel = Security(
        get_token_{{name}}{{#isOAuth}}, scopes=[{{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}
    ),
    {{/authMethods}}
    {{/hasAuthMethods}}
) -> {{returnType}}{{^returnType}}None{{/returnType}}:
    {{#notes}}"""{{.}}"""
    return Base{{classname}}.subclasses[0]().{{operationId}}({{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}}){{/notes}}{{^notes}}...{{/notes}}
{{^-last}}


{{/-last}}
{{/operation}}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy