Consider the following:
from flask import Flask
from flask_restplus import Api, Resource, fields
app = Flask(__name__)
api = Api(app)
ns = api.namespace('ns')
payload = api.model('Payload', {
'a_str': fields.String(required=True),
'a_date': fields.Date(required=True)
})
@ns.route('/')
class AResource(Resource):
@ns.expect(payload)
def post(self):
pass
If I POST {"a_str": 0, "a_date": "2000-01-01"}
I get 400 as expected,
because a_str
is not a string.
However, when I POST {"a_str": "str", "a_date": "asd"}
I don't get 400.
Here I would like to also get 400, because "asd" is not a common date format.
I looked into the Date
class doc and
I see that there is a format
and a parse
method which should check whether the string is in a common date format.
However, they do not seem to be called here.
Is there another way how to do this? Currently I am validating the date format by hand, but it seems that fask restplus should be able to do it for me.