Schemas API#
- class fastapi_restly.schemas.BaseSchema#
Bases:
BaseModelThin Pydantic base for ORM-facing Restly schemas.
Equivalent to:
class BaseSchema(pydantic.BaseModel): model_config = pydantic.ConfigDict(from_attributes=True)
from_attributes=Truelets Pydantic/FastAPI validate objects by attribute when the schema is used directly. Generated Restly routes still serialize throughto_response_schema()so Restly-specific behavior such asWriteOnlyfiltering and relationship-id normalization is applied.- model_config: ClassVar[ConfigDict] = {'from_attributes': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fastapi_restly.schemas.IDRef(value: ~typing.Any = <object object>, *, id: ~typing.Annotated[~typing.Any, fr.ReadOnly])#
Bases:
IDSchema,Generic[SQLAlchemyModel]Reference to a row of T by id.
Wire format is the raw id value (e.g.
5); accepts both scalars and{"id": N}dicts on input. The framework validates the referenced row exists and resolves it to the FK column on the way in.Use this for typical REST APIs where you want
task_id: 5on the wire. For JSON-API or React-Admin-style nested wire format{"id": N}, useIDSchema[T]instead.products: list[IDRef[Product]] # serializes as [“uuid1”, “uuid2”]
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fastapi_restly.schemas.IDSchema(*, id: Annotated[Any, fr.ReadOnly])#
Bases:
BaseSchema,Generic[SQLAlchemyModel]Generic schema useful for serializing only the id of objects. Can be used as IDSchema[MyModel].
- get_sql_model_annotation() type[SQLAlchemyModel] | None#
Return the annotation on IDSchema when used as:
foo: IDSchema[Foo]
This property will return “Foo”.
- id: ReadOnly, FieldInfo(annotation=NoneType, required=True, json_schema_extra={'readOnly': True})]#
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fastapi_restly.schemas.TimestampsSchemaMixin(*, created_at: Annotated[datetime, fr.ReadOnly], updated_at: Annotated[datetime, fr.ReadOnly])#
Bases:
BaseModel- created_at: ReadOnly, FieldInfo(annotation=NoneType, required=True, json_schema_extra={'readOnly': True})]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- updated_at: ReadOnly, FieldInfo(annotation=NoneType, required=True, json_schema_extra={'readOnly': True})]#
- fastapi_restly.schemas.create_schema_from_model(model_cls: type[DeclarativeBase], *, schema_name: str | None = None, include_relationships: bool = True, include_readonly_fields: bool = True) type[BaseSchema]#
Auto-generate a Pydantic schema from a SQLAlchemy model.
- Args:
model_cls: The SQLAlchemy model class schema_name: Optional name for the generated schema class include_relationships: Whether to include relationship fields include_readonly_fields: Whether to include read-only fields like id, created_at, etc.
- Returns:
A Pydantic schema class