Commit Graph

504 Commits

Author SHA1 Message Date
Ruwann
3fa9f3bf3d Bugfix/basepath (#1716)
Working towards #1709 

I think we're almost there, some tests I did are now working properly.

Would love to get some feedback/ideas on the implementation and the
tests :)
2023-07-01 11:08:21 +02:00
Robbe Sneyders
15fe2eda8f Fix add_middleware enum comparison (#1698)
Fixes #1697

Because of a wrong comparison against the position `Enum`, middleware
was not actually being added to the stack via `add_middleware`. This PR
fixes this, adds a warning when the middleware position cannot be found,
and adds a test.
2023-04-24 18:09:57 +02:00
Robbe Sneyders
c3e2e57422 Unpack error handler when registering on middleware (#1695)
Registering error handlers on the async app leads to an error on 3.0.0a5
because the error handlers are not unpacked correctly when being
registered internally.
2023-04-24 16:47:36 +02:00
Robbe Sneyders
1beb0539f5 Inspect middleware parameters before passing in lifespan (#1686)
Fixes #1682 

This PR inspects the parameters of a Middleware class before passing in
the `lifespan` keyword argument. I was doubting to check the class
instead (`isinstance(LifespanMiddleware)`), but that's less flexible if
users want to write custom middleware to handle the lifespan.
2023-04-22 22:01:30 +02:00
Ruwann
e0550e6a90 Add test for security_map argument (#1691)
Follow-up of #1671 

Let me know if there is an easier way doing the test instead of the
current "custom" basic auth.
2023-04-22 21:42:55 +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
Ruwann
d9b699bf65 Add tests for strict validation in combination with api key in query (#1681)
Continues on the work of #1077 by moving the test fixtures into the
`secure_endpoint` fixture and adding a test for it in
`test_secure_api.py`.

The test will check whether an api key in the query will not lead to an
error when `strict_validation` is enabled.
2023-04-20 19:59:23 +02:00
Ruwann
5b4beeb2ea Make security pluggable (#1671)
Make security pluggable

- [x] Solution for standard security handlers: `security_deny`,
`security_passthrough`, `verify_none`
- [x] HTTP security handlers & overlap with basic from swagger 2
- [x] Do we need a separate handler for each `oauth2` flow?
2023-04-08 18:19:26 +02:00
Robbe Sneyders
55e376f816 Fix stream replay in validators (#1678)
The current implementation of replaying the stream will always replay
the first message. This PR fixes this by progressing through the
messages with each call.
2023-03-30 22:12:56 +02:00
Robbe Sneyders
79c0852c93 Add lifespan middleware (#1676)
This PR adds a new middleware to handle lifespan events.

I added this as a separate middleware so it is encapsulated and aligned
for both the `FlaskApp` and `AsyncApp`. It leverages a Starlette
`Router` to register and call the lifespan handler.
2023-03-23 19:11:43 +01:00
Robbe Sneyders
8a85a4fe01 Pass through lifespan events (#1673)
Fixes #1672

Lifespan events were being intercepted by the swagger UI middleware. We
should let them pass through.
2023-03-13 23:34:00 +01:00
Robbe Sneyders
4383c5363f Delay import error for optional flask depencendy (#1668)
This PR delays import errors for the optional Flask dependency, so you
can use the AsyncApp without Flask installed.

This issue is hidden in our tests since we install all extras. To
prevent this, we need to address
https://github.com/spec-first/connexion/issues/1389.
2023-03-06 21:45:56 +01:00
Robbe Sneyders
4f6ddfb0a0 Add jsonifier as argument to app / api (#1656)
This PR adds a `jsonifier` argument to the app and api to align it with
other customization options. We also no longer pass it via the operation
object, which brings us closer to operations as data class only.
2023-03-02 22:00:47 +01:00
Robbe Sneyders
1cb5f83181 Don't return 400 when read-only property is provided (#1655)
Fixes #942 

No longer return 400 if a read-only property is provided, as discussed
in the issue. We still raise an error if write-only properties are
included in the response and response validation is enabled.

I also changed how read-/write-only works in combination with
`required`. Previously, `required` would not be overwritten by
read-/write-only. Now we just follow the spec to the letter:
- required and read-only: must be included but must be ignored by the
server
- required and write-only: impossible to achieve, but I also don't see
how this combination could make sense
- read-only: may be included but must be ignored by server
- write-only: must not be included by server
2023-03-02 22:00:28 +01: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
3e733df181 Create AbstractRequestBodyValidator class 2023-03-01 23:54:01 +01:00
Robbe Sneyders
969c1460e6 Enforce required RequestBody (#1652)
Fixes #878 
Fixes #1317
2023-02-25 16:40:11 +01:00
Robbe Sneyders
ec5dd278d0 Re-add attributes to OAuthScopeProblem 2023-02-23 00:13:13 +01:00
Robbe Sneyders
69f117ce52 Drop extended ResolverError traceback 2023-02-23 00:13:13 +01:00
Robbe Sneyders
700b071c45 Clean up errors and fix hierarchy 2023-02-23 00:12:23 +01:00
Robbe Sneyders
2f9a461981 Add support for relative refs in spec (#1648)
Fixes #254 
Fixes #967 

This PR fixes the very long-standing issue of being able to handle
relative references, which allows users to split their specification
into multiple files.
2023-02-22 23:43:27 +01:00
Robbe Sneyders
05c32d5907 Re-add tests for multiple and mixed file uploads (#1642)
Fixes #992

This PR re-adds tests that were removed when dropping aiohttp, as raised
in
https://github.com/spec-first/connexion/issues/1395#issuecomment-1175591898.
2023-02-21 21:48:20 +01:00
Robbe Sneyders
5ecbf00f29 Add test for multiple float path parameters 2023-02-18 01:15:24 +01:00
Robbe Sneyders
a8a7e514f4 Re-add tests for multiple and mixed file uploads 2023-02-17 17:46:10 +01:00
Robbe Sneyders
19bf15e7dd Skip tests relying on AsyncMock for Python3.7 2023-02-16 10:46:50 +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
25e0b15465 Update some test endpoints to work with different fixture values 2023-02-16 09:35:35 +01:00
Robbe Sneyders
03d806786f Add error handlers for AsyncApp (#1640)
This PR adds all the needed error handling for the AsyncApp.

Only 5 errors remaining.
2023-02-16 09:19:04 +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
4f56b11c29 Define request interface and align WSGI and ASGI (#1636)
This PR defines a request interface and aligns the `ASGIRequest` with
the `WSGIRequest` class. This brings down the test errors from 62 to 25.
2023-02-16 09:16:40 +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
642a5f2dc3 Refactor tests (#1631)
This PR refactors our tests to prepare the activation of our tests for
our AsyncApp.

The separate commits are atomic, which can be useful for reviewing.

---------

Co-authored-by: Ruwann <ruwanlambrichts@gmail.com>
2023-02-12 22:25:08 +01:00
Robbe Sneyders
15e985e864 Introduce poetry (#1628) 2023-02-07 20:17:38 +01:00
Robbe Sneyders
022bb8f34a Coerce types only in uri parser (#1627)
This PR moves all type coercing into the URI parsers and makes sure it's
only done once for each code path.
2023-01-30 08:49:49 +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
2bf18f6629 Expose additional context (#1620)
This PR contains 2 main changes:
- Expose additional context. We now expose the scope, operation,
connexion context, and receive channel as context aware globals. This
makes them available to the decorators independent of the framework in
between. The user will also be able to use these.
I also implemented a `TestContext` class which can be used to populate
the context during testing. It's minimal, but can be extended towards
the future.
- Rename the decorators to be framework specific. This is part of a
bigger change for which I'll submit a follow up PR. I was working on
this first when it became clear that the context would need to be
extended, which is why this is already included.
2023-01-13 22:01:08 +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
de3b6f6895 Extract framework specific functionality into framework module & class 2023-01-03 22:38:33 +01:00
Robbe Sneyders
6fdb807567 Extract response parsing into decorator 2023-01-03 22:29:21 +01:00
Robbe Sneyders
2c7f83dd4a Refactor parameter decorator into sync and async version 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
db6ebecc8a Drop deprecated response serialization 2022-12-23 11:15:10 +01:00
Robbe Sneyders
7acbad0691 Move parameter decorator related methods out of operation classes 2022-12-23 11:15:10 +01:00
Robbe Sneyders
825c682086 Remove strict_validation and validate_responses from API and Operation classes 2022-11-14 23:31:09 +01:00
Robbe Sneyders
2581a7e4c4 Move parameter validation to middleware 2022-11-14 23:15:31 +01:00
Robbe Sneyders
9d7258c25d Create MediaTypeDict class for range matching (#1603) 2022-11-04 11:07:03 +01:00
Robbe Sneyders
b8bdcc999d Move Swagger 2 form validation to middleware (#1599)
* Move Swagger 2 form validation to middleware

* Add unit test for form transformation
2022-11-04 11:07:03 +01:00