Skip to content

Feature request : Parameter validation #5

@MPr0pre

Description

@MPr0pre

I worked locally to integrate a functionnality like in apistar.

It could be use like this :

from m2core.bases.base_handler import BaseHandler, http_statuses
from m2core.m2core import M2Core
from m2core.validation import types, validators
from tornado import gen
from json.decoder import JSONDecodeError
from sqlalchemy import exc


class Product(types.Type):
    name = validators.String(max_length=100)
    rating = validators.Integer(minimum=1, maximum=5)
    in_stock = validators.Boolean(default=False)
    size = validators.String(enum=['small', 'medium', 'large'])


class Item(types.Type):
    field = validators.String(max_length=12)

class ValidatorHandler(BaseHandler):
    """Validate params"""

    @gen.coroutine
    @M2Core.tryex(*exceptions_list)
    @M2Core.validate
    def post(self, product: Product, i: Item):
        print(product)
        print(i)

Actually it work with query parameters and json body.

Do you think it would be a good idea to integrate it in your repo ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions