Skip to content

Commit 2492b49

Browse files
committed
add docstring to build_models #522
1 parent d53c565 commit 2492b49

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

datagateway_api/src/datagateway_api/build_models.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,56 @@ class ICATBaseEntity(ICATId):
4141

4242
def build_datagateway_api_model(**kwargs):
4343
"""
44-
Build the datagateway models using the SQL scheme given by the ICAT server
44+
Dynamically construct Pydantic models for all ICAT entities exposed by the
45+
connected ICAT server.
46+
47+
This function queries the ICAT server for its schema (entity names, fields,
48+
types, relationships, and nullability) and generates a set of Pydantic
49+
models representing:
50+
51+
- The base entity model for each ICAT entity (e.g. `Investigation`)
52+
- A corresponding POST model for creation (e.g. `InvestigationPost`)
53+
- A corresponding PATCH model for partial updates (e.g. `InvestigationPatch`)
54+
55+
Relationship fields (ONE or MANY) are converted into model references or
56+
lists of ICAT IDs. Attribute fields are mapped to Python/Pydantic primitive
57+
types according to the `TYPE_MAP`. Optionality and nullability are respected
58+
for all generated fields. Field descriptions from ICAT (if present) are
59+
carried forward into the model metadata.
60+
61+
All generated models are finally rebuilt (`model_rebuild`) using the full
62+
model namespace so that forward references between models resolve correctly.
63+
64+
Parameters
65+
----------
66+
**kwargs :
67+
Optional configuration parameters. Expected keys:
68+
- `client_pool`: A pool or cache of ICAT clients, passed into
69+
`get_cached_client`.
70+
71+
Returns
72+
-------
73+
dict
74+
A dictionary mapping model names (e.g. `"Investigation"`,
75+
`"InvestigationPost"`, `"InvestigationPatch"`) to their corresponding
76+
dynamically generated Pydantic model classes.
77+
78+
Raises
79+
------
80+
PythonICATError
81+
If the ICAT server reports an error while fetching entity names or
82+
entity schema information.
83+
84+
Notes
85+
-----
86+
- Models include metadata (via `Annotated[... , Field(...)]`) for descriptions.
87+
- SYSTEM_FIELDS are always excluded from the generated models.
88+
- Relationship fields use forward references and are resolved at the end of
89+
generation.
90+
- The POST and PATCH models differ by optionality and update semantics.
4591
46-
:returns dict of name and pydantic model key value pair
4792
"""
93+
4894
log.info("Building datagateway models")
4995

5096
datagateway_api_models = {}

0 commit comments

Comments
 (0)