mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-07 20:37:44 +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:
@@ -3,7 +3,6 @@
|
||||
import pathlib
|
||||
import tempfile
|
||||
|
||||
from swagger_spec_validator.common import SwaggerValidationError
|
||||
from yaml import YAMLError
|
||||
|
||||
import pytest
|
||||
@@ -31,6 +30,14 @@ def test_api():
|
||||
assert api2.blueprint.name == '/v1_0'
|
||||
assert api2.blueprint.url_prefix == '/v1.0'
|
||||
|
||||
api3 = FlaskApi(TEST_FOLDER / "fixtures/simple/openapi.yaml", base_path="/api/v1.0")
|
||||
assert api3.blueprint.name == '/api/v1_0'
|
||||
assert api3.blueprint.url_prefix == '/api/v1.0'
|
||||
|
||||
api4 = FlaskApi(TEST_FOLDER / "fixtures/simple/openapi.yaml")
|
||||
assert api4.blueprint.name == '/v1_0'
|
||||
assert api4.blueprint.url_prefix == '/v1.0'
|
||||
|
||||
|
||||
def test_api_base_path_slash():
|
||||
api = FlaskApi(TEST_FOLDER / "fixtures/simple/basepath-slash.yaml")
|
||||
@@ -86,13 +93,13 @@ def test_invalid_operation_does_not_stop_application_in_debug_mode():
|
||||
|
||||
def test_other_errors_stop_application_to_setup():
|
||||
# Errors should still result exceptions!
|
||||
with pytest.raises(SwaggerValidationError):
|
||||
with pytest.raises(InvalidSpecification):
|
||||
FlaskApi(TEST_FOLDER / "fixtures/bad_specs/swagger.yaml",
|
||||
base_path="/api/v1.0", arguments={'title': 'OK'})
|
||||
|
||||
|
||||
def test_invalid_schema_file_structure():
|
||||
with pytest.raises(SwaggerValidationError):
|
||||
with pytest.raises(InvalidSpecification):
|
||||
FlaskApi(TEST_FOLDER / "fixtures/invalid_schema/swagger.yaml",
|
||||
base_path="/api/v1.0", arguments={'title': 'OK'}, debug=True)
|
||||
|
||||
@@ -111,12 +118,12 @@ def test_use_of_safe_load_for_yaml_swagger_specs():
|
||||
f.flush()
|
||||
try:
|
||||
FlaskApi(pathlib.Path(f.name), base_path="/api/v1.0")
|
||||
except SwaggerValidationError:
|
||||
except InvalidSpecification:
|
||||
pytest.fail("Could load invalid YAML file, use yaml.safe_load!")
|
||||
|
||||
|
||||
def test_validation_error_on_completely_invalid_swagger_spec():
|
||||
with pytest.raises(SwaggerValidationError):
|
||||
with pytest.raises(InvalidSpecification):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write('[1]\n'.encode())
|
||||
f.flush()
|
||||
@@ -128,9 +135,3 @@ def mock_api_logger(monkeypatch):
|
||||
mocked_logger = MagicMock(name='mocked_logger')
|
||||
monkeypatch.setattr('connexion.apis.abstract.logger', mocked_logger)
|
||||
return mocked_logger
|
||||
|
||||
|
||||
def test_warn_users_about_base_url_parameter_name_change(mock_api_logger):
|
||||
FlaskApi(TEST_FOLDER / "fixtures/simple/swagger.yaml", base_url="/api/v1")
|
||||
mock_api_logger.warning.assert_called_with(
|
||||
'Parameter base_url should be no longer used. Use base_path instead.')
|
||||
|
||||
Reference in New Issue
Block a user