Files
connexion/tests/test_resolver3.py
João Santos 44ea9336fe Connexion 2.0 (#619)
- App and Api options must be provided through the "options" argument (``old_style_options`` have been removed).
- You must specify a form content-type in 'consumes' in order to consume form data.
- The `Operation` interface has been formalized in the `AbstractOperation` class.
- The `Operation` class has been renamed to `Swagger2Operation`.
- Array parameter deserialization now follows the Swagger 2.0 spec more closely.
  In situations when a query parameter is passed multiple times, and the collectionFormat is either csv or pipes, the right-most value will be used.
  For example, `?q=1,2,3&q=4,5,6` will result in `q = [4, 5, 6]`.
  The old behavior is available by setting the collectionFormat to `multi`, or by importing `decorators.uri_parsing.AlwaysMultiURIParser` and passing `parser_class=AlwaysMultiURIParser` to your Api.
- The spec validator library has changed from `swagger-spec-validator` to `openapi-spec-validator`.
- Errors that previously raised `SwaggerValidationError` now raise the `InvalidSpecification` exception.
  All spec validation errors should be wrapped with `InvalidSpecification`.
- Support for nullable/x-nullable, readOnly and writeOnly/x-writeOnly has been added to the standard json schema validator.
- Custom validators can now be specified on api level (instead of app level).
- Added support for basic authentication and apikey authentication
- If unsupported security requirements are defined or ``x-tokenInfoFunc``/``x-tokenInfoUrl`` is missing, connexion now denies requests instead of allowing access without security-check.
- Accessing ``connexion.request.user`` / ``flask.request.user`` is no longer supported, use ``connexion.context['user']`` instead
2018-11-05 14:50:42 +01:00

181 lines
5.3 KiB
Python

from connexion.operations import OpenAPIOperation
from connexion.resolver import Resolver, RestyResolver
COMPONENTS = {'parameters': {'myparam': {'in': 'path', 'schema': {'type': 'integer'}}}}
def test_standard_resolve_x_router_controller():
operation = OpenAPIOperation(
api=None,
method='GET',
path='endpoint',
path_parameters=[],
operation={
'x-openapi-router-controller': 'fakeapi.hello',
'operationId': 'post_greeting',
},
app_security=[],
components=COMPONENTS,
resolver=Resolver()
)
assert operation.operation_id == 'fakeapi.hello.post_greeting'
def test_resty_resolve_operation_id():
operation = OpenAPIOperation(
api=None,
method='GET',
path='endpoint',
path_parameters=[],
operation={
'operationId': 'fakeapi.hello.post_greeting',
},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.post_greeting'
def test_resty_resolve_x_router_controller_with_operation_id():
operation = OpenAPIOperation(
api=None,
method='GET',
path='endpoint',
path_parameters=[],
operation={
'x-openapi-router-controller': 'fakeapi.hello',
'operationId': 'post_greeting',
},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.post_greeting'
def test_resty_resolve_x_router_controller_without_operation_id():
operation = OpenAPIOperation(api=None,
method='GET',
path='/hello/{id}',
path_parameters=[],
operation={'x-openapi-router-controller': 'fakeapi.hello'},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi'))
assert operation.operation_id == 'fakeapi.hello.get'
def test_resty_resolve_with_default_module_name():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/hello/{id}',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.get'
def test_resty_resolve_with_default_module_name_lowercase_verb():
operation = OpenAPIOperation(
api=None,
method='get',
path='/hello/{id}',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.get'
def test_resty_resolve_with_default_module_name_will_translate_dashes_in_resource_name():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/foo-bar',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.foo_bar.search'
def test_resty_resolve_with_default_module_name_can_resolve_api_root():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.get'
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_get_as_search():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/hello',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.search'
def test_resty_resolve_with_default_module_name_and_x_router_controller_will_resolve_resource_root_get_as_search():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/hello',
path_parameters=[],
operation={
'x-openapi-router-controller': 'fakeapi.hello',
},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.search'
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_as_configured():
operation = OpenAPIOperation(
api=None,
method='GET',
path='/hello',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi', 'api_list')
)
assert operation.operation_id == 'fakeapi.hello.api_list'
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_post_as_post():
operation = OpenAPIOperation(
api=None,
method='POST',
path='/hello',
path_parameters=[],
operation={},
app_security=[],
components=COMPONENTS,
resolver=RestyResolver('fakeapi')
)
assert operation.operation_id == 'fakeapi.hello.post'