diff --git a/README.md b/README.md index 10d374a..551c124 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Options: -n, --name TEXT Name of your awesome project -V, --version Prints current version --force Owerrite directory if it exists - --quite Do not ask for features during generation + --quiet Do not ask for features during generation --api-type [rest|graphql] Select API type for your application --db [none|sqlite|mysql|postgresql|mongodb] Select a database for your app diff --git a/fastapi_template/cli.py b/fastapi_template/cli.py index 64d8128..58f6a17 100644 --- a/fastapi_template/cli.py +++ b/fastapi_template/cli.py @@ -41,8 +41,8 @@ def disable_orm(ctx: BuilderContext) -> MenuEntry: return None -def do_not_ask_features_if_quite(ctx: BuilderContext) -> Optional[List[MenuEntry]]: - if ctx.quite: +def do_not_ask_features_if_quiet(ctx: BuilderContext) -> Optional[List[MenuEntry]]: + if ctx.quiet: return [SKIP_ENTRY] return None @@ -342,7 +342,7 @@ def checker(ctx: BuilderContext) -> bool: code="features", description="Additional project features", multiselect=True, - before_ask=do_not_ask_features_if_quite, + before_ask=do_not_ask_features_if_quiet, entries=[ MenuEntry( code="pydanticv1", @@ -627,7 +627,7 @@ def run_command(callback: Callable[[BuilderContext], None]) -> None: help="Owerrite directory if it exists", ), Option( - ["--quite"], + ["--quiet"], is_flag=True, help="Do not ask for features during generation", ), diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py index 7d93783..5bbdfd3 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/conftest.py @@ -344,7 +344,7 @@ async def setup_db() -> AsyncGenerator[None, None]: :yield: nothing. """ - client = AsyncIOMotorClient(settings.db_url.human_repr()) + client = AsyncIOMotorClient(settings.db_url.human_repr()) # type: ignore from {{cookiecutter.project_name}}.db.models import load_all_models # noqa: WPS433 await beanie.init_beanie( database=client[settings.db_base], diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/api/dummy/schema.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/api/dummy/schema.py index adb6d52..bc2eef8 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/api/dummy/schema.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/api/dummy/schema.py @@ -5,7 +5,11 @@ {%- endif %} {%- if cookiecutter.db_info.name == "mongodb" %} +{%- if cookiecutter.pydanticv1 == "True" %} +from pydantic import validator +{%- else %} from pydantic import field_validator +{%- endif %} from bson import ObjectId {%- endif %} @@ -25,8 +29,12 @@ class DummyModelDTO(BaseModel): name: str {%- if cookiecutter.db_info.name == "mongodb" %} + {%- if cookiecutter.pydanticv1 == "True" %} + @validator("id") + {%- else %} @field_validator("id", mode="before") @classmethod + {%- endif %} def parse_object_id(cls, document_id: ObjectId) -> str: """ Validator that converts `ObjectId` to json serializable `str`. diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/lifetime.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/lifetime.py index 06753bc..bda7725 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/lifetime.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/web/lifetime.py @@ -125,7 +125,7 @@ def _setup_db(app: FastAPI) -> None: # pragma: no cover from motor.motor_asyncio import AsyncIOMotorClient from {{cookiecutter.project_name}}.db.models import load_all_models async def _setup_db(app: FastAPI) -> None: - client = AsyncIOMotorClient(str(settings.db_url)) + client = AsyncIOMotorClient(str(settings.db_url)) # type: ignore app.state.db_client = client await beanie.init_beanie( database=client[settings.db_base],