summaryrefslogtreecommitdiffstats
path: root/openbb_platform/core/openbb_core/api/app_loader.py
blob: d6ff19878ca43d07f8e8b3571202e976faa5ad9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""App loader module."""

from typing import List, Optional

from fastapi import APIRouter, FastAPI
from openbb_core.app.router import RouterLoader


class AppLoader:
    """App loader."""

    @staticmethod
    def get_openapi_tags() -> List[dict]:
        """Get openapi tags."""
        main_router = RouterLoader.from_extensions()
        openapi_tags = []
        # Add tag data for each router in the main router
        for r in main_router.routers:
            openapi_tags.append(
                {
                    "name": r,
                    "description": main_router.get_attr(r, "description"),
                }
            )
        return openapi_tags

    @staticmethod
    def from_routers(
        app: FastAPI, routers: List[Optional[APIRouter]], prefix: str
    ) -> FastAPI:
        """Load routers to app."""
        for router in routers:
            if router:
                app.include_router(router=router, prefix=prefix)

        return app