Project

General

Profile

Feature #40962

Updated by Ernesto Puerta over 4 years ago

While front-end language Typescript provides build-time type-checks, there's no current action taken to ensure run-time type-safety from-to back-end API. 

 Apart from extra safety measures like type guards (@typeof@|@instanceof@|etc), it'd desirable to have a type definition framework to share between Python (now wer're enforcing type hints) and Typescript. 

 It seems there are libraries for handling "jsonschema":https://json-schema.org both in: 
 * "Typescript":https://github.com/YousefED/typescript-json-schema 
 * Python: "jsonschema":https://pypi.org/project/jsonschema/ (JSON schema to Python type hints), "pydantic":https://pydantic-docs.helpmanual.io/ (generating JSON schema from Python type hints). "Python":https://pypi.org/project/jsonschema/. 
 * Additionally there are tools to extract json-schemas from OpenAPI/Swagger definitions, which would allow for an API driven scenario. 

 The workflow would be more or less like this (as Python is our source of truth in terms of API): this: 
 # JSON Schema -> {Python code, OpenAPI Schema, Typescript} (It seems there's no easy to way to export Python type hints to JSON schema, but only the other way). 
 # Or Python code -> JSON Schema -> {OpenAPI Schema, Typescript} (It seems there's no easy to way to export Python type hints to JSON schema, but only the other way). 

 If we find the way to enforce type/schemas between C++ API and Python (as the initiative proposed by SebastianW), we might ensure end-to-end type safety in Ceph. 

Back