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[CommentDto, ErrorSchema[Source]]):
@validate
async def test1(self):
post_ids = list(range(1, 10))
if self.data.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.data.post_id} not found",
source=Source(
local="data/post_id",
),
)
)
@validate
@pre_state(lambda self: self.data.owner_id > 0, negative_id_error)
async def test2(self):
owner_ids = list(range(1, 10))
if self.data.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.data.post_id} not found",
source=Source(
local="data/owner_id",
),
)
)
Use
async def function():
validator = CommentValidator()
errors = await validator.errors(comment)
# or
await validator.validate() # raise ValidationError
Project details
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.2.0.tar.gz
(7.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file core_validator-0.2.0.tar.gz.
File metadata
- Download URL: core_validator-0.2.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.26.1 CPython/3.11.14 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b77370c4c597f9112b7366ab1dc1693377150cc8048fcfe38e0e64b7ceada0c2
|
|
| MD5 |
9017af7fef77b5a1942fe634e0f19f87
|
|
| BLAKE2b-256 |
b178b240c8e32a0eb5a278b2a3680637384d79c1c282c428060479f5d137bf69
|
File details
Details for the file core_validator-0.2.0-py3-none-any.whl.
File metadata
- Download URL: core_validator-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.26.1 CPython/3.11.14 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca4468fff8a8b1ff577bbe70f3ad046b82179130cd5614527226753bf82a7775
|
|
| MD5 |
251994ff1d9a666239f6b08dd6643b70
|
|
| BLAKE2b-256 |
a4d7d3949b61a38dc1fb709e14a1209267d63a157d085a2b2bff2fc907feee69
|