diff options
author | David Robertson <davidr@element.io> | 2022-08-15 20:05:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 19:05:57 +0000 |
commit | d642ce4b3258012da6c024b0b5d1396d2a3e69dd (patch) | |
tree | daf0fc320f58f1364a2ee7e91f7eb0ddcffda58b /synapse/rest/models.py | |
parent | Add a warning to retention documentation regarding the possibility of databas... (diff) | |
download | synapse-d642ce4b3258012da6c024b0b5d1396d2a3e69dd.tar.xz |
Use Pydantic to systematically validate a first batch of endpoints in `synapse.rest.client.account`. (#13188)
Diffstat (limited to 'synapse/rest/models.py')
-rw-r--r-- | synapse/rest/models.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/synapse/rest/models.py b/synapse/rest/models.py new file mode 100644 index 0000000000..ac39cda8e5 --- /dev/null +++ b/synapse/rest/models.py @@ -0,0 +1,23 @@ +from pydantic import BaseModel, Extra + + +class RequestBodyModel(BaseModel): + """A custom version of Pydantic's BaseModel which + + - ignores unknown fields and + - does not allow fields to be overwritten after construction, + + but otherwise uses Pydantic's default behaviour. + + Ignoring unknown fields is a useful default. It means that clients can provide + unstable field not known to the server without the request being refused outright. + + Subclassing in this way is recommended by + https://pydantic-docs.helpmanual.io/usage/model_config/#change-behaviour-globally + """ + + class Config: + # By default, ignore fields that we don't recognise. + extra = Extra.ignore + # By default, don't allow fields to be reassigned after parsing. + allow_mutation = False |