New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I write a custom validator? #716
Comments
I tried to apply this with no luck: |
I don't know how to do a custom validator, but you can use "pattern" to validate the string: api.model('a_name', { I hope it helps |
@AbdoDabbas , reading what you implemented, and your described problem, did you implement the last step? In the example you posted, they created another function,
This is based on the code in the flask_restplus I'm not having good luck on peeking where |
@JBarrioGarcia I tried your way, the problem now is the error message is strange, it says:
If 'string' can be resolved using the "title", I didn't find how to replace the pattern in the message to be something I want. |
+1. the |
I was able somehow to work around this by doing two things:
Here: Maybe |
@AbdoDabbas It seems you're doing validation after flask-restplus already had a crack at it and passed it. You can definitely do validation inside the endpoints, but that pollutes your routes and creates a fractured logic - some validation happens before, some after. Besides, the |
Actually I need to do it before, but using api model validation way will not give me what I need and it's limited as you saw in the previous comments. I think it may work better using the |
@AbdoDabbas I created a PR addressing this issue in a more standardized way (imho). If you don't want to wait, you can just update your own copy of the |
@andreixk |
Is there a way to write a validator for a custom field type that I can use in the API model (in except decorator).
I mean like this:
I tried to inherit from
fields.String
and did it like:The text was updated successfully, but these errors were encountered: