hug
hug copied to clipboard
body validation can not take effect when body is None
from marshmallow import Schema, fields
class TestingSchema(Schema): a = fields.Integer(required=True) b = fields.Integer(required=True) c = fields.Integer()
@api.route.post('/test') def test_validation(body: TestingSchema()): return True, '', body
when body is None
@guozhihua12 I'm having a little trouble reproducing this. Would you mind updating with the full code you're using for a repo? For instance, I'm not exactly sure how you are defining api
and it doesn't seem to be something with direct documentation.
To try to reproduce, I used a file like this
from marshmallow import Schema, fields
import hug
class TestingSchema(Schema):
a = fields.Integer(required=True)
b = fields.Integer(required=True)
c = fields.Integer()
@hug.route.post('/test')
def test_validation(body: TestingSchema()):
return True, '', body
and then used POST requests like this
➜ hug-examples curl -X POST localhost:8000/test -d "a=1&b=2&c=3"
[true, "", {"b": 2, "a": 1, "c": 3}]
➜ hug-examples curl -X POST localhost:8000/test
{"errors": {"body": {"_schema": ["Invalid input type."]}}}