Open thomsentner opened 3 years ago
Also, the api.payload doesn't match the model definition. Date fields a rendered as String and not as Date
Same for me :(
I'm currently using a simple regex but it's very flimsy as it can't validate all the iso8601 patterns:
iso8601_regex = r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$'
model = api.model('Model', {
'timepoint': fields.String(required=True, description='Timepoint in ISO 8601 format', pattern=iso8601_regex),
# Other fields...
})
Code
Repro Steps
Execute:
Expected Behavior
I would expect the following response:
Actual Behavior
Even though the
begin_date
does not conform iso8601 format, I don't get a validation error. The input passes validation just fine.Environment
Additional Context
The bug is fixable by uncommenting the following line in my code example:
An issue about this bug has been open at Flask-RESTPlus since 2016: noirbizarre/flask-restplus#204.
I feel like this is a bug, as having a
fields.Date
functionality implies that validation will take place, but it actually doesn't. This behavior seems to be sort-of documented, but its documentation is extremely tucked away and not explicit, and this whole problem gave me quite a headache. I feel like either theFormatChecker
functionality should be turned on by default, a warning / exception should be raised if noFormatChecker
is provided butflask_restx.fields.Date
is initiated, or at leastflask_restx.fields.Date
/flask_restx.fields.DateTime
's documentation should be improved.