Skip to content

Commit

Permalink
Merge pull request #95 from fehguy/issue-94
Browse files Browse the repository at this point in the history
added logic for detecting x-swagger-router-controller
  • Loading branch information
hjacobs committed Nov 18, 2015
2 parents b148e73 + d6524f1 commit 80084b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
11 changes: 10 additions & 1 deletion connexion/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def __init__(self, method, path, operation, app_produces, app_security,
self.validate_responses = validate_responses

self.operation = operation
self.operation_id = operation['operationId']
operation_id = operation['operationId']

router_controller = operation.get('x-swagger-router-controller')

self.operation_id = self.detect_controller(operation_id, router_controller)
# todo support definition references
# todo support references to application level parameters
self.parameters = list(self.resolve_parameters(operation.get('parameters', [])))
Expand All @@ -85,6 +89,11 @@ def __init__(self, method, path, operation, app_produces, app_security,
self.security = operation.get('security', app_security)
self.__undecorated_function = resolver(self.operation_id)

def detect_controller(self, operation_id, router_controller):
if router_controller is None:
return operation_id
return router_controller + '.' + operation_id

def resolve_reference(self, schema):
schema = schema.copy() # avoid changing the original schema
reference = schema.get('$ref') # type: str
Expand Down
35 changes: 35 additions & 0 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@
OPERATION5 = {'operationId': 'fakeapi.hello.post_greeting',
'parameters': [{'$ref': '/parameters/fail'}]}

OPERATION6 = {'description': 'Adds a new stack to be created by lizzy and returns the '
'information needed to keep track of deployment',
'operationId': 'post_greeting',
'x-swagger-router-controller': 'fakeapi.hello',
'parameters': [{'in': 'body',
'name': 'new_stack',
'required': True,
'schema': {'$ref': '#/definitions/new_stack'}}],
'responses': {201: {'description': 'Stack to be created. The '
'CloudFormation Stack creation can '
"still fail if it's rejected by senza "
'or AWS CF.',
'schema': {'$ref': '#/definitions/stack'}},
400: {'description': 'Stack was not created because request '
'was invalid',
'schema': {'$ref': '#/definitions/problem'}},
401: {'description': 'Stack was not created because the '
'access token was not provided or was '
'not valid for this operation',
'schema': {'$ref': '#/definitions/problem'}}},
'security': [{'oauth': ['uid']}],
'summary': 'Create new stack'}

SECURITY_DEFINITIONS = {'oauth': {'type': 'oauth2',
'flow': 'password',
'x-tokenInfoUrl': 'https://ouath.example/token_info',
Expand Down Expand Up @@ -225,3 +248,15 @@ def test_resolve_invalid_reference():

exception = exc_info.value # type: InvalidSpecification
assert exception.reason == "GET endpoint '$ref' needs to start with '#/'"

def test_detect_controller():
operation = Operation(method='GET',
path='endpoint',
operation=OPERATION6,
app_produces=['application/json'],
app_security=[],
security_definitions={},
definitions={},
parameter_definitions=PARAMETER_DEFINITIONS,
resolver=get_function_from_name)
assert operation.operation_id == 'fakeapi.hello.post_greeting'

0 comments on commit 80084b4

Please sign in to comment.