Skip to main content

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

Metadata

Release files for core-validator 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for core-validator 0.2.2
File Size Uploaded Provenance Actions
core_validator-0.2.2.tar.gz 7.3 kB Without provenance Details for core_validator-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for core-validator 0.2.2
File Interpreter ABI Platform Actions
core_validator-0.2.2-py3-none-any.whl Python 3 none any Details for core_validator-0.2.2-py3-none-any.whl

Total release size: 17.6 kB

Release files / core_validator-0.2.2.tar.gz

Download URL core_validator-0.2.2.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7c41e978d5f6d3e000850489388239506c97f85a9aa149eb2ea635d6bd1d4186
BLAKE2b-256 checksum
How to use checksums
edb1db5a4107604871c0ebb0b87220da037cc2ccfd3ba29bc455f48ff2c7b561
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.27.0 CPython/3.11.15 Linux/5.15.154+

Release files / core_validator-0.2.2-py3-none-any.whl

Download URL core_validator-0.2.2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27e337c90a807116db35d2c900eb98851071c35ad31287f5dc87d11216763026
BLAKE2b-256 checksum
How to use checksums
94135df5a59f067ffab66cce3f464e244316afd25da151aaf227eb4651faed65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.27.0 CPython/3.11.15 Linux/5.15.154+

Security for core-validator 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page