You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.5 KiB

  1. # Copyright 2022 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import TYPE_CHECKING
  15. from synapse._pydantic_compat import HAS_PYDANTIC_V2
  16. if TYPE_CHECKING or HAS_PYDANTIC_V2:
  17. from pydantic.v1 import BaseModel, Extra
  18. else:
  19. from pydantic import BaseModel, Extra
  20. class RequestBodyModel(BaseModel):
  21. """A custom version of Pydantic's BaseModel which
  22. - ignores unknown fields and
  23. - does not allow fields to be overwritten after construction,
  24. but otherwise uses Pydantic's default behaviour.
  25. Ignoring unknown fields is a useful default. It means that clients can provide
  26. unstable field not known to the server without the request being refused outright.
  27. Subclassing in this way is recommended by
  28. https://pydantic-docs.helpmanual.io/usage/model_config/#change-behaviour-globally
  29. """
  30. class Config:
  31. # By default, ignore fields that we don't recognise.
  32. extra = Extra.ignore
  33. # By default, don't allow fields to be reassigned after parsing.
  34. allow_mutation = False