# Path: muffin_rest/openapi.py
# def render_openapi(api, request):
#     """Prepare openapi specs."""
#     # Setup Specs
#     options = dict(api.openapi_options)
#     options.setdefault('servers', [{
#         'url': str(request.url.with_query('').with_path(api.prefix))
#     }])
# 
#     spec = APISpec(
#         options['info'].pop('title', f"{ api.app.cfg.name.title() } API"),
#         options['info'].pop('version', '1.0.0'),
#         options.pop('openapi_version', '3.0.0'),
#         **options, plugins=[MarshmallowPlugin()])
#     spec.tags = {}
# 
#     # Setup Authorization
#     if api.authorize:
#         _, _, schema = parse_docs(api.authorize)
#         spec.options['security'] = []
#         for key, value in schema.items():
#             spec.components.security_scheme(key, value)
#             spec.options['security'].append({key: []})
# 
#     # Setup Paths
#     routes = api.router.routes()
#     for route in routes:
#         if route.path in SKIP_PATH:
#             continue
# 
#         spec.path(route.path, **route_to_spec(route, spec))
# 
#     return spec.to_dict()


import dataclasses as dc
import typing as t
import muffin
from pathlib import Path
from http_router import Router
from muffin.utils import to_awaitable
from .openapi import render_openapi
        from .handler import RESTBase
        if self.app is None:
            raise RuntimeError('API must be binded to an app.')

        return self.app.logger

    def setup(self, app: muffin.Application, prefix: str = '',
              openapi: bool = None, *, servers: t.List = None, **openapi_info):
        """Initialize the API."""
        self.app = app
        self.prefix = (prefix or self.prefix).rstrip('/')

        # Setup routing
        self.router.trim_last_slash = self.app.router.trim_last_slash
        self.router.validator = self.app.router.validator                   # type: ignore
        self.app.router.route(self.prefix)(self.router)

        if openapi is not None:
            self.openapi = openapi

        if openapi_info:
            self.openapi_options['info'] = openapi_info

        if servers:
            self.openapi_options['servers'] = servers

        # Setup API Docs
        if not self.openapi:
            return

        async def openapi_json(request):

# Path: muffin_rest/openapi.py
# def render_openapi(api, request):
#     """Prepare openapi specs."""
#     # Setup Specs
#     options = dict(api.openapi_options)
#     options.setdefault('servers', [{
#         'url': str(request.url.with_query('').with_path(api.prefix))
#     }])
# 
#     spec = APISpec(
#         options['info'].pop('title', f"{ api.app.cfg.name.title() } API"),
#         options['info'].pop('version', '1.0.0'),
#         options.pop('openapi_version', '3.0.0'),
#         **options, plugins=[MarshmallowPlugin()])
#     spec.tags = {}
# 
#     # Setup Authorization
#     if api.authorize:
#         _, _, schema = parse_docs(api.authorize)
#         spec.options['security'] = []
#         for key, value in schema.items():
#             spec.components.security_scheme(key, value)
#             spec.options['security'].append({key: []})
# 
#     # Setup Paths
#     routes = api.router.routes()
#     for route in routes:
#         if route.path in SKIP_PATH:
#             continue
# 
#         spec.path(route.path, **route_to_spec(route, spec))
# 
#     return spec.to_dict()


# Path: muffin_rest/api.py
import dataclasses as dc
import typing as t
import muffin
from pathlib import Path
from http_router import Router
from muffin.utils import to_awaitable
from .openapi import render_openapi
        from .handler import RESTBase

        if self.app is None:
            raise RuntimeError('API must be binded to an app.')

        return self.app.logger

    def setup(self, app: muffin.Application, prefix: str = '',
              openapi: bool = None, *, servers: t.List = None, **openapi_info):
        """Initialize the API."""
        self.app = app
        self.prefix = (prefix or self.prefix).rstrip('/')

        # Setup routing
        self.router.trim_last_slash = self.app.router.trim_last_slash
        self.router.validator = self.app.router.validator                   # type: ignore
        self.app.router.route(self.prefix)(self.router)

        if openapi is not None:
            self.openapi = openapi

        if openapi_info:
            self.openapi_options['info'] = openapi_info

        if servers:
            self.openapi_options['servers'] = servers

        # Setup API Docs
        if not self.openapi:
            return

        async def openapi_json(request):

            return render_openapi(self, request=request)