41 Commits

Author SHA1 Message Date
Robbe Sneyders
4556779343 Fix CLI and drop click dependency (#1762) 2023-10-29 11:34:55 +01:00
Robbe Sneyders
415d383740 Add swagger-ui docs and clean up swagger-ui options (#1739)
Contributes to #1531
2023-10-13 20:33:22 +02:00
Robbe Sneyders
7f111505a2 Add add_middleware interface (#1683)
This PR adds an `add_middleware` method to the apps and
`ConnexionMiddleware` to easily add middleware to the stack. Before, the
only way to do this was to pass in a complete middleware stack.

The default position to add the new middleware is right before the
`ContextMiddleware`, which is the final middleware in the stack. Another
position can be selected by passing in a `MiddlewarePosition` enum,
which defines some positions which make sense.

Since we can no longer assume that the whole middleware stack is defined
when initializing the `ConnexionMiddleware`, we need to delay building
the middleware stack until the `ConnexionMiddleware` is actually called.
This also means we need to delay registering the APIs and error
handlers. This is now all done in the `_build_middleware_stack` method.
2023-04-22 21:37:19 +02:00
Robbe Sneyders
bcdd26ba0d Update CLI for 3.0 (#1687)
Fixes #1684
2023-04-21 12:11:38 +02:00
Robbe Sneyders
69f117ce52 Drop extended ResolverError traceback 2023-02-23 00:13:13 +01:00
Robbe Sneyders
15e985e864 Introduce poetry (#1628) 2023-02-07 20:17:38 +01:00
Robbe Sneyders
073f0d446e Update examples for Connexion 3.0 (#1615)
This PR updates the examples for Connexion 3.0 and merges them for
OpenAPI and Swagger.

2 examples required some changes to make them work:
- The reverse proxy example required some fixes to the
SwaggerUIMiddleware to leverage the `root_path` correctly. This is
included in the PR.
- The enforced defaults example requires the json validator to adapt the
body and pass it on. We currently pass on the original body after
validation, and I'm not sure if we should change this. I'll submit a
separate PR to discuss this.
2022-12-30 20:34:19 +01:00
Robbe Sneyders
600ed4ed94 Format files with black 2022-06-25 23:50:52 +02:00
Robbe Sneyders
ca70b16ff5 Drop aiohttp support (#1491) 2022-03-22 22:26:41 +01:00
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
jlaba
16a896cdbf Switched from mock to unittest.mock (#1218)
* Switched from mock to unittest.mock

* Update test_validation.py

Removed mock comment

* Update test_parameter.py

Removed comment for mock

Co-authored-by: Joachim Langenbach <joachim.langenbach@engsas.de>
2020-04-23 22:59:41 +02:00
Jacob Floyd
bd2552c313 Fix aiohttp upgrade (#951)
* Revert "set max aiohttp version to 3.5.1 (until build is fixed) (#844)"

This reverts commit b2a4287405.

* Fix test_run_with_aiohttp_not_installed

Somewhere between 3.5.1 and 3.5.2, the aiohttp reimport started
succeeding (in connexion.connexion.cli.run()). It's not clear which
change caused the issue, but it's probably one of:

- aio-libs/aiohttp#3469 (Remove wildcard imports)
- aio-libs/aiohttp#3464 (Don't suppress gunicorn cleanup errors)
- aio-libs/aiohttp#3471 (Refactor workers)
- aio-libs/aiohttp#3500 (Ignore done tasks)

In any case, setting sys.modules['aiohttp'] = None should prevent
reimporting it. See: https://stackoverflow.com/a/1350574

I successfully tested locally on py37 with aiohttp 3.5.1 and 3.5.2.
2019-10-15 18:42:28 +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
Daniel Grossmann-Kavanagh
fdac62726d Use server_spec option in cli.py instead of swagger_ui (#745)
- gets rid of deprecation warning when using `connexion run ...` (Fixes #747)
2018-11-07 08:34:47 +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
bbff57ca6e fix wording 2018-04-09 21:25:17 +02:00
Diogo Dutra
8f4ff0313d Changes for aiohttp support:
- Created a metaclass for AbstractAPI (it is used to set the jsonifier for the class);
 - Created a new class method AbstractAPI._set_jsonifier;
 - Changed the code to use the new jsonifier interface;
 - Create a new module called coroutines_wrapper to put the wrapper functions with the 'yield from' statement. It is used to enable frameworks with coroutine handlers;
 - Did the AioHttpApi.get_request coroutine and add req.read() to get the request body;
 - Moved the flask jsonifier to utils and did it a generic jsonifier;
 - Created a function called 'has_coroutine' on utils module;
 - Added aiohttp_jinja2 to requirements-aiohttp;
 - Added a new python3 coreragerc file to skip only python2 lines;
 - Fixed the set of validation_response on test_aiohttp_simple_api.py;
 - Added the test to check the aiohttp body request;
 - Fixed the response for 'aiohttp_bytes_response' and 'aiohttp_non_str_non_json_response' paths on aiohttp/swagger_simple.yml file.
2018-02-05 13:35:56 -02:00
Diogo Dutra
1408dbeb19 Added an aiohttp lib validation on cli 2018-01-18 14:27:08 -02:00
Diogo Dutra
09daab63ca Changed the cli script:
- created a new option called 'server'
 - did wsgi-server option deprecated
 - changed the app-cls option to app-framework
 - fixed the possible frameworks that will run the app
 - added a validation on framework/server selection
2018-01-18 14:27:08 -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
Rafael Caricio
6746cb2be8 Fix mocking API partially 2017-06-30 16:46:26 +02: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
Yoan Blanc
be437a980b Fix isort checks 2016-10-16 11:32:11 +02:00
Victor Torres
90712d1f8c Receiving --host or -H option via CLI and writting test cases.
We’re using -H instead of -h in order not to be confused with help arguments.
Fabric also uses -H as host parameter.
2016-10-09 13:11:54 -03:00
Henning Jacobs
ff5596aab1 #292 fix comment 2016-09-30 11:48:23 +02:00
Henning Jacobs
1f25b0dc0c #292 test run with --mock 2016-09-30 11:48:02 +02:00
Havoc Pennington
8a67a3bf3f Add a --base-path option to the CLI
This allows deploying at different paths without
editing the API spec.
2016-09-22 16:48:07 -04:00
Rafael Caricio
871fd3ef6f Print version using the CLI 2016-09-17 15:03:11 +02:00
Rafael Caricio
d71674b35b Make sure very verbose is the same as debug 2016-09-15 10:29:00 +02:00
Rafael Caricio
c1d55c1116 Support different log levels in CLI 2016-09-15 10:25:22 +02:00
Rafael Caricio
9b7cb99318 Check that all options are passed correctly from the CLI module 2016-09-15 09:53:58 +02:00
Rafael Caricio
07c6eb7b8a Fix parameters in the CLI interface 2016-09-14 21:06:17 +02:00
Rafael Caricio
d9b59c65ac Fix imports 2016-09-13 22:44:15 +02:00
Rafael Caricio
8ef5794df8 Merge master into cli branch 2016-09-13 22:33:41 +02:00
Rafael Caricio
e7f96e4bd9 Sort imports 2016-09-13 00:11:43 +02:00
Rafael Caricio
82dcb617a9 Pass along all options available 2016-09-12 23:18:22 +02:00
Rafael Caricio
9c5f6bcd8a Refine stub option 2016-09-12 22:58:38 +02:00
Rafael Caricio
e9d5a61437 Run with specification stubs 2016-09-12 21:55:47 +02:00
Rafael Caricio
c74d8cdd3b Provide CLI support for runnning specifications 2016-09-12 18:28:14 +02:00