business-validator-1.0.2
توضیحات
-
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | business-validator-1.0.2 |
| نام | business-validator |
| نسخه کتابخانه | 1.0.2 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | maksyutov vlad <maksyutov.vlad@gmail.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/business-validator/ |
| مجوز | MIT |
# Business-Validator
## ErrorSchema
Use business_validator.ErrorSchema if you don't know which format you're gonna use.
## Quick Start
### DTO
```python
class CommentDto(BaseModel):
comment: str
post_id: int
owner_id: int
```
### Add error source (error context)
```python
class Source(BaseModel):
local: str
```
### DTO Validator
```python
@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
```python
async def function():
validator = CommentValidator(...)
errors = await validator.errors()
# or
await validator.validate() # raise ValidationError
```
نیازمندی
| مقدار | نام |
|---|---|
| - | pydantic>=1.10.4 |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.11 | Python |
نحوه نصب
نصب پکیج whl business-validator-1.0.2:
pip install business-validator-1.0.2.whl
نصب پکیج tar.gz business-validator-1.0.2:
pip install business-validator-1.0.2.tar.gz