Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"description": "A docstring to prevent auto generated docstring",
},
"NoContentSchema": {
"type": "object",
"properties": {},
"description": "A docstring to prevent auto generated docstring",
},
"UserSchema": {
"type": "object",
"properties": {
"first_name": {"type": "string"},
"last_name": {"type": "string"},
"display_name": {"type": "string"},
"company": {"type": "string"},
"username": {"type": "string", "pattern": "[\\w-]+"},
"email_address": {"type": "string", "format": StringFormat.EMAIL},
"id": {"type": "integer"},
},
"required": [
"company",
"display_name",
"email_address",
"first_name",
"last_name",
"username",
],
"description": "A docstring to prevent auto generated docstring",
},
"AboutResponseSchema": {
"type": "object",
"properties": {
"version": {"type": "string"},
"$ref": "#/definitions/UserSchema_exclude_first_name_last_name_email_address"
},
},
},
"required": ["item_nb", "items", "pagination"],
"description": "A docstring to prevent auto generated docstring",
},
"UserSchema_exclude_id": {
"type": "object",
"properties": {
"first_name": {"type": "string"},
"last_name": {"type": "string"},
"display_name": {"type": "string"},
"company": {"type": "string"},
"username": {"type": "string", "pattern": "[\\w-]+"},
"email_address": {"type": "string", "format": StringFormat.EMAIL},
},
"required": [
"company",
"display_name",
"email_address",
"first_name",
"last_name",
"username",
],
"description": "A docstring to prevent auto generated docstring",
},
"NoContentSchema": {
"type": "object",
"properties": {},
"description": "A docstring to prevent auto generated docstring",
},
@dataclasses.dataclass
class UserPathSchema(object):
"""A docstring to prevent auto generated docstring"""
id: int = number_field(minimum=1, cast_on_load=True)
@dataclasses.dataclass
class UserSchema(object):
"""A docstring to prevent auto generated docstring"""
first_name: str
last_name: str
display_name: str
company: str
username: str = string_field(pattern='[\w-]+')
email_address: str = string_field(format_=StringFormat.EMAIL)
id: typing.Optional[int] = None # Note: must be optional to be unused in POST user
@dataclasses.dataclass
class PaginationSchema(object):
"""A docstring to prevent auto generated docstring"""
first_id: int
last_id: int
current_id: int
@dataclasses.dataclass
class ListsUserSchema(object):
"""A docstring to prevent auto generated docstring"""
pagination: PaginationSchema
item_nb: int = number_field(minimum=0)
1 and 999
"""
id: int = number_field(minimum=1, cast_on_load=True)
@dataclasses.dataclass
class UserSchema(object):
"""Complete representation of a user"""
first_name: str
last_name: typing.Optional[str]
display_name: str
company: typing.Optional[str]
id: int
email_address: str = string_field(format_=StringFormat.EMAIL)
@dataclasses.dataclass
class UserDigestSchema(object):
"""User representation for listing"""
id: int
display_name: str = ""
@dataclasses.dataclass
class UserAvatarSchema(object):
"""Avatar (image file) of user"""
avatar: typing.Any
class AboutSchema(object):
""" Representation of the /about route """
version: str
datetime: datetime
@dataclasses.dataclass
class UserIdPathSchema(object):
"""
representation of a user id in the uri. This allow to define rules for
what is expected. For example, you may want to limit id to number between
1 and 999
"""
id: int = number_field(minimum=1, cast_on_load=True)
@dataclasses.dataclass
class UserSchema(object):
"""Complete representation of a user"""
first_name: str
last_name: typing.Optional[str]
display_name: str
company: typing.Optional[str]
id: int
email_address: str = string_field(format_=StringFormat.EMAIL)
@dataclasses.dataclass
class UserDigestSchema(object):
id: typing.Optional[int] = None # Note: must be optional to be unused in POST user
@dataclasses.dataclass
class PaginationSchema(object):
"""A docstring to prevent auto generated docstring"""
first_id: int
last_id: int
current_id: int
@dataclasses.dataclass
class ListsUserSchema(object):
"""A docstring to prevent auto generated docstring"""
pagination: PaginationSchema
item_nb: int = number_field(minimum=0)
items: typing.List[UserSchema] = nested_field(
only=['id', 'username', 'display_name', 'company'],
)
@dataclasses.dataclass
class NoContentSchema(object):
"""A docstring to prevent auto generated docstring"""
@dataclasses.dataclass
class AboutResponseSchema(object):
"""A docstring to prevent auto generated docstring"""
version: str
datetime: datetime
@dataclasses.dataclass
class UserPathSchema(object):
"""A docstring to prevent auto generated docstring"""
id: int = number_field(minimum=1, cast_on_load=True)
@dataclasses.dataclass
class UserSchema(object):
"""A docstring to prevent auto generated docstring"""
first_name: str
last_name: str
display_name: str
company: str
username: str = string_field(pattern='[\w-]+')
email_address: str = string_field(format_=StringFormat.EMAIL)
id: typing.Optional[int] = None # Note: must be optional to be unused in POST user
@dataclasses.dataclass
class PaginationSchema(object):
@dataclasses.dataclass
class UserPathSchema(object):
"""A docstring to prevent auto generated docstring"""
id: int = number_field(minimum=1, cast_on_load=True)
@dataclasses.dataclass
class UserSchema(object):
"""A docstring to prevent auto generated docstring"""
first_name: str
last_name: str
display_name: str
company: str
username: str = string_field(pattern='[\w-]+')
email_address: str = string_field(format_=StringFormat.EMAIL)
id: typing.Optional[int] = None # Note: must be optional to be unused in POST user
@dataclasses.dataclass
class PaginationSchema(object):
"""A docstring to prevent auto generated docstring"""
first_id: int
last_id: int
current_id: int
@dataclasses.dataclass
class ListsUserSchema(object):
"""A docstring to prevent auto generated docstring"""
pagination: PaginationSchema
def load(self, data: typing.Any) -> typing.Any:
"""
Use schema to validate given data and return dataclass instance.
If validation fail, raise InputValidationException
:param data: data to validate and process
:return: schema dataclass instance
"""
# Prevent serpyco error when Rrequest context give us a MultiDictProxy
if isinstance(data, (MultiDictProxy, MultiDict)):
data = dict(data)
try:
return self.serializer.load(data)
except ValidationError as exc:
raise ValidationException("Error when loading: {}".format(exc.args[0])) from exc
except Exception as exc:
raise ValidationException(
'Unknown error when serpyco load: "{}": "{}"'.format(type(exc).__name__, str(exc))
) from exc
@dataclasses.dataclass
class PaginationSchema(object):
"""A docstring to prevent auto generated docstring"""
first_id: int
last_id: int
current_id: int
@dataclasses.dataclass
class ListsUserSchema(object):
"""A docstring to prevent auto generated docstring"""
pagination: PaginationSchema
item_nb: int = number_field(minimum=0)
items: typing.List[UserSchema] = nested_field(
only=['id', 'username', 'display_name', 'company'],
)