Skip to main content

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.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

core_validator-0.2.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file core_validator-0.2.2.tar.gz.

File metadata

  • Download URL: core_validator-0.2.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.27.0 CPython/3.11.15 Linux/5.15.154+

File hashes

Hashes for core_validator-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7c41e978d5f6d3e000850489388239506c97f85a9aa149eb2ea635d6bd1d4186
MD5 20d179cb46ef52d6bb3a5139982a1846
BLAKE2b-256 edb1db5a4107604871c0ebb0b87220da037cc2ccfd3ba29bc455f48ff2c7b561

See more details on using hashes here.

File details

Details for the file core_validator-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: core_validator-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.27.0 CPython/3.11.15 Linux/5.15.154+

File hashes

Hashes for core_validator-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27e337c90a807116db35d2c900eb98851071c35ad31287f5dc87d11216763026
MD5 ea7b61cc8fea5d6e8f68c9b83bb0c52f
BLAKE2b-256 94135df5a59f067ffab66cce3f464e244316afd25da151aaf227eb4651faed65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page