pallets-eco / flask-jwt

JWT (JSON Web Tokens) for Flask applications
MIT License
564 stars 178 forks source link

Parameters in yaml, crash functions with @jwt_required() decorator #81

Open srlopez opened 8 years ago

srlopez commented 8 years ago

I write this issue https://github.com/KarimJedda/connexion_jwt_example/issues/2 in the example using flask-jwt with Swagger api description.

I see that writing parameters in swagger api.yaml file, and decorating the controller with @jwt_required() the app crashed.

This is part of the yaml api description file,

paths:
  '/stuff':
    get:
      tags: [stuff]
      operationId: zblaaaa.get_secret
      summary: Give me sugar sugar
      parameters:
        - name: animal_type
          in: query
          type: string
          pattern: "^[a-zA-Z0-9]*$"
        - name: limit
          in: query
          type: integer
          minimum: 0
          default: 100
      responses:
        200:
          description: Something secret

and this is the controller function decorated with @jwt_required()

from run import jwt_required, current_identity
pets = {}
@jwt_required()
def get_secret(limit, animal_type=None):
    return [pet for pet in pets.values() if not animal_type or pet['animal_type'] == animal_type][:limit]

the app crash with the following error

*flask_jwt/init.py", line 177 in decorator return fn(args, kwargs) TypeError: get_secret() takes at least 1 argument (0 given)**

ERROR:run:Exception on /api/stuff [GET]
Traceback (most recent call last):
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
 ....
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/validation.py", line 192, in wrapper
    response = function(*args, **kwargs)
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/produces.py", line 117, in wrapper
    data, status_code, headers = self.get_full_response(function(*args, **kwargs))
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/parameter.py", line 133, in wrapper
    return function(*args, **kwargs)
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/flask_jwt/__init__.py", line 177, in decorator
    return fn(*args, **kwargs)
TypeError: get_secret() takes at least 1 argument (0 given)
127.0.0.1 - - [2016-03-21 20:20:26] "GET /api/stuff?animal_type=dino&limit=100 HTTP/1.1" 500 377 0.003594

But without the decorator the app runs fine.

Thanks in advance