No project description provided
Project description
Core-Validator
ErrorSchema
Use core_validator.ErrorSchema if you don't know which format you're gonna use.
Quick Start
DTO
class CommentDto(BaseModel):
comment: str
post_id: int
owner_id: int
Add error source (error context)
class Source(BaseModel):
local: str
DTO Validator
@dataclasses.dataclass()
class CommentValidator(Validator[ErrorSchema[Source]]):
dto: CommentDto
@validate
async def test1(self):
post_ids = list(range(1, 10))
if self.dto.post_id not in post_ids:
self.context.add_error(
ErrorSchema(
code=ErrorCodeEnum.not_found.value,
message="Id doen't not exists",
detail=f"Post with id={self.dto.post_id} not found",
source=Source(
local="data/post_id",
),
)
)
@validate
async def test2(self):
owner_ids = list(range(1, 10))
if self.dto.owner_id not in owner_ids:
self.context.add_error(
ErrorSchema(
code=ErrorCodeEnum.not_found.value,
message="Id doen't not exists",
detail=f"User with id={self.dto.post_id} not found",
source=Source(
local="data/owner_id",
),
)
)
Use
async def function():
validator = CommentValidator(...)
errors = await validator.errors()
# or
await validator.validate() # raise ValidationError
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
core_validator-0.0.2.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for core_validator-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfd9c13678fe3c61ecc086757fee83ad7dca73991fe09f3030c35b3d025ca866 |
|
MD5 | cf98073e07b4b6807a0ee7e20a807edb |
|
BLAKE2b-256 | 7caf2c682cb30de31f6b21730b41a61a83165ab0f6141dce6a9a2396dfba2def |