Skip to content

Main

fastapi_gateway_auto_generate.Generator

Generator(config)

The class responsible for adding automatic service connections to the FastAPI object.

Parameters:

Name Type Description Default
config Config

The Config object with its configuration.

required
Source code in fastapi_gateway_auto_generate/Generator.py
def __init__(self, config: Config) -> None:
    self.__config = config

    if not os.path.isfile(self.__config.db_path):
        InitDatabaseUsecase().execute(db_url=config.db_url, db_path=config.db_path)

    if self.__config.service_management:
        self.__init_management_urls()

    self.build()

__init_management_urls()

Service management initialization.

Source code in fastapi_gateway_auto_generate/Generator.py
def __init_management_urls(self):
    """Service management initialization.
    """
    Management(config=self.__config)

build()

Adding services to the FastAPI object.

Source code in fastapi_gateway_auto_generate/Generator.py
def build(self) -> None:
    """Adding services to the FastAPI object.
    """

    services_result = BuildRouteModelsUsecase().execute(
        config=self.__config
    )

    BuildRoutesUsecase().execute(
        services_result=services_result,
        fast_api_app=self.__config.fast_api_app
    )

fastapi_gateway_auto_generate.Config

Config(fast_api_app, service_management=True, db_path='./', db_name='database', jwt=None)

The Configuration class is intended for configuring the auto-generation of services for the API Gateway.

Parameters:

Name Type Description Default
fast_api_app FastAPI

Pointer to your FastAPI application.

required
service_management bool

Enable the built-in service manager.

True
db_path str

The path to the SQLite database.

'./'
jwt Optional[Type[T]]

The class responsible for protecting the routers.

None
celery_app Optional[Celery]

The Celery object responsible for transferring large files.

required
Source code in fastapi_gateway_auto_generate/Config.py
def __init__(
        self,
        fast_api_app: FastAPI,
        service_management: bool = True,
        db_path: str = "./",
        db_name: str = "database",
        jwt: Optional[Type[T]] = None,
        # allow_large_files: bool = False,
        # broker_url: str = ""
) -> None:
    self.fast_api_app: FastAPI = fast_api_app
    self.service_management: bool = service_management
    self.jwt = jwt
    self.service_name = "API-Gateway"

    if db_name != "database":
        self.db_name = db_name
    else:
        self.db_name = "database"

    if db_path != "./":
        self.db_path = db_path
    else:
        self.db_path = "./"

    # self.db_path = "./database.db" if db_path is None else db_path
    self.db_url = f"sqlite:///{self.get_database_absolute_path()}"

Warning

The service_management parameter is temporarily not functioning and will always be set to True.