mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-06 04:19:26 +00:00
Update NumberConverter regex to match new Werkzeug behavior (v2) (#1643)
Fixes #1635 See https://github.com/pallets/werkzeug/issues/2518. Apparently, this is only an issue when you have more than 1 path parameter, so added a test for that.
This commit is contained in:
2
.github/workflows/pipeline.yml
vendored
2
.github/workflows/pipeline.yml
vendored
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||
python-version: [3.7, 3.8, 3.9]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
|
||||
@@ -172,7 +172,7 @@ class FlaskJSONEncoder(json.JSONEncoder):
|
||||
|
||||
class NumberConverter(werkzeug.routing.BaseConverter):
|
||||
""" Flask converter for OpenAPI number type """
|
||||
regex = r"[+-]?[0-9]*(\.[0-9]*)?"
|
||||
regex = r"[+-]?[0-9]*(?:\.[0-9]*)?"
|
||||
|
||||
def to_python(self, value):
|
||||
return float(value)
|
||||
|
||||
@@ -175,6 +175,16 @@ def test_path_parameter_somefloat(simple_app, arg, result):
|
||||
assert resp.data.decode('utf-8', 'replace') == f'"{result}"\n'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('arg, arg2, result', [
|
||||
['-0.000000001', '0.3', 'float -1e-09, 0.3'],
|
||||
])
|
||||
def test_path_parameter_doublefloat(simple_app, arg, arg2, result):
|
||||
assert isinstance(arg, str) # sanity check
|
||||
app_client = simple_app.app.test_client()
|
||||
resp = app_client.get(f'/v1.0/test-float-path/{arg}/{arg2}') # type: flask.Response
|
||||
assert resp.data.decode('utf-8', 'replace') == f'"{result}"\n'
|
||||
|
||||
|
||||
def test_path_parameter_somefloat__bad(simple_app):
|
||||
# non-float values will not match Flask route
|
||||
app_client = simple_app.app.test_client()
|
||||
|
||||
@@ -274,6 +274,10 @@ def test_get_somefloat(somefloat):
|
||||
return f'{type(somefloat).__name__} {somefloat:g}'
|
||||
|
||||
|
||||
def test_get_doublefloat(somefloat, someotherfloat):
|
||||
return f'{type(somefloat).__name__} {somefloat:g}, {someotherfloat}'
|
||||
|
||||
|
||||
def test_default_param(name):
|
||||
return {"app_name": name}
|
||||
|
||||
|
||||
18
tests/fixtures/simple/openapi.yaml
vendored
18
tests/fixtures/simple/openapi.yaml
vendored
@@ -528,6 +528,24 @@ paths:
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
'/test-float-path/{somefloat}/{someotherfloat}':
|
||||
get:
|
||||
summary: Test type casting of path parameter
|
||||
operationId: fakeapi.hello.test_get_doublefloat
|
||||
parameters:
|
||||
- name: somefloat
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: number
|
||||
- name: someotherfloat
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: number
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
/test-default-query-parameter:
|
||||
get:
|
||||
summary: Test if default parameter is passed to function
|
||||
|
||||
17
tests/fixtures/simple/swagger.yaml
vendored
17
tests/fixtures/simple/swagger.yaml
vendored
@@ -394,6 +394,23 @@ paths:
|
||||
200:
|
||||
description: OK
|
||||
|
||||
/test-float-path/{somefloat}/{someotherfloat}:
|
||||
get:
|
||||
summary: Test type casting of path parameter
|
||||
operationId: fakeapi.hello.test_get_doublefloat
|
||||
parameters:
|
||||
- name: somefloat
|
||||
in: path
|
||||
type: number
|
||||
required: true
|
||||
- name: someotherfloat
|
||||
in: path
|
||||
type: number
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: O
|
||||
|
||||
/test-default-query-parameter:
|
||||
get:
|
||||
summary: Test if default parameter is passed to function
|
||||
|
||||
2
tox.ini
2
tox.ini
@@ -5,7 +5,6 @@ rst-roles=class
|
||||
|
||||
[tox]
|
||||
envlist =
|
||||
{py36}-{min,pypi,dev}
|
||||
{py37}-{min,pypi,dev}
|
||||
{py38}-{min,pypi,dev}
|
||||
{py39}-{min,pypi,dev}
|
||||
@@ -17,7 +16,6 @@ envlist =
|
||||
|
||||
[gh-actions]
|
||||
python =
|
||||
3.6: py36-min,py36-pypi
|
||||
3.7: py37-min,py37-pypi
|
||||
3.8: py38-min,py38-pypi
|
||||
3.9: py39-min,py39-pypi,flake8,isort-check,isort-check-examples,isort-check-tests,mypy
|
||||
|
||||
Reference in New Issue
Block a user