Skip to content

Schemas

The CRUDRouter is able to generate and document your routes based on the schema, a pydantic model, that is passed to it.

In general, the all provided CRUDRouter's have the option to pass both a schema and a create schema to it. If no create schema is provided, the CRUDRouter will automatically automatically generate one.

CRUDRouter(schema=MyPydanticModel, create_schema=MyPydanticCreateModel)

Create Schemas

Create schemas are models which typically don't include fields that are generated by a database or other backends. An example of this is an id field in a model.

from pydantic import BaseModel

class Potato(BaseModel):
    id: int
    color: str
    mass: float

class CreatePotato(BaseModel):
    color: str
    mass: float

Automatic Create Schema Generation

Leaving the create schema argument blank when creating your CRUDRouter will result in the crud router automatically generating and documenting a create schema in your routes. It does this my automatically removing the field which matches the primary key in the database.