Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api_deploy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def deploy(config_file,
# Always remove scopes when deploying to Amazon API Gateway
config['gateway']['remove_scopes'] = True

# Always remove descriptions when deploying to Amazon API Gateway
config['gateway']['remove_descriptions'] = True

target_schema = _compile(source_schema, config)
click.secho('Successfully compiled OpenAPI file.\n', fg='green')

Expand Down
1 change: 1 addition & 0 deletions api_deploy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, config_file: ConfigFile, file_path) -> None:
config_file.get('gateway', {}).get('integrationHost', ''))
default_config['gateway'].setdefault('connection_id', config_file.get('gateway', {}).get('connectionId', ''))
default_config['gateway'].setdefault('remove_scopes', config_file.get('gateway', {}).get('removeScopes', False))
default_config['gateway'].setdefault('remove_descriptions', config_file.get('gateway', {}).get('removeDescriptions', False))

default_config['cors'].setdefault('allow_origin', config_file.get('cors', {}).get('origin', '*'))

Expand Down
24 changes: 23 additions & 1 deletion api_deploy/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ def merge_all_of(self, node, schema: Schema):


class ApiGatewayProcessor(AbstractProcessor):
def __init__(self, config: Config, integration_host, connection_id, remove_scopes, **kwargs) -> None:
def __init__(self, config: Config, integration_host, connection_id, remove_scopes, remove_descriptions, **kwargs) -> None:
super().__init__(config)
self.integration_host = integration_host
self.connection_id = connection_id
self.remove_scopes = remove_scopes
self.remove_descriptions = remove_descriptions

def process(self, schema: Schema) -> Schema:
for path in schema['paths']:
Expand All @@ -231,6 +232,11 @@ def process(self, schema: Schema) -> Schema:
# remove all scopes from authorizer, not supported in API Gateway
security[authorizer] = []

# Remove all descriptions from models
if self.remove_descriptions:
for model_name in schema['components'].get('schemas', {}):
self._remove_descriptions(schema['components']['schemas'][model_name])

# Replace all authorizers with API key type
for authorizer in schema['components'].get('securitySchemes', {}):
scheme = schema['components']['securitySchemes'][authorizer]
Expand All @@ -242,6 +248,22 @@ def process(self, schema: Schema) -> Schema:

return schema


def _remove_descriptions(self, schema: object):
if isinstance(schema, dict):
schema.pop('description', None)

if 'properties' in schema:
for property_name in schema['properties']:
self._remove_descriptions(schema['properties'][property_name])

if 'items' in schema:
self._remove_descriptions(schema['items'])
if 'properties' in schema['items']:
for property_name in schema['items']['properties']:
self._remove_descriptions(schema['items']['properties'][property_name])


def _get_response_codes(self, schema, path, method):
responses = {
'default': {
Expand Down
1 change: 1 addition & 0 deletions tests/functional/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ gateway:
integrationHost: https://integration.com
connectionId: 1234567890
removeScopes: true
removeDescriptions: true
headers:
request:
- host
Expand Down
Loading