Skip to content

Commit

Permalink
Merge branch 'swagger-param'
Browse files Browse the repository at this point in the history
* swagger-param:
  Move 'parameters' key in swagger up one level
  • Loading branch information
jamesls committed Aug 31, 2017
2 parents 3c75891 + cd77232 commit f787f3e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
CHANGELOG
=========

Next Release (TBD)
==================

* Fix issue where requestParameters were not being mapped
correctly resulting in invalid generated javascript SDKs
(`#498 <https://github.com/aws/chalice/issues/498>`__)


1.0.1
=====

Expand Down
8 changes: 4 additions & 4 deletions chalice/deploy/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def _generate_route_method(self, view):
current['security'] = [{'api_key': []}]
if view.authorizer:
current['security'] = [{view.authorizer.name: []}]
if view.view_args:
self._add_view_args(current, view.view_args)
return current

def _generate_precanned_responses(self):
Expand Down Expand Up @@ -164,13 +166,11 @@ def _generate_apig_integ(self, view):
'contentHandling': 'CONVERT_TO_TEXT',
'type': 'aws_proxy',
}
if view.view_args:
self._add_view_args(apig_integ, view.view_args)
return apig_integ

def _add_view_args(self, apig_integ, view_args):
def _add_view_args(self, single_method, view_args):
# type: (Dict[str, Any], List[str]) -> None
apig_integ['parameters'] = [
single_method['parameters'] = [
{'name': name, 'in': 'path', 'required': True, 'type': 'string'}
for name in view_args
]
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def _clear_app_import(self):
del sys.modules['app']


@pytest.fixture
def apig_client():
s = botocore.session.get_session()
return s.create_client('apigateway')


@pytest.fixture(scope='module')
def smoke_test_app(tmpdir_factory):
tmpdir = str(tmpdir_factory.mktemp('smoketestapp'))
Expand Down Expand Up @@ -160,6 +166,34 @@ def test_supports_path_params(smoke_test_app):
assert smoke_test_app.get_json('/path/bar') == {'path': 'bar'}


def test_path_params_mapped_in_api(smoke_test_app, apig_client):
# Use the API Gateway API to ensure that path parameters
# are modeled as such. Otherwise this will break
# SDK generation and any future features that depend
# on params. We could try to verify the generated
# javascript SDK looks ok. Instead we're going to
# query the resources we've created in API gateway
# and make sure requestParameters are present.
rest_api_id = smoke_test_app.rest_api_id
# This is the resource id for the '/path/{name}'
# route. As far as I know this is the best way to get
# this id.
resource_id = [
resource for resource in
apig_client.get_resources(restApiId=rest_api_id)['items']
if resource['path'] == '/path/{name}'
][0]['id']
method_config = apig_client.get_method(
restApiId=rest_api_id,
resourceId=resource_id,
httpMethod='GET'
)
assert 'requestParameters' in method_config
assert method_config['requestParameters'] == {
'method.request.path.name': True
}


def test_supports_post(smoke_test_app):
app_url = smoke_test_app.url
response = requests.post(app_url + '/post')
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/deploy/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ def foo(name):

doc = swagger_gen.generate_swagger(sample_app)
single_method = doc['paths']['/path/{capture}']['get']
apig_integ = single_method['x-amazon-apigateway-integration']
assert 'parameters' in apig_integ
assert apig_integ['parameters'] == [
assert 'parameters' in single_method
assert single_method['parameters'] == [
{'name': "capture", "in": "path", "required": True, "type": "string"}
]

Expand Down

0 comments on commit f787f3e

Please sign in to comment.