Project

General

Profile

Feature #46423

Feature #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

Added by Ernesto Puerta over 2 years ago. Updated about 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
General - Back-end
Target version:
% 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 is pydantic. 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 *


Related issues

Related to Dashboard - Feature #46501: mgr/dashboard: evaluate FastAPI New

History

#1 Updated by Ernesto Puerta over 2 years ago

#2 Updated by Ken Dreyer about 1 year ago

I've built python-pydantic for el8 and el9 at https://copr.fedorainfracloud.org/coprs/ktdreyer/python-pydantic/

Also available in: Atom PDF