encode / apistar

The Web API toolkit. 🛠
https://docs.apistar.com
BSD 3-Clause "New" or "Revised" License
5.57k stars 411 forks source link

Auto validation date/datetime params #566

Closed zueve closed 5 years ago

zueve commented 6 years ago

It will grate to auto validate base types date / datetime Now the API can not validate only: str, int, float and can not catch date / datetime.

Example: ` from datetime

def myhandler (name: str, created: date):     pass   ` Now i have an exception: No component able to handle parameter "date" on function "myhandlee"

If you agree i would like to make patch

freakabcd commented 6 years ago

validators.String already supports auto validation of date, time and datetime strings using format=date, format=time and format=datetime respectively. Please comment on whether these are sufficient.

zueve commented 6 years ago

it's support if i use complex validator like

class Product(typing.Type):
    date = validators.Date()

def myhandler (product: Product):
    pass

But I wont validate data type out of complex validator(Product), like in example:

def myhandler (date: datetime.date):
    pass
freakabcd commented 6 years ago

ah, I see what you mean. You want a toplevel data element that is not an object. See #507 where the user wanted a toplevel array element instead of an object. The JSON spec has changed slightly from the past in terms of the definition of a JSON document. Previously only {} and [] were allowed root elements.

I guess we will wait for @tomchristie to chime in on what he wants to support.

tomchristie commented 5 years ago

Now redundant, given we're using https://github.com/encode/typesystem for all the validation here.