import typer from location import config from location.cli.utils import check_schema, dump_schema cli: typer.Typer = typer.Typer(short_help="Perform API commands.", no_args_is_help=True) @cli.command("gen-spec") def gen_spec() -> None: """ Generate OpenAPI specification. """ from location.api.main import app dump_schema(app, filepath=config.OPENAPI_FILEPATH) typer.secho( ( f"OpenAPI specification was successfully " f"generated to `{config.OPENAPI_FILEPATH}`", ), fg="green", ) @cli.command("check-spec") def check_spec() -> None: """ Check that service has latest OpenAPI specification. """ from location.api.main import app if not check_schema(app, filepath=config.OPENAPI_FILEPATH): typer.secho( "Service OpenAPI specification is not equals to actual one. " "Please, generate new one with `python manage.py api gen-spec`.", fg="red", ) raise typer.Exit(1) typer.secho("You have latest OpenAPI specification generated.", fg="green")