449 path format (#450)

* added test for path formatted parameters

* re-added removed test, as it would generate valid flask route
This commit is contained in:
Kyle Cacciatore
2017-05-10 16:04:48 -04:00
committed by Henning Jacobs
parent c30ba1f571
commit 1f34e3565b
4 changed files with 32 additions and 1 deletions

View File

@@ -18,6 +18,12 @@ def test_app(simple_app):
swagger_icon = app_client.get('/v1.0/ui/images/favicon.ico') # type: flask.Response swagger_icon = app_client.get('/v1.0/ui/images/favicon.ico') # type: flask.Response
assert swagger_icon.status_code == 200 assert swagger_icon.status_code == 200
post_greeting_url = app_client.post('/v1.0/greeting/jsantos/the/third/of/his/name', data={}) # type: flask.Response
assert post_greeting_url.status_code == 200
assert post_greeting_url.content_type == 'application/json'
greeting_response_url = json.loads(post_greeting_url.data.decode('utf-8'))
assert greeting_response_url['greeting'] == 'Hello jsantos thanks for the/third/of/his/name'
post_greeting = app_client.post('/v1.0/greeting/jsantos', data={}) # type: flask.Response post_greeting = app_client.post('/v1.0/greeting/jsantos', data={}) # type: flask.Response
assert post_greeting.status_code == 200 assert post_greeting.status_code == 200
assert post_greeting.content_type == 'application/json' assert post_greeting.content_type == 'application/json'

View File

@@ -38,6 +38,9 @@ def post_greeting(name, **kwargs):
data = {'greeting': 'Hello {name}'.format(name=name)} data = {'greeting': 'Hello {name}'.format(name=name)}
return data return data
def post_greeting_url(name, remainder, **kwargs):
data = {'greeting': 'Hello {name} thanks for {remainder}'.format(name=name,remainder=remainder)}
return data
def post_goodday(name): def post_goodday(name):
data = {'greeting': 'Hello {name}'.format(name=name)} data = {'greeting': 'Hello {name}'.format(name=name)}

View File

@@ -23,7 +23,28 @@ paths:
description: Name of the person to greet. description: Name of the person to greet.
required: true required: true
type: string type: string
/greeting/{name}/{remainder}:
post:
summary: Generate greeting and collect the remainder of the url
description: Generates a greeting message and includes the rest of the url.
operationId: fakeapi.hello.post_greeting_url
responses:
'200':
description: greeting response with url
schema:
type: object
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
type: string
- name: remainder
in: path
description: the rest of the url
required: true
type: string
format: path
/greetings/{name}: /greetings/{name}:
get: get:
summary: Generate greeting summary: Generate greeting

View File

@@ -9,6 +9,7 @@ def test_flaskify_path():
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'integer'}) == "foo/<int:a>/<b>" assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'integer'}) == "foo/<int:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'number'}) == "foo/<float:a>/<b>" assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'number'}) == "foo/<float:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'path'}) == "foo/<path:a>/<b>" assert flask_utils.flaskify_path("foo/{a}/{b}", {'a': 'path'}) == "foo/<path:a>/<b>"
assert flask_utils.flaskify_path("foo/{a}", {'a': 'path'}) == "foo/<path:a>"
def test_flaskify_endpoint(): def test_flaskify_endpoint():