code: def validate_fields(func):
      
      @functools.wraps(func)
      def decorated(instance, *args, **kwargs):
          """The decorator function."""
          data = request.get_json(force=True, silent=True)
          if not data:
              raise BadRequestException('No data received from request')
          for key in data:
              if key not in (
                      instance.__model__.required() +
                      instance.__model__.optional()):
                  raise BadRequestException('Unknown field [{}]'.format(key))
          missing = set(instance.__model__.required()) - set(data)
          if missing:
              message = 'The following required fields are missing: ' + ', '.join(missing)
              raise BadRequestException(message)
          return func(instance, *args, **kwargs)
      return decorated
docs: A decorator to automatically detect missing required fields from
      json data.