Skip to content

Commit

Permalink
Fix passing route with path parameter default value
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Apr 16, 2019
1 parent 42c7ed8 commit b87fb05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_rest_api/spec/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def register_converter(self, converter, conv_type, conv_format=None):
def rule_to_params(self, rule):
"""Get parameters from flask Rule"""
params = []
for argument in rule.arguments:
for argument in [a for a in rule.arguments if a not in rule.defaults]:
param = {
'in': 'path',
'name': argument,
Expand Down
29 changes: 29 additions & 0 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,35 @@ def func():
assert 'get' in paths['/test/route_1']
assert 'get' in paths['/test/route_2']

@pytest.mark.parametrize('openapi_version', ('2.0', '3.0.2'))
@pytest.mark.parametrize('as_method_view', (True, False))
def test_blueprint_route_path_parameter_default(
self, app, as_method_view, openapi_version):
app.config['OPENAPI_VERSION'] = openapi_version
api = Api(app)
blp = Blueprint('test', __name__, url_prefix='/test')

if as_method_view:
@blp.route('/<int:user_id>')
@blp.route('/', defaults={'user_id': 1})
class Resource(MethodView):

def get(self, user_id):
pass

else:
@blp.route('/<int:user_id>')
@blp.route('/', defaults={'user_id': 1})
def func(user_id):
pass

api.register_blueprint(blp)
paths = api.spec.to_dict()['paths']

assert 'parameters' not in paths['/test/']['get']
assert paths['/test/{user_id}']['get']['parameters'][0][
'name'] == 'user_id'

def test_blueprint_response_tuple(self, app):
api = Api(app)
blp = Blueprint('test', __name__, url_prefix='/test')
Expand Down

0 comments on commit b87fb05

Please sign in to comment.