onconova.core.serialization.factory
__all__
module-attribute
¶
create_filters_schema
module-attribute
¶
create_schema
module-attribute
¶
factory
module-attribute
¶
SchemaFactory
¶
Bases: SchemaFactory
A factory class for dynamically creating Pydantic schema classes based on ORM models.
This class extends NinjaSchemaFactory
and provides methods to generate Pydantic models
(schemas) for serialization and deserialization of ORM models, as well as filter schemas
for querying.
Attributes:
Name | Type | Description |
---|---|---|
IGNORE_FIELDS |
List[str]
|
List of model field names to ignore when generating schemas. |
IGNORE_FIELDS
class-attribute
instance-attribute
¶
create_filters_schema(schema, *, name='', depth=0, fields=None, exclude=None, base_class=FilterBaseSchema)
¶
Dynamically creates a Pydantic schema class for filtering based on the fields of the given schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Type[Any]
|
The base Pydantic schema class to generate filters for. |
required |
|
str
|
The name of the generated filter schema. Defaults to the name of the input schema. |
''
|
|
int
|
The depth for nested schema generation. Defaults to 0. |
0
|
|
Optional[List[str]]
|
List of field names to include in the filter schema. Mutually exclusive with |
None
|
|
Optional[List[str]]
|
List of field names to exclude from the filter schema. Mutually exclusive with |
None
|
|
Type[Schema]
|
The base class to use for the generated filter schema. Defaults to FilterBaseSchema. |
FilterBaseSchema
|
Raises:
Type | Description |
---|---|
ConfigError
|
If both |
Returns:
Type | Description |
---|---|
Type[Schema]
|
Type[Schema]: The dynamically generated Pydantic schema class for filtering. |
Source code in onconova/core/serialization/factory.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
create_schema(model, *, name='', depth=0, fields=None, exclude=None, expand=None, reverse_fields=None, optional_fields=None, custom_fields=None, bases=tuple())
¶
Dynamically creates a Pydantic schema class for a given ORM model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Type[BaseModel]
|
The ORM model class to generate the schema for. |
required |
|
str
|
The name of the generated schema class. Defaults to the model's class name. |
''
|
|
int
|
The depth for nested/related fields expansion. Defaults to 0. |
0
|
|
List[str]
|
List of field names to include in the schema. Mutually exclusive with |
None
|
|
List[str]
|
List of field names to exclude from the schema. Mutually exclusive with |
None
|
|
dict
|
Dictionary specifying related fields to expand in the schema. |
None
|
|
List[str]
|
List of reverse relation field names to include. |
None
|
|
Optional[List[str]]
|
List of field names to mark as optional, or "all" for all fields. |
None
|
|
Optional[List[Tuple[str, Any, Any]]]
|
List of custom fields to add, each as (name, type, FieldInfo). |
None
|
|
Tuple[Any, ...]
|
Additional base classes for the generated schema. |
tuple()
|
Returns:
Type | Description |
---|---|
Type[Schema]
|
Type[Schema]: The dynamically generated Pydantic schema class. |
Raises:
Type | Description |
---|---|
ConfigError
|
If both |
Notes
- The generated schema is cached and reused if the same parameters are provided.
- Custom resolvers for fields are attached as static methods.
- ORM metadata is stored on the schema for later use.
Source code in onconova/core/serialization/factory.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|