Search Options

Results per page
Sort
Preferred Languages
Advance

Results 201 - 210 of 346 for BaseModel (0.06 sec)

  1. tests/test_request_params/test_body/test_required_str.py

    from typing import Annotated, Any, Union
    
    import pytest
    from dirty_equals import IsOneOf
    from fastapi import Body, FastAPI
    from fastapi.testclient import TestClient
    from pydantic import BaseModel, Field
    
    from .utils import get_body_model_name
    
    app = FastAPI()
    
    # =====================================================================================
    # Without aliases
    
    
    @app.post("/required-str", operation_id="required_str")
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 11K bytes
    - Viewed (0)
  2. docs_src/pydantic_v1_in_v2/tutorial003_an_py310.py

    from fastapi import FastAPI
    from pydantic import BaseModel as BaseModelV2
    from pydantic.v1 import BaseModel
    
    
    class Item(BaseModel):
        name: str
        description: str | None = None
        size: float
    
    
    class ItemV2(BaseModelV2):
        name: str
        description: str | None = None
        size: float
    
    
    app = FastAPI()
    
    
    @app.post("/items/", response_model=ItemV2)
    async def create_item(item: Item):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Oct 11 16:45:54 UTC 2025
    - 407 bytes
    - Viewed (0)
  3. tests/test_invalid_path_param.py

    import pytest
    from fastapi import FastAPI
    from pydantic import BaseModel
    
    
    def test_invalid_sequence():
        with pytest.raises(AssertionError):
            app = FastAPI()
    
            class Item(BaseModel):
                title: str
    
            @app.get("/items/{id}")
            def read_items(id: list[Item]):
                pass  # pragma: no cover
    
    
    def test_invalid_tuple():
        with pytest.raises(AssertionError):
            app = FastAPI()
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 1.6K bytes
    - Viewed (0)
  4. tests/test_response_model_data_filter.py

    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class UserBase(BaseModel):
        email: str
    
    
    class UserCreate(UserBase):
        password: str
    
    
    class UserDB(UserBase):
        hashed_password: str
    
    
    class PetDB(BaseModel):
        name: str
        owner: UserDB
    
    
    class PetOut(BaseModel):
        name: str
        owner: UserBase
    
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 1.7K bytes
    - Viewed (0)
  5. docs_src/body_nested_models/tutorial004_py310.py

    from fastapi import FastAPI
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class Image(BaseModel):
        url: str
        name: str
    
    
    class Item(BaseModel):
        name: str
        description: str | None = None
        price: float
        tax: float | None = None
        tags: set[str] = set()
        image: Image | None = None
    
    
    @app.put("/items/{item_id}")
    async def update_item(item_id: int, item: Item):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed May 11 17:29:02 UTC 2022
    - 455 bytes
    - Viewed (0)
  6. docs_src/pydantic_v1_in_v2/tutorial003_an_py39.py

    from typing import Union
    
    from fastapi import FastAPI
    from pydantic import BaseModel as BaseModelV2
    from pydantic.v1 import BaseModel
    
    
    class Item(BaseModel):
        name: str
        description: Union[str, None] = None
        size: float
    
    
    class ItemV2(BaseModelV2):
        name: str
        description: Union[str, None] = None
        size: float
    
    
    app = FastAPI()
    
    
    @app.post("/items/", response_model=ItemV2)
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 445 bytes
    - Viewed (0)
  7. docs_src/body_multiple_params/tutorial002_py39.py

    from typing import Union
    
    from fastapi import FastAPI
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class Item(BaseModel):
        name: str
        description: Union[str, None] = None
        price: float
        tax: Union[float, None] = None
    
    
    class User(BaseModel):
        username: str
        full_name: Union[str, None] = None
    
    
    @app.put("/items/{item_id}")
    async def update_item(item_id: int, item: Item, user: User):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 490 bytes
    - Viewed (0)
  8. tests/test_get_request_body.py

    from fastapi import FastAPI
    from fastapi.testclient import TestClient
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class Product(BaseModel):
        name: str
        description: str = None  # type: ignore
        price: float
    
    
    @app.get("/product")
    async def create_item(product: Product):
        return product
    
    
    client = TestClient(app)
    
    
    def test_get_with_body():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 3.7K bytes
    - Viewed (0)
  9. tests/test_additional_properties_bool.py

    from typing import Union
    
    from fastapi import FastAPI
    from fastapi.testclient import TestClient
    from pydantic import BaseModel, ConfigDict
    
    
    class FooBaseModel(BaseModel):
        model_config = ConfigDict(extra="forbid")
    
    
    class Foo(FooBaseModel):
        pass
    
    
    app = FastAPI()
    
    
    @app.post("/")
    async def post(
        foo: Union[Foo, None] = None,
    ):
        return foo
    
    
    client = TestClient(app)
    
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 3.7K bytes
    - Viewed (0)
  10. docs_src/body_updates/tutorial002_py39.py

    from typing import Union
    
    from fastapi import FastAPI
    from fastapi.encoders import jsonable_encoder
    from pydantic import BaseModel
    
    app = FastAPI()
    
    
    class Item(BaseModel):
        name: Union[str, None] = None
        description: Union[str, None] = None
        price: Union[float, None] = None
        tax: float = 10.5
        tags: list[str] = []
    
    
    items = {
        "foo": {"name": "Foo", "price": 50.2},
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 20 15:55:38 UTC 2025
    - 1K bytes
    - Viewed (0)
Back to top