Coverage for tests/test_filter_pydantic_sub_model/app_pv1.py: 100%
22 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Optional 1abcde
3from fastapi import Depends, FastAPI 1abcde
4from pydantic import BaseModel, validator 1abcde
6app = FastAPI() 1abcde
9class ModelB(BaseModel): 1abcde
10 username: str 1abcde
13class ModelC(ModelB): 1abcde
14 password: str 1abcde
17class ModelA(BaseModel): 1abcde
18 name: str 1abcde
19 description: Optional[str] = None 1abcde
20 model_b: ModelB 1abcde
22 @validator("name") 1abcde
23 def lower_username(cls, name: str, values): 1abcde
24 if not name.endswith("A"): 1abcde
25 raise ValueError("name must end in A") 1abcde
26 return name 1abcde
29async def get_model_c() -> ModelC: 1abcde
30 return ModelC(username="test-user", password="test-password") 1abcde
33@app.get("/model/{name}", response_model=ModelA) 1abcde
34async def get_model_a(name: str, model_c=Depends(get_model_c)): 1abcde
35 return {"name": name, "description": "model-a-desc", "model_b": model_c} 1abcde