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.1.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.1.tar.gz.
File metadata
- Download URL: core_validator-0.2.1.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 |
d177403e108070acdfc46b7aea85c2dc197844d0aa4a09261ccd24c9f9a4e890
|
|
| MD5 |
06535a5d4f34c687259573bc08cd664d
|
|
| BLAKE2b-256 |
72f0e892ebdcad9f826293debcdf9f60a073bf7a75d48113f16af1092f8e08fa
|
File details
Details for the file core_validator-0.2.1-py3-none-any.whl.
File metadata
- Download URL: core_validator-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.2 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 |
76c2a3cfa59d120291438dcc6f6023d17775d59637b9ff0efe7464ceec296955
|
|
| MD5 |
42db88a31412168e50acc09c30ff6c5e
|
|
| BLAKE2b-256 |
599cb7031179f994a30a53afd3ed9c4d6b21deeeb13b17d3f29074b3b32b088d
|