No project description provided
Project description
Business-Validator
ErrorSchema
Use business_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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 business_validator-2.0.1.tar.gz.
File metadata
- Download URL: business_validator-2.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
272bde76d439023226d8af299354eab3a4278f1beecc7582e84e4b109a043c7f
|
|
| MD5 |
ad83c2126b483e1c92c8b3bc03816007
|
|
| BLAKE2b-256 |
73d5b324d56cb56c6e0e406261fdfb3876b5711fcdafaf9dc03ad80526ab2ddd
|
File details
Details for the file business_validator-2.0.1-py3-none-any.whl.
File metadata
- Download URL: business_validator-2.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bdbf06325ee8ee21f3e0e91de24681c4544d420a451c5f1d3d62b2f63594063
|
|
| MD5 |
2214ca3e4dc35a1015a4268a87325d1a
|
|
| BLAKE2b-256 |
80503dedd5f270a530d956f51db628dd73cd2710bcf7c5907808523153906d7e
|