42 Commits

Author SHA1 Message Date
Christian Clauss
6c4f99051d Upgrade syntax for Python >= 3.6 (#1383)
* pyupgrade --py36-plus **/*.py

* Fix indentation

* Fix indentation
2021-07-04 20:04:22 +02:00
Robbe Sneyders
fb44e6acb4 Fix import order for isort 2021-06-25 13:08:46 +02:00
Jyhess
8830d56841 Async security check (#869)
Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>

Fixes #868

Allow to use coroutines with Aiohttp in security handlers.

- Move all function from connexion.operations.security to a class in connexion.security.SecurityHandlerFactory
- Specialize this class for AioHttp and Flask, and instantiate them in dedicated APIs
- AioHttp specialization now support coroutines
- pass_context_arg_name option is supported for security handlers
2020-07-22 06:52:16 +00:00
Daniel Grossmann-Kavanagh
c672c85c00 add tests for reverse proxies 2019-12-11 17:58:15 -08:00
Jyhess
d18c387d94 Return tuple for aiohttp (#849)
* Support aiohttp handlers to return tuples

* Minor update from #828 review

* Factorize more code between Flask and AioHttp response

* Fix CI

* Drop six string types

* Standardize response logging

* Handle one-tuples that only contain data

* clean up a couple of type hint comments

* Add a few more get_response tests

* Adjust _prepare_body interface to simplify improving _serialize_data

Rename _jsonify_data to _serialize_data to make its purpose easier to
understand (this was also known as _cast_body in aiohttp_api).

In exploring how to harmonize json serialization between aiothttp and
flask, we needed to be able to adjust the mimetype from within
_serialize_data. Harmonizing the actual serialization has to wait until
backwards incompatible changes can be made, but we can keep the new
interface, as these functions were introduced in this PR (#849).

* Add deprecation warnings about implicit serialization
2019-12-11 12:54:44 +01:00
Jyhess
db4459fa20 Datetime serialization (#851)
* Add datetime and uuid serialization for AioHttp

* Remove ujson dependency

* fix merge error

* Retry CI

* remove bad jsonifier import

* remove ujson import
2019-12-03 05:23:36 +01:00
Peter Bašista
738f47ed50 Do not sanitize body keys in OpenAPI 3 (#1008)
* Remove the unused "query_sanitazion" fixture

* Test whether no sanitization is performed in the request body

* Do not perform sanitization on request body keys in OpenAPI v3

The deserialized JSON form of the request body
needs to be passed to the client applications
* without further modification *
so that they can work directly with objects
that have been received over the network.
The only names for which sanitization makes sense
are the ones which are used as Python identifiers.

Keys of the top-level JSON object within the request payload
are never used by Connexion as Python identifiers.

Also, no such sanitization of keys within request body
is performed in OpenAPI v2.

Closes issue #835.
2019-12-03 05:01:49 +01:00
Fabian Wollert
54e50f2278 handle deepObject and explode: true (#971)
* first implementation draft

* gitignore virtualenv

* use isinstance instead of type function

* fix tests

* remove unused function

* move object parsing to uri_parsing.py

* remove not needed import

* only test for OpenAPI

* remove not needed import

* make it work for other cases again

* flake8 fixes

* python2.7 fixes

* isort fix

* address code review comments

* remove for loop and address other comments

* remove not needed abstract function

* move array unnesting into uri_parsing

* make nested arrays possible

* style fixes

* style fixes

* test other data types

* comment and simplify function

* WIP: start additionalProperties test

* test additionalProperties

* remove uneccessary exception

* set default values

* set default values also in response

* flake8 fixes

* fix test

* use suggestions from dtkav's branch

* fix tests partially

* fix tests partially

* fix tests

* fix tests

* add comments for clarity
2019-10-15 17:36:58 +02:00
Daniel Grossmann-Kavanagh
08e4536e5e bump and pin isort, apply all automatic fixes (#903)
Fixes the build.

Changes proposed in this pull request:
 - apply all of the isort changes that resulted from the latest version
 - pin to the latest version (4.3.15) so this doesn't happen again, unless we bump the version on purpose
2019-03-15 13:04:33 +01:00
Diogo Dutra
03a0febbf9 Fixed aiohttp test client deprecation messages. (#810) 2018-12-11 08:50:46 +01:00
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
Henning Jacobs
b775d4de05 Merge branch 'aiohttp_support' of https://github.com/dutradda/connexion into dutradda-aiohttp_support 2018-04-09 21:22:55 +02:00
Shaun Kaasten
a4cabb23ae Allow token_info response to use 'scopes' key (#565) 2018-02-08 16:30:00 +01:00
Maksim Ekimovskii
2841697b9e aiohttp tests: simplify folder layout; naming refactoring. Small aiohttp_api refactoring + tests; Extend aiohttp swagger files and fake apis. Problem with request body for aiohttp handlers remains; 2018-02-03 17:40:03 +02:00
Diogo Dutra
f24ca441dc Changes did on the base code to support aiohttp
- Added the AioHttpApi and AioHttpApp on connexion __init__;
- Created an abstract method on AbstractApi to cast the framework response to connexion response;
- Implemented the get_connexion_response on FlaskApi;
- Changed the CLI to use any kind of App class;
- Changed the ResponseValidator to always convert the response to a connexion response;
- Changed the ResponseValidator to support coroutine responses;
- Added the aiohttp as optional dependency;
- Added ujson as optional dependency;
- Skipped the aiohttp tests run on python 2.7;
- Changed the tests configs to run aiohttp tests properly on python 3.4+.
2018-01-18 12:53:58 -02:00
Mikko Valkonen
f4bc6dc71b FIX a typo causing an ERROR log (#523)
* FIX a typo causing an ERROR log

A small bug was introduced in #500 when sanitizing the request query
parameters. Instead of fetching the arguments from `request.query`,
the parameters were sanitized from the `request.form`. This causes an
error log to be printed, as the parameters are not expected for the
query (for example in the case of a POST request).

Fixes #504

* adds a fixture for testing query param sanitazion

Adds a simple fixture to test form and query parameter sanitazion. This
is mostly related to #522, in which the `formData` parameters were
treated as query parameters.

* add a test to validate form data params

* introduce testfixtures library
2017-11-16 13:04:06 +01:00
Mohab Usama
a275f7b0e2 Use Authorization headers for verifying token info (#542)
* Use Authorization headers for retrieving token info

* Fix flake8

* Adjust token info example

* Only accept Authorization headers in test
2017-11-14 18:13:41 +01:00
Rafael Carício
93c06711ed New style of passing options to Connexion (#436)
* Order classes by relevance in module

* Order definitions by relevance within module

* Swagger UI options extracted

* New style options

* Use new-style options

* Reuse code

* Sort imports

* Ignore typing imports

* Warn users about parameter name change

* Add back isort check

* Fix isort check
2017-04-11 16:47:21 +02:00
Rafael Carício
1858c9d4a0 Flask required only if necessary (#424)
* Example with Flask support

* Only show import error when trying to use Flask

* Re-organize imports

* Move flask_utils next to related module

* Code style

* Change back to incentivizes

* Includes Flask by default

* Project clean up

* Update Rafael Caricio's e-mail address

* Fix conflicts
2017-04-04 20:48:08 +02:00
Diogo Dutra
3952ea2771 did changes requested by isort and flake8 2017-04-04 08:20:25 -03:00
Diogo
5857dd237f Uncouple all flask functions from base code.
removed test_decorators and test_parameter (this test is useless now);
removed the request/response containers and add new request response classes;
created a abstract api class and a api flask class;
derived classes will implements the get_response/get_request methods that will convert framework req/resp types to connexion req/resp types;
moved the jsonifier from produces to flask api;
created a abstract app class and a app flask class;
changed all validators to use the ConnexionRequest instead flask request;
changed the problem function to generate a ConnexionRequest;
created a new user variables container called context (this is a property of ConnexionRequest). this will be passed as kwargs to all operations functions;
this context is used on authentication;
fixed all tests to new API;
some changes that I did may not be documented in this commit.
2017-04-04 08:20:24 -03:00
Diogo Dutra
a7af62fbf0 Uncouple flask from App and Api. Created Abstract classes for theses modules. Fixed the tests 2017-04-04 08:20:23 -03:00
Dan Ballance
702142ec48 Fixes #340 | Convert camelcased parameter names to Python style 2017-03-09 16:42:17 +00:00
Rafael Caricio
9b036923ec Fix annoying typo 2016-12-10 22:37:40 +01:00
Rafael Caricio
3b5bb13276 Refactor code to fix confusion with returned values 2016-12-10 19:54:27 +01:00
Yoan Blanc
be437a980b Fix isort checks 2016-10-16 11:32:11 +02:00
Jens Finkhaeuser
74cec244b4 Fixes after running & fixing TOXENV=isort-check tox 2016-09-13 16:24:28 +02:00
Jens Finkhaeuser
9d4a40ee38 Merge branch 'fix-missing-operation-id' into bad-operation-id-to-5xx
See #274 for discussion.
2016-09-13 15:37:23 +02:00
Jens Finkhaeuser
328aa51f6c Fix isort errors. Some of these look like they're not from my branch to
begin with.
2016-09-12 13:56:29 +02:00
Jens Finkhaeuser
3cd04f8b8d Add test cases for the resolver_error flag. That's what it should do,
next up: the implementation.
2016-09-09 11:52:05 +02:00
Jens Finkhaeuser
f804a96a45 It's bad practice to derive custom exception classes from BaseException.
See https://www.python.org/dev/peps/pep-0352/
2016-09-07 13:36:36 +02:00
Dylan Semler
b7c6dede95 Add flag for strict_validation on extra parameters 2016-07-31 20:21:19 -04:00
Rafael Caricio
654df09838 #256 🎯 identify the bug 2016-07-27 22:57:23 +02:00
Arjun Naik
dba916c354 Fix for when parameter spec is unordered. 2016-05-17 16:29:32 +02:00
Rafael Caricio
c30bdbb324 Fix import sorting in examples and tests 2016-04-08 14:33:27 +02:00
Rafael Caricio
a86b96c5e2 Sort imports in tests and examples 2016-04-08 14:33:27 +02:00
Rafael Caricio
6358c8c47d Adopt isort to ensure better code quality 2016-04-08 14:33:27 +02:00
João Santos
e4ab78b619 #173 Use new-style Python classes since we support Python 2.7 2016-03-08 08:08:47 +01:00
Rafael Caricio
6d5630e32d Increases significantly the test running time 2016-02-25 16:41:36 +01:00
Rafael Caricio
d6aac92eee Increase coverage 2016-02-25 15:41:11 +01:00
Rafael Caricio
a7aec5d53c Split tests in isolated modules 2016-02-25 14:49:19 +01:00
Rafael Caricio
2fec6e9259 Leave body param validation to external lib 2016-02-25 14:49:19 +01:00