This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/teal/request.py
Cayo Puigdefabregas 01ef359bd4 add teal as module
2023-03-21 12:08:13 +01:00

29 lines
748 B
Python

from flask import Request as _Request
from flask import current_app as app
from ereuse_devicehub.teal.resource import Schema
class Request(_Request):
def get_json(
self,
force=False,
silent=False,
cache=True,
validate=True,
schema: Schema = None,
) -> dict:
"""
As :meth:`flask.Request.get_json` but parsing
the resulting json through passed-in ``schema`` (or by default
``g.schema``).
"""
json = super().get_json(force, silent, cache)
if validate:
json = (
schema.load(json)
if schema
else app.resources[self.blueprint].schema.load(json)
)
return json