Actions
Feature #46423
openFeature #50320: mgr/dashboard: Lean Dashboard
Feature #40962: mgr/dashboard: REST API: runtime front-end/back-end (end-to-end) schema validation
mgr/dashboard: Python runtime typechecking framework
% Done:
0%
Source:
Tags:
Backport:
Reviewed:
Affected Versions:
Pull request ID:
Description
Python (as well as Typescript) lacks runtime typechecking, this may lead to a lot runtime issues. Part of this is alleviated by QA/Back-end API tests, but they cannot cover all the possible real-life situations.
Additionally, there's a lot of (potential) duplicate type definitions at both Front-end (Typescript) and Back-end (Python).
One of the most mature solutions for tackling these concerns ispydantic
. For our purposes, it fulfills the following requirements:
- Runtime type-checking: integrated with mypy.
>>> class RBD(pydantic.BaseModel): ... id: int ... name: str ... >>> RBD(id=1, name='test_rbd') RBD(id=1, name='test_rbd') >>> RBD(id='1', name='test_rbd') RBD(id=1, name='test_rbd') >>> RBD(id='asd', name='test_rbd') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pydantic/main.py", line 338, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 1 validation error for RBD id value is not a valid integer (type=type_error.integer)
- Export Python types/schemas to JSON Schema/OpenAPI: this could be later imported to Angular/Typescript via 3rd party tools
# OpenAPI compliant >>> RBD.schema_json() '{"title": "RBD", "type": "object", "properties": {"id": {"title": "Id", "type": "integer"}, "name": {"title": "Name", "type": "string"}}, "required": ["id", "name"]}'
As a con, current package support is limited to latest upstream distros *
Updated by Ernesto Puerta almost 4 years ago
- Related to Feature #46501: mgr/dashboard: evaluate FastAPI added
Updated by Ken Dreyer over 2 years ago
I've built python-pydantic for el8 and el9 at https://copr.fedorainfracloud.org/coprs/ktdreyer/python-pydantic/
Actions