Skip to content
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

RequestParser support with custom validation function #23

Open
slitayem opened this issue Nov 23, 2017 · 2 comments
Open

RequestParser support with custom validation function #23

slitayem opened this issue Nov 23, 2017 · 2 comments

Comments

@slitayem
Copy link

slitayem commented Nov 23, 2017

I have a custom validation function for a RequestParser argument. And I use the parser object to pass its arguments to spec. But unfortunately, it seems that the library does not support custom types input types e.g

    def one_character_string(value):
        """One character string parameter validator"""
        if isinstance(value, str) and len(value) == 1:
            return value
        else:
            raise ValueError(
                "The parameter '{}' should be a single character length".format(
                   value))

.....
    from flask_restful import reqparse
    parser = reqparse.RequestParser()
    parser.add_argument(
        'customInput', type=one_character_string,
        help='String value expected', required=False)

I am getting the following exception

File "/usr/local/lib/python3.5/dist-packages/flask_restful_swagger_2/init.py", line 271, in get_swagger_arg_type
elif issubclass(type
, basestring):
TypeError: issubclass() arg 1 must be a class

@vsu
Copy link
Collaborator

vsu commented Nov 24, 2017

You could try extending _get_swagger_arg_type in init.py to handle a custom argument and map it to swagger type 'object'.

https://swagger.io/docs/specification/data-models/data-types/

If you open a pull request I'd be happy to merge it.

@mycaule
Copy link

mycaule commented Jul 30, 2018

Do I have to use https://github.com/Yelp/bravado-core to validate the body request data for a POST route ?

I would like to reuse a model class MyRequestModel(Schema) I have written, I cannot find the code.

The class UserModel(Schema) in example is just for the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants