In order to support further development, ease of maintenance, and OpenAPI 3.*, we are moving to the FastAPI framework. FastAPI is based on Starlette (high performance ASGI framework) and Pydantic (validation through type hints), all in active development. The HTTP API will remain backwards compatible.
Description
Details
- Difficulty level
- Unknown (require assessment)
- Version
- -
- Why the issue appeared?
- Will be filled on close
- Is it a breaking change?
- Perfectly compatible
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Resolved | FEATURE REQUEST | jestabro | T2395 HTTP API move to flask/flask-restx as microframework | ||
Resolved | FEATURE REQUEST | jestabro | T2397 HTTP API: export OpenAPI definition | ||
Resolved | jestabro | T3412 HTTP API: move to FastAPI as web framework |
Event Timeline
There are two versions that have been developed, reasonably feature complete, pending testing. One presents an OpenAPI schema of application/x-www-form-urlencoded (multipart forms); the other, application/json. The latter uses middleware (strictly speaking, a custom request and route class, instead of the Starlette middleware capability, although that may change) to intercept multipart requests, so as to remain backwards compatible.
https://github.com/jestabro/vyos-1x/tree/fastapi-multipart
https://github.com/jestabro/vyos-1x/tree/fastapi-json
Pending completion/confirmation of the compatibility layer, the latter version will be considered.
Draft PR linked below; it is a draft pending the addition of a supporting package (vyos-http-api-tools). All data validation for application/json requests is done implicitly using Pydantic models/validators; for multipart forms requests, all explicit validation has been moved out of the endpoint function bodies and into the middleware --- this is a pedantic block of code, but allows consolidation and review of all manual checks. An OpenAPI 3.0.2 schema is automatically generated and presented at server-name/docs (Swagger) and server-name/redoc (ReDoc version; slightly more pleasing to the eye).