Commit Graph

56 Commits

Author SHA1 Message Date
Robbe Sneyders
17fcad0c30 Update response handling documenation (#1742)
Contributes to #1531
2023-10-16 23:51:21 +02:00
Heinz-Alexander Fuetterer
8459c614fd chore: fix typos (#1740)
Changes proposed in this pull request:

 - fix some minor typos
2023-10-12 23:30:23 +02:00
Robbe Sneyders
b28cf09a0c Enable response mimetype validation for non-error responses (#1654)
Addresses a todo left in the code.

We only validate the mimetype if the spec defines which mime-types it
produces, and only for non-error responses.
2023-03-02 21:59:50 +01:00
Robbe Sneyders
969c1460e6 Enforce required RequestBody (#1652)
Fixes #878 
Fixes #1317
2023-02-25 16:40:11 +01:00
Robbe Sneyders
c1ff7641f6 Change deprecated httpx data usage in tests to content 2023-02-16 09:35:35 +01:00
Robbe Sneyders
816707d469 Align default content type between WSGI and ASGI 2023-02-16 09:35:35 +01:00
Robbe Sneyders
1ee9c25aab Feature/request context (#1639)
This PR fixes 'outside of Flask context' errors in our test suite and
contains the following changes:

- `Connexion.request` is now a Connexion `ASGIRequest` instead of a
Flask `request`
- All other tests with a Flask dependency have been updated or split

Failing tests are down to 11.
2023-02-16 09:18:48 +01:00
Robbe Sneyders
65bc8b9138 Leverage Starlette TestClient for both FlaskApp and AsyncApp tests 2023-02-15 00:48:40 +01:00
Robbe Sneyders
515e324c80 Make tests framework agnostic 2023-02-13 20:01:25 +01:00
Robbe Sneyders
edb0381af3 Implement user facing interface for ConnexionMiddleware (#1621)
This PR adds an interface for the ConnexionMiddleware, similar to the
interface of the Connexion Apps.

The Connexion Apps are now a simple wrapper around the
ConnexionMiddleware and framework app, delegating the work to the
middleware. This enables a similar interface and behavior for users when
using either the middleware or apps.

The arguments are repeated everywhere there is a user interface, but are
parsed in a central place. Repeating the arguments is not DRY, but
needed to provide users with IDE autocomplete, typing, etc. They are
parsed in a single `_Options` class, which also provides a mechanism to
set default options on an App level, and override them on the more
granular API level.

This makes the long list of provided parameters a lot more manageable,
so I would like to use it for the `Jsonifier` as well, and re-add the
`debug` and `extra_files` arguments which I have dropped in previous
PRs. I'll submit a separate PR for this.

I renamed the `options` parameter to `swagger_ui_options` since it only
contains swagger UI options. This is a breaking change though, and we'll
need to highlight this upon release.

We still have quite a lot of `App`, `MiddlewareApp`, and abstract
classes. It would be great if we could find a way to reduce those
further, or at least find better naming to make it more clear what each
one does 🙂 .

Finally, I added examples on how the middleware can be used with third
party frameworks under `examples/frameworks`. Currently there's an
example for Starlette and Quart, but this should be easy to extend. They
also show how the `ASGIDecorator` and `StarletteDecorator` from my
previous PR can be used.
2023-01-26 14:40:29 +01:00
Robbe Sneyders
f064fd04b7 Switch to own maintained version of swagger-ui (#1619)
Fixes #1412
Fixes #1516 

Since [swagger-ui-bundle](https://github.com/dtkav/swagger_ui_bundle) is
no longer maintained, I forked it under the spec-first organization as
[py-swagger-ui](https://github.com/spec-first/py-swagger-ui). This PR
updates connexion to use it instead.
2023-01-09 18:57:15 +01:00
Robbe Sneyders
6fdb807567 Extract response parsing into decorator 2023-01-03 22:29:21 +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
2581a7e4c4 Move parameter validation to middleware 2022-11-14 23:15:31 +01: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
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
Robbe Sneyders
600ed4ed94 Format files with black 2022-06-25 23:50:52 +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
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
Chris HORLER
d375ea8dac Don't validate streamed responses (#1259)
* rework PR #467 - don't attempt to validate streamed responses

* Add is_streamed property to ConnexionResponse

* Adhere to response.direct_passthrough

* Add test for file response validation

* Add warning about skipping validation for streamed response

Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2022-02-19 17:18:45 +01:00
Christian Clauss
1012721d2d Upgrade isort==5.9.1 (#1388)
* Upgrade isort==5.9.1

* isort --thirdparty connexion,aiohttp ./tests

* isort --thirdparty aiohttp,connexion --check-only --diff .

* cd tests before running isort
2021-07-07 12:43:36 +02: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
Daniel Grossmann-Kavanagh
3fecd3e735 fix nested additionalProperties (#1138) 2020-01-29 09:24:48 +01:00
Fabian Wollert
e62ac5958c match all but whitespaces inside object keys (#1130)
* add a test

* match all but whitespaces inside object keys

* exclude square brackets

* make one char possible as key

* allow any character

* fix everything
2020-01-21 17:48:53 +01:00
Daniel Grossmann-Kavanagh
154d367a9e use yaml.BaseLoader in test to remove warning 2019-12-11 18:16:15 -08: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
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
João Santos
1bda0659d5 Fix broken tests (#933)
* Remove extra space in error.

* Fix tests due to new behaviour of external dependencies
2019-05-05 19:38:42 +02:00
Christoph Ziebuhr
cca92c0777 Fix passing empty object body (#815)
Having a json request with an empty object body `{}` resulted in having `None` passed as body argument.
2018-12-18 08:27:10 +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
Pavel Melnikov
6675ccc800 Fix body validator different error codes for bad Content-Types. (#629)
Fixes #628 .

 - Added a test for this bug.
 - Fixed it by checking for non-empty HTTP POST payload by considering request.body, request.form and request.files (only request.body was checked)
2018-08-14 13:22:03 +02:00
Pavel Melnikov
0c352cd4da Correct validator response on bad JSON (#610)
* report 400 Bad Request if validation fails to parse JSON while Content-Type is json.
2018-07-10 09:43:44 +02:00
John Krukoff
94f64b80e1 Allow http.HTTPStatus enums as response status codes. (#504)
* Allow http.HTTPStatus enums as response status codes.

Python 3.5 introduced a new enumeration "http.HTTPStatus" for
representing HTTP response status codes. The default response validation
introduced in connexion 1.1.12 highlighted the fact that connexion does
not natively support this type and was previously silently ignoring
non-integer status code representations.

This modifies the response validation code to extract the value when
given an enum instead of an int. Somewhat hacky test code is added to
check for enum support on python versions that include
"http.HTTPStatus".

* [master]: Restructure tests from PR comments.

* [master]: Revert to exception based version checking.

This reverts to exception based python version checking for both tests,
due to the suggested unittest skipping alternative not being supported
in all python versions.

"unittest.case.SkipTest: Not supported in this version" is the error
reported.

* [master]: Move enum handling deeper into the stack.

* [master]: Respond to yet more PR comments.
2017-10-05 09:08:59 +02:00
Fiete Gruenter
07ce38b484 Move import to top level. 2017-08-15 09:09:12 +02:00
Fiete Gruenter
ee72325345 Implement hacky workaround for passing environ to test_client.open() for no-content-type-test since old flask<=0.12.2 does not support it. 2017-08-04 09:30:25 +02:00
Fiete Gruenter
bf66cc726d Add a test that posts a requests without sending Content-Type in the header. 2017-08-03 12:43:48 +02:00
Tony Tung
6668835420 Validate responses against the default response field if the code is not found. (#487) 2017-07-20 22:58:22 +02:00
Kyle Cacciatore
1f34e3565b 449 path format (#450)
* added test for path formatted parameters

* re-added removed test, as it would generate valid flask route
2017-05-10 22:04:48 +02: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
Landon
6f567ee4de Fix returning flask Response objects in a tuple (#425)
* Fix returning Response objects in tuple with status code and/or headers

* Use flasks code for dealing with tuples instead of my own

* Unit tests for returning flask reponse in tuple

* fix test, should be a dict, not a set

* Properly sort imports
2017-04-04 20:11:03 +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
Leena Bhegade
f12ff8e3f3 Add Test Cases for unicode string
Add test cases
2017-02-11 16:48:40 +00:00
Leena Bhegade
f7b3d9a0bb add parameter to decode 2017-02-08 23:48:04 +00:00
Leena Bhegade
c1020bf0f6 Fix tests 2017-02-08 21:31:35 +00:00
Jeffrey Slort
0e9a78ffb1 removed "weird+json" test case 2017-02-08 19:49:51 +01:00
Jeffrey Slort
03e1405db4 Improved error messages when using an Invalid Content-Type header for the posted data
Added tests for content-type check
2017-02-08 19:49:51 +01:00
Rafael Caricio
3b5bb13276 Refactor code to fix confusion with returned values 2016-12-10 19:54:27 +01:00
Elisey Zanko
1fb776ebbd Errors fixed 2016-09-29 11:15:25 +05:00
Elisey Zanko
58da2b308d Fix a string issue 2016-09-29 10:35:58 +05:00