mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 20:37:46 +00:00
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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from connexion.mock import MockResolver, partial
|
||||
from connexion.operation import Operation
|
||||
from connexion.operations import Swagger2Operation
|
||||
|
||||
|
||||
def test_partial():
|
||||
@@ -23,64 +23,27 @@ def test_mock_resolver():
|
||||
}
|
||||
}
|
||||
|
||||
operation = Operation(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)
|
||||
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)
|
||||
assert status_code == 200
|
||||
assert response == {'foo': 'bar'}
|
||||
|
||||
def test_mock_resolver_ref_schema_example():
|
||||
resolver = MockResolver(mock_all=True)
|
||||
|
||||
responses = {
|
||||
'default': {
|
||||
'schema': {
|
||||
'$ref': '#/definitions/Schema'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
operation = Operation(api=None,
|
||||
method='GET',
|
||||
path='endpoint',
|
||||
path_parameters=[],
|
||||
operation={
|
||||
'responses': responses
|
||||
},
|
||||
app_produces=['application/json'],
|
||||
app_consumes=['application/json'],
|
||||
app_security=[],
|
||||
security_definitions={},
|
||||
definitions={
|
||||
'Schema': {
|
||||
'example': {
|
||||
'foo': 'bar'
|
||||
}
|
||||
}
|
||||
},
|
||||
parameter_definitions={},
|
||||
resolver=resolver)
|
||||
assert operation.operation_id == 'mock-1'
|
||||
|
||||
response, status_code = resolver.mock_operation(operation)
|
||||
assert status_code == 200
|
||||
assert response == {'foo': 'bar'}
|
||||
|
||||
def test_mock_resolver_inline_schema_example():
|
||||
def test_mock_resolver_example():
|
||||
resolver = MockResolver(mock_all=True)
|
||||
|
||||
responses = {
|
||||
@@ -99,20 +62,20 @@ def test_mock_resolver_inline_schema_example():
|
||||
}
|
||||
}
|
||||
|
||||
operation = Operation(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)
|
||||
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)
|
||||
@@ -126,20 +89,20 @@ def test_mock_resolver_no_examples():
|
||||
'418': {}
|
||||
}
|
||||
|
||||
operation = Operation(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)
|
||||
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)
|
||||
@@ -155,38 +118,38 @@ def test_mock_resolver_notimplemented():
|
||||
}
|
||||
|
||||
# do not mock the existent functions
|
||||
operation = Operation(api=None,
|
||||
method='GET',
|
||||
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)
|
||||
operation = Swagger2Operation(api=None,
|
||||
method='GET',
|
||||
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 = Operation(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)
|
||||
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
|
||||
assert operation._Operation__undecorated_function() == ('No example response was defined.', 418)
|
||||
assert operation._resolution.function() == ('No example response was defined.', 418)
|
||||
|
||||
Reference in New Issue
Block a user