How to use the connexion.operations.Swagger2Operation function in connexion

To help you get started, we’ve selected a few connexion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando / connexion / tests / test_resolver.py View on Github external
def test_resty_resolve_with_default_module_name_and_x_router_controller_will_resolve_resource_root_get_as_search():
    operation = Swagger2Operation(api=None,
                                  method='GET',
                                  path='/hello',
                                  path_parameters=[],
                                  operation={
                                      'x-swagger-router-controller': 'fakeapi.hello',
                                  },
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.hello.search'
github zalando / connexion / tests / test_resolver.py View on Github external
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_as_configured():
    operation = Swagger2Operation(api=None,
                                  method='GET',
                                  path='/hello',
                                  path_parameters=[],
                                  operation={},
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=RestyResolver('fakeapi', 'api_list'))
    assert operation.operation_id == 'fakeapi.hello.api_list'
github zalando / connexion / tests / test_resolver.py View on Github external
def test_resty_resolve_with_default_module_name_lowercase_verb():
    operation = Swagger2Operation(api=None,
                                  method='get',
                                  path='/hello/{id}',
                                  path_parameters=[],
                                  operation={},
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.hello.get'
github zalando / connexion / tests / test_resolver.py View on Github external
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_get_as_search():
    operation = Swagger2Operation(api=None,
                                  method='GET',
                                  path='/hello',
                                  path_parameters=[],
                                  operation={},
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.hello.search'
github zalando / connexion / tests / test_operation2.py View on Github external
def test_parameter_reference(api):
    op_spec = make_operation(OPERATION3, definitions=False)
    operation = Swagger2Operation(api=api,
                                  method='GET',
                                  path='endpoint',
                                  path_parameters=[],
                                  operation=op_spec,
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=Resolver())
    assert operation.parameters == [{'in': 'path', 'type': 'integer'}]
github zalando / connexion / tests / test_operation2.py View on Github external
op_spec['parameters'][1]['default'] = 1
    Swagger2Operation(
        api=api, method='GET', path='endpoint', path_parameters=[],
        operation=op_spec, app_produces=['application/json'],
        app_consumes=['application/json'], app_security=[],
        security_definitions={}, definitions=DEFINITIONS,
        parameter_definitions=PARAMETER_DEFINITIONS, resolver=Resolver()
    )
    op_spec = make_operation(OPERATION6, parameters=False)
    op_spec['parameters'][0]['default'] = {
        'keep_stacks': 1,
        'image_version': 'one',
        'senza_yaml': 'senza.yaml',
        'new_traffic': 100
    }
    Swagger2Operation(
        api=api, method='POST', path='endpoint', path_parameters=[],
        operation=op_spec, app_produces=['application/json'],
        app_consumes=['application/json'], app_security=[],
        security_definitions={}, definitions=DEFINITIONS,
        parameter_definitions={}, resolver=Resolver()
    )
github zalando / connexion / tests / test_operation2.py View on Github external
def test_operation_local_security_oauth2(api, monkeypatch):
    dummy = object()
    verify_oauth = mock.MagicMock(return_value=dummy)
    monkeypatch.setattr('connexion.operations.secure.verify_oauth', verify_oauth)

    op_spec = make_operation(OPERATION8)
    operation = Swagger2Operation(api=api,
                                  method='GET',
                                  path='endpoint',
                                  path_parameters=[],
                                  operation=op_spec,
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions=SECURITY_DEFINITIONS_LOCAL,
                                  definitions=DEFINITIONS,
                                  parameter_definitions=PARAMETER_DEFINITIONS,
                                  resolver=Resolver())
    assert isinstance(operation.function, types.FunctionType)
    security_decorator = operation.security_decorator
    assert security_decorator.func is verify_security
    assert len(security_decorator.args[0]) == 1
    assert security_decorator.args[0][0] is dummy
github zalando / connexion / tests / test_mock.py View on Github external
def test_mock_resolver_no_examples():
    resolver = MockResolver(mock_all=True)

    responses = {
        '418': {}
    }

    operation = Swagger2Operation(api=None,
                                  method='GET',
                                  path='endpoint',
                                  path_parameters=[],
                                  operation={
                                      'responses': responses
                                  },
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions={},
                                  resolver=resolver)
    assert operation.operation_id == 'mock-1'

    response, status_code = resolver.mock_operation(operation)
github zalando / connexion / tests / test_operation2.py View on Github external
def test_get_path_parameter_types(api):
    op_spec = make_operation(OPERATION1, parameters=False)
    op_spec['parameters'] = [
        {'in': 'path', 'type': 'int', 'name': 'int_path'},
        {'in': 'path', 'type': 'string', 'name': 'string_path'},
        {'in': 'path', 'type': 'string', 'format': 'path', 'name': 'path_path'}
    ]

    operation = Swagger2Operation(
        api=api, method='GET', path='endpoint', path_parameters=[],
        operation=op_spec, app_produces=['application/json'],
        app_consumes=['application/json'],
        definitions=DEFINITIONS, resolver=Resolver()
    )

    assert {'int_path': 'int', 'string_path': 'string', 'path_path': 'path'} == operation.get_path_parameter_types()
github zalando / connexion / tests / test_mock.py View on Github external
path='endpoint',
                                  path_parameters=[],
                                  operation={
                                      'operationId': 'fakeapi.hello.get'
                                  },
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions={},
                                  resolver=resolver)
    assert operation.operation_id == 'fakeapi.hello.get'

    # mock only the nonexistent ones
    operation = Swagger2Operation(api=None,
                                  method='GET',
                                  path='endpoint',
                                  path_parameters=[],
                                  operation={
                                      'operationId': 'fakeapi.hello.nonexistent_function',
                                      'responses': responses
                                  },
                                  app_produces=['application/json'],
                                  app_consumes=['application/json'],
                                  app_security=[],
                                  security_definitions={},
                                  definitions={},
                                  parameter_definitions={},
                                  resolver=resolver)

    # check if it is using the mock function