diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 413197ef1..c3a551553 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -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 }} diff --git a/connexion/apps/flask_app.py b/connexion/apps/flask_app.py index 8ea46f25c..46481b176 100644 --- a/connexion/apps/flask_app.py +++ b/connexion/apps/flask_app.py @@ -172,7 +172,7 @@ def default(self, o): 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) diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index 33d52410d..b834176e8 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -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() diff --git a/tests/fakeapi/hello/__init__.py b/tests/fakeapi/hello/__init__.py index 01d9c7212..490f939d3 100644 --- a/tests/fakeapi/hello/__init__.py +++ b/tests/fakeapi/hello/__init__.py @@ -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} diff --git a/tests/fixtures/simple/openapi.yaml b/tests/fixtures/simple/openapi.yaml index 9ab6f6915..050f44be7 100644 --- a/tests/fixtures/simple/openapi.yaml +++ b/tests/fixtures/simple/openapi.yaml @@ -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 diff --git a/tests/fixtures/simple/swagger.yaml b/tests/fixtures/simple/swagger.yaml index 5133eac1a..9628b8224 100644 --- a/tests/fixtures/simple/swagger.yaml +++ b/tests/fixtures/simple/swagger.yaml @@ -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 diff --git a/tox.ini b/tox.ini index 8b8085af5..8e0472cb0 100644 --- a/tox.ini +++ b/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