Commit Graph

1320 Commits

Author SHA1 Message Date
Robbe Sneyders
1ab5400c0b Move JSON response body validation to middleware (#1591)
* Extract boilerplate code into Routed base classes

* Use typing_extensions for Python 3.7 Protocol support

* Use Mock instead of AsyncMock

* Extract response validation to middleware

* Refactor Request validation to match Response validation

* Factor out shared functionality

* Fix typo in TextResponseBodyValidator class name

* Fix string formatting

* Use correct schema to check nullability in response validation
2022-10-03 23:01:21 +02:00
Robbe Sneyders
181c61bfb6 Extract boilerplate code into Routed base classes (#1590)
* Extract boilerplate code into Routed base classes

* Use typing_extensions for Python 3.7 Protocol support

* Use Mock instead of AsyncMock

* Turn properties into class attributes
2022-09-26 20:33:58 +02:00
Robbe Sneyders
024666de89 Explicitly support Flask async routes (#1592) 2022-09-26 20:04:23 +02:00
Leonardo Festa
fc003ca140 Removed internal variable pass_context_arg_name (#1568)
* Removed internal variable pass_context_arg_name

* fixed issue with personalized context name in tests

* restored code from pr suggestion

* restore decorator functionality

now the function accept a pass_context_arg boolean parameter,
instead of the pass_context_arg_name value

* Fixed security test checks, now passes tests

* Removed pass_context_arg, fixed security handler

fixed security handler as suggested
removed pass_context_arg as before

* Fix context injection test

Co-authored-by: Niels Dewulf <87133686+nielsbox@users.noreply.github.com>
Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-09-22 22:53:25 +02:00
Robbe Sneyders
7ab4180111 Remove AbstractSwaggerUIAPI class (#1589) 2022-09-18 19:50:48 +02:00
Robbe Sneyders
fb071ea56f Extract JSON request body validation to middleware (#1588)
* Set up code skeleton for validation middleware

* Add more boilerplate code

* WIP

* Add ASGI JSONBodyValidator

* Revert example changes

* Remove incorrect content type test

Co-authored-by: Ruwan <ruwanlambrichts@gmail.com>
2022-09-18 10:55:16 +02:00
John Vandenberg
e4b7827b6d setup.py: Update url (#1586) 2022-09-13 18:57:42 +02:00
Robbe Sneyders
3e52c782eb Use Flask request_ctx instead of _request_ctx_stack (#1583)
* Use Flask request_ctx instead of _request_ctx_stack

* Suppress first party warnings
2022-09-07 08:35:34 +02:00
Robbe Sneyders
45468a14e6 Update json for Flask 2.3 (#1582)
* Update json for Flask 2.3

* Update docstrings
2022-09-06 22:57:13 +02:00
Yasunobu Chiba
5a71737c68 Resolve $ref referring to another $ref (#1584)
* Resolve $ref referring to another $ref.

* Fix issues detected by black.
2022-09-05 17:51:50 +02:00
Florian Greinacher
390c2e355d fix: don't interpret simple parameter as deepObject (#1570)
* fix: don't interpret simple parameter as deepObject

* Fix flake8 issues

Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-08-30 18:02:11 +02:00
Robbe Sneyders
e39c255217 Fix tests for Flask 2.2 (#1572) 2022-08-30 18:02:11 +02:00
Motti Lanzkron
5cc9b0e787 Only warn about the schema's x-body-name being deprecated if it's used. (#1554)
Co-authored-by: Motti Lanzkron <motti@microfocus.com>
2022-08-30 18:02:11 +02:00
Ricardo Piro-Rael
a2c679f5a3 Fix OpenAPI parameters containing other parameters (#1523)
* Fix OpenAPI parameters containing other parameters

OpenAPI parameters can be unspecified and sometimes contain other
parameters. The current behavior is to assume it's a bracket parameter
and nest the containing parameter within the contained parameter, which
breaks the schema as the original parameter now seems to contain a
nested object.

We can avert this by checking for the presence of a '[' in the
parameter.

* Trigger Github workflow

Co-authored-by: Ricardo Piro-Rael <rpiro-rael@ironox.com>
2022-08-30 18:02:11 +02:00
Christian Clauss
5f2aaba1fb Remove "type: ignore" by using list(dict), not dict.keys() (#1575)
In Python 3, `list(dict)` is often a better way to express `dict.keys()`

Related to #1560 -- @RobbeSneyders @nielsbox Your review, please.
2022-08-23 11:18:21 +02:00
Robbe Sneyders
67bd37fe77 Activate mypy check in pre-commit (#1560) 2022-08-23 09:02:14 +02:00
Nico Braun
64f42547dc rename method view resolver and pass class args and kwargs to it (#1564)
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
2022-07-05 00:27:05 +02:00
Robbe Sneyders
1aa0567457 Add .git-blame-ignore-revs file with black commit (#1561) 2022-06-29 23:45:20 +02:00
Robbe Sneyders
83e6e7ec75 Add black formatting (#1539) 2022-06-27 17:25:50 +02:00
Robbe Sneyders
600ed4ed94 Format files with black 2022-06-25 23:50:52 +02:00
Robbe Sneyders
29747fafc3 Add black formatting 2022-06-25 23:50:40 +02:00
Trieu Huy Vu
1d3d6c582d debug mode interaction for non-flask server (#1556)
Co-authored-by: Trieu Vu <trieu.vu@strategicdata.com.au>
2022-06-25 23:44:35 +02:00
Robbe Sneyders
cff1705c0a Add test for MethodViewResolver (#1559)
* Add test for MethodViewResolver

* Warn about ignoring of collection_endpoint_name in MethodViewResolver

* Add docstring on class_arguments in MethodViewResolver
2022-06-25 10:55:32 +02:00
Ruwann
6f9117caf4 Fix async tests (#1558)
* Use pytest-asyncio for async tests

* Fix async tests
2022-06-24 18:25:15 +02:00
Nico Braun
3c6e13c1c1 call as_view in methodresolver (#1552)
* call as_view in methodresolver

Signed-off-by: Nico Braun <rainbowstack@gmail.com>

* allow to use deprecated method view resolver

Signed-off-by: Nico Braun <rainbowstack@gmail.com>

* update method view example

Signed-off-by: Nico Braun <rainbowstack@gmail.com>

* update method view docs

Signed-off-by: Nico Braun <rainbowstack@gmail.com>

* fix pre-commit issues

Signed-off-by: Nico Braun <rainbowstack@gmail.com>
2022-06-24 17:55:11 +02:00
Robbe Sneyders
abbc8ff162 Use resolver in security middleware (#1553)
* Use resolver in security middleware

* Initialize RoutingOperation with operation object
2022-06-20 22:54:54 +02:00
jacobstanly89
b561ecfdaa Fix for bug of the function is_json_mimetype() (#1541)
* Fix for bug of the function is_json_mimetype() (#1114)

* Splitting the mimetype correctly

* Added a test for the json mimetype usecases

* Update connexion/utils.py

Co-authored-by: Ruwann <ruwan.lambrichts@ml6.eu>
2022-05-31 19:01:27 +02:00
jacobstanly89
be492f99f2 Remove built-in support for uWSGI (#1544)
* Remove check for uwsgi metrics

* Removing uwsgi metrics and corresponding test files
2022-05-24 18:40:57 +02:00
Jonas Boecquaert
6856482603 Removed jsonschema version check (#1540)
* Removed jsonschema version check

* Remove dependency on importlib-metadata

* Remove packaging dependency
2022-05-17 23:00:33 +02:00
Robbe Sneyders
e0183d3485 Clean up operation classes (#1535) 2022-05-13 15:04:51 +02:00
Robbe Sneyders
7d23a1e1ed Refactor routing into middleware-api-operation model (#1533)
* Rename MiddlewareAPI to RoutingAPI

* Refactor routing into middleware-api-operation model
2022-05-13 15:04:36 +02:00
Jonas Boecquaert
d2391a2898 Fix deprecation warning for Validator.iter_errors (#1536)
* Fix deprecation warning for iter_errors
Bump jsonschema version to at least v4

* Bump jsonschema to v4.0.1

* Provide schema as keyword arg to evolve

* Fix evolve statement
2022-05-12 18:23:42 +02:00
Robbe Sneyders
156bf79ee6 Merge V2 to main (#1518)
* Fix uri parsing for query parameter with empty brackets (#1501)

* Update tests for changed werkzeug behavior in 2.1 (#1506)

https://github.com/pallets/werkzeug/issues/2352

* Bugfix/async security check (#1512)

* Add failing tests

* Use for else construct

* openapi: remove JSON body second validation and type casting (#1170)

* openapi: remove body preprocessing

Body is already validated using jsonschema. There was also some type
casting but it was wrong: e.g. not recurring deeply into dicts and lists,
relying on existence of "type" in schema (which is not there e.g. if
oneOf is used). Anyway, the only reason why types should be casted is
converting integer values to float if the type is number. But this is in
most cases irrelevant.

Added an example, which did not work before this commit (echoed `{}`)
e.g. for
```
curl localhost:8080/api/foo -H 'content-type: application/json' -d
'{"foo": 1}'
```
but now the example works (echoes `{"foo": 1}`).

* test with oneOf in the requestBody

* remove oneof examples: superseded by tests

Co-authored-by: Pavol Vargovcik <pavol.vargovcik@kiwi.com>

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>
Co-authored-by: Pavol Vargovčík <pavol.vargovcik@gmail.com>
Co-authored-by: Pavol Vargovcik <pavol.vargovcik@kiwi.com>
2022-05-04 17:31:04 +02:00
Rafael Carício
972d1a9f9c Remove myself as maintainer (#1517) 2022-04-27 22:27:10 +02:00
Robbe Sneyders
4603e0679d Extract security to middleware (#1514)
* Extract security to middleware

* Add MissingMiddleware exception

* Extract add_auth_on_not_found in security middleware

* Add detail kwarg to exceptions

* Return JSONResponse in ExceptionMiddleware

* Type dicts in SecurityMiddleware

* Add trailing comma in setup.py

* Rework connexion context

* Improve error handling for missing security operation

* Refactor default security operation

* Revert "Return JSONResponse in ExceptionMiddleware"

This reverts commit c1004c7500d1be7e0938eea8672325cf15355359.

* Move routing context name into constant
2022-04-27 22:20:38 +02:00
Robbe Sneyders
84e33e5897 Add routing middleware (#1497)
* Add routing middleware

Factor out starlette BaseHTTPMiddleware

Fix exceptions for starlette < 0.19

Fix docstring formatting

Rename middleware/base.py to abstract.py

Rework routing middleware

* Clean up abstract API docstrings

* Move connexion context into extensions

* Allow empty middleware list
2022-04-19 22:55:20 +02:00
Robbe Sneyders
7f2931037e Add pre-commit hook (#1511) 2022-04-12 22:02:29 +02:00
Robbe Sneyders
41c19c1127 Extract Swagger UI functionality into middleware (#1496)
* Extract swagger UI functionality from AbstractAPI

* Extract Swagger UI functionality into middleware

Co-authored-by: Wojciech Paciorek <arkkors@users.noreply.github.com>

* Add additional docstrings

Co-authored-by: Wojciech Paciorek <arkkors@users.noreply.github.com>
2022-04-10 17:15:27 +02:00
Robbe Sneyders
895d3d475a Add empty connexion middleware (#1502)
* Add empty connexion middleware

* Address PR comments

* Bump minimum Flask version to 2

* Update tests for changed werkzeug behavior in 2.1

https://github.com/pallets/werkzeug/issues/2352
2022-03-31 19:24:44 +02:00
Robbe Sneyders
9d3155f1be Add Python 3.10 in favor of 3.6 (#1494)
* Add Python 3.10 in favor of 3.6

* Increase lower bound requests for Python 3.10 compatibility
2022-03-28 23:54:53 +02:00
Robbe Sneyders
ca70b16ff5 Drop aiohttp support (#1491) 2022-03-22 22:26:41 +01:00
Ruwann
f236c6883d Drop pkg_resources (#1499)
* Use pkgutil instead of pkg_resources

* Use importlib.metadata and packaging for getting and parsing version number
2.13.0
2022-03-22 19:10:15 +01:00
Ruwann
85058ed3f1 Rework required_scopes checking (#1474)
* WIP: rework required_scopes checking

* Update tests for security scopes

* Add test for oauth security scheme with multiple possible scopes

* Update security tests

* Change optional auth test to correct behaviour

* Update security documentation

* Remove TODOs

* Catch possible exceptions from failed checks in async security factory

* Add .venv/ to gitignore

* Try to raise most specific exception

* Add test for raising most specific error

* Update async security handler factory

* Fix security handler error catching

* Fix imports order
2022-03-21 21:31:26 +01:00
Andrey Abramov
87a0fed4dc Remove obsolete code from basicauth example (#1486)
* Remove obsolete code

* Remove scopes completely

* Add hinting

* Remove outdated function from docs/security

* Revert "Add hinting"

This reverts commit faeea24c28bf88eead4015feea8f4dbd750cec1c.

* Change README for examples and other review fixes
2022-03-16 20:20:44 +01:00
Ruwann
3703a46d09 Add link to Flask JSONEncoder documentation (#1484) 2022-03-12 11:01:28 +01:00
Vadim Markovtsev
28c33d88ce Save memory on unused schema strings (#1482)
Nodoby needs the schema strings vs. the parsed contents, yet those strings consume quite some memory for big specs.
2022-03-10 17:43:18 +01:00
Robbe Sneyders
d335e01fd2 Move x-body-name to requestBody level (#1475)
* issue 1452 - placement of x-body-name isnt valid OAS3 location for an extension

* issue 1452 - placement of x-body-name isnt valid OAS3 location for an extension

* add vim temp files to ignore

* issue 1452 - placement of x-body-name isnt valid OAS3 location for an extension - now at requestBody after review comment

* issue 1452 - placement of x-body-name isnt valid OAS3 location for an extension - now at operation after review

* removed unused import

* Move x-body-name into requestBody

* Update tests/fixtures/simple/openapi.yaml

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>

* Update README.rst

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>

* Update docs/request.rst

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>

* Update README.rst

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>

* Add deprecationwarning for x-body-name position

Co-authored-by: John Lonergan <john.lonergan@gmail.com>
Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>
2022-03-07 18:09:21 +01:00
Jonas Boecquaert
37f729ceb5 upgrade pyYAML supported versions in setup.py (#1478)
Fix test using pyYAML
2022-03-07 18:08:38 +01:00
Nicolas Noirbent
a1dddf62d4 lifecycle: add cookies attribute to ConnexionRequest (#1168) (#1209)
Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-02-23 22:45:34 +01:00
Pavol Vargovčík
a6717c3bbf Enforcedefaults aiohttp (#1163)
* cache ConnexionRequest.json

* add openapi3 enforcedefaults_aiohttp example

Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-02-23 22:31:41 +01:00