Commit Graph

1443 Commits

Author SHA1 Message Date
Robbe Sneyders
c1ef3f4e3a Add gunicorn with uvicorn workers to docs (#1766)
Fixes #1755
2023-10-31 20:08:17 +01:00
Robbe Sneyders
cbeac6f2c1 Update security docs (#1764)
Contributes to #1531
2023-10-31 20:08:04 +01:00
Robbe Sneyders
17aa31a7ab Remove cookbook docs and sort index better (#1765)
Contributes to #1531
2023-10-30 20:54:59 +01:00
Robbe Sneyders
99c7a13b53 Update cli docs (#1763)
Contributes towards #1531
3.0.0a8
2023-10-29 14:23:21 +01:00
Robbe Sneyders
4556779343 Fix CLI and drop click dependency (#1762) 2023-10-29 11:34:55 +01:00
Robbe Sneyders
d8ceb52822 Update Exceptions documentations (#1758)
Contributes towards #1531
2023-10-29 09:58:05 +01:00
Robbe Sneyders
452ffc7676 Add testing documentation (#1760)
Contributes towards https://github.com/spec-first/connexion/issues/1531
2023-10-29 09:40:43 +01:00
Robbe Sneyders
77a63a07ef Add lifespan documentation (#1759)
Contributes towards https://github.com/spec-first/connexion/issues/1531
2023-10-29 09:40:16 +01:00
Robbe Sneyders
b9ba13cde5 Centralize error handling in ExceptionMiddleware (#1754)
I was writing the documentation on exception handling, and I noticed
that it was very hard to explain our current behavior.

Error handlers can be registered either on the internal Flask app (not
the Starlette one) or on the Connexion app, which leads to some
undefined (actually just really hard to explain) behavior. Eg.
- Registering error handlers on a status code would capture
`starlette.HTTPException` errors on the Connexion app, and
`werkzeug.HTTPException` errors on the Flask App, which means that
registering an error handler on a status code doesn't catch all the
errors with that status code.
- Flask does some default error handling which leads to some exceptions
never reaching the error handlers registered on the Connexion app.

So I made the following changes:
- Replaced the default error handlers we registered on the Flask app
with a default handler on the `ExceptionMiddleware` that takes into
account other handlers registered on status codes.
- Configured Flask to propagate exceptions instead of catching them.
- Abstracted away the Starlette `Request` and `Response` types, so users
can and must now use `ConnexionRequest`
  and `ConnexionResponse` types in error handlers.
- Renamed the `ASGIRequest` class to `ConnexionRequest` since it is the
only Request class part of the high level
  Connexion interface.

We could also rename `ConnexionRequest` and `ConnexionResponse` to just
`Request` and `Response`. Wdyt?
2023-10-29 09:37:54 +01:00
Robbe Sneyders
1b72019b1b Create FUNDING.yml (#1753)
Add Github Sponsors to side panel.

Fixes #1573
2023-10-23 23:11:18 +02:00
Robbe Sneyders
a210917b46 Drop Python 3.7 in favor of 3.11 and 3.12 (#1752)
Python 3.7 is end of life. We should support the newer versions instead.

I also changed tox to only run against the minimum dependency versions
on the lowest Python version, since this should lead to the lowest
versions over all Python versions, and hopefully helps speed up our
pipelines :)
2023-10-23 23:11:06 +02:00
Ruwann
79fd9edfb8 Feature/get delete body (#1712)
Fixes #1689 

Changes proposed in this pull request:

 - Pass through request body in case of `GET` and `DELETE` requests

---------

Co-authored-by: Robbe Sneyders <robbe.sneyders@gmail.com>
2023-10-23 22:24:47 +02:00
Robbe Sneyders
7eb43f133d Add context documentation (#1747)
Contributes towards #1531 

Fixes #937
2023-10-22 22:51:18 +02:00
Robbe Sneyders
3ef9a76590 Remove debug argument from example (#1749)
Small fix
2023-10-22 22:41:21 +02:00
Robbe Sneyders
655ea430ed Add validation documentation (#1743)
Contributes to #1531
2023-10-17 23:57:06 +02:00
Robbe Sneyders
41c525c52c Support multiple APIs with same base path (#1736)
Fixes #1542 
Fixes #1724 

Cherry-picked some commits from #1598.

---------

Co-authored-by: Leonardo Festa <4375330+leonardofesta@users.noreply.github.com>
2023-10-17 23:40:13 +02:00
Robbe Sneyders
17fcad0c30 Update response handling documenation (#1742)
Contributes to #1531
2023-10-16 23:51:21 +02:00
Robbe Sneyders
b102ad9f6c Update request handling documentation (#1741)
Contributes to #1531
2023-10-15 12:59:58 +02: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
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
abc1da750e Update routing documentation (#1738)
Works towards #1531 

Some parts of the old outing docs will need to be included on the
`parameters` and `swagger-ui` pages which we still need to add.
2023-10-12 01:37:45 +02:00
Robbe Sneyders
382fbca145 Make middleware_app property private (#1737)
So it doesn't show up in documentation.
2023-10-07 01:05:23 +02:00
Robbe Sneyders
649c7ec75e Bump starlette (#1734)
Fixes https://github.com/spec-first/connexion/issues/1728
2023-10-06 15:46:03 +02:00
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 :)
3.0.0a7
2023-07-01 11:08:21 +02:00
Julien Schuermans
5e9447c3fd Fix typo (#1713)
Fixes a translation error in the `AbstractApp.add_api` docstring
2023-06-18 17:38:09 +02:00
Ruwann
59a09c7c7f Use repr for error logging (#1711)
Follow-up on #1708
([comment](https://github.com/spec-first/connexion/pull/1708#issuecomment-1581196226))

As mentioned there, there is a `__repr__` but not a `__str__`, leading
to an empty log message (for HTTPExceptions).

An example when running the dev server (previously the first line would
just be an empty line):
```
HTTPException(status_code=404, detail='Not Found')
INFO:     127.0.0.1:33538 - "GET /swaggers/ui/ HTTP/1.1" 404 Not Found
```

However, I would also be fine with just removing the logging here as
`HTTPException`s can be part of the normal flow, without indicating an
actual application error (case in point: raising a `Not Found`
exception)
2023-06-13 23:00:33 +02:00
Robbe Sneyders
55f3c59044 Deepcopy only headers in validator (#1710)
Fixes the failing pipeline.

I don't understand the underlying issue completely, but It's related to
[this
code](https://github.com/encode/starlette/compare/0.27.0...0.28.0#diff-87bccafe494bc79680d9d8f57ea797733354b076aa411c0e2bd63f5b4039f71fR51-R54)
added in starlette 0.28. This makes the scope unpicklable in some cases,
leading to an error when trying to deepcopy it.

I replaced the deepcopy of the whole scope with just a deepcopy of the
headers, since this is the only part we're chaning.
2023-06-11 11:01:52 +02:00
Robbe Sneyders
fcd4e66ec6 Add middleware documentation (#1706)
Contributes towards https://github.com/spec-first/connexion/issues/1531

This PR adds a documentation page on middleware.
2023-06-08 00:15:28 +02:00
Ruwann
a34da315db Add traceback info to common error handler (#1708)
When an internal server error
occurs, the logged error is not really useful for the user.
For example, a `KeyError` will only print the missing key instead of the
full stacktrace and error.

Adding it to the common error handler as that one is meant to catch all
remaining errors, `HTTPException`s are handled by another error handler.
2023-06-01 11:06:59 +02:00
Robbe Sneyders
0c0c517cf6 Update quickstart documentation (#1701)
Contributes towards #1531

Updates the quickstart documentation for v3. I removed some more
detailed stuff that I don't think belongs on this page.
2023-05-09 22:22:52 +02:00
Robbe Sneyders
ab54842bb2 Improve and fix docs index page (#1700)
Contributes towards #1531 

Improves the high level explanation of Connexion and fixes broken links
on the index page.
2023-05-09 21:11:49 +02:00
Marcin Lulek
fc1f0df05d Move from caret to inequality requirements (#1704)
Fixes # .
I want to use connexion with newer Starlette


Changes proposed in this pull request:

 - Loosen requirements on starlette version

---------

Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
2023-05-09 20:24:29 +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.
3.0.0a6
2023-04-24 18:09:57 +02:00
Ruwann
128a8e073f Use logger error instead of exception (#1692)
Fixes the `Nonetype: None` issue that shows up in the logging.

It is caused by using `logging.exception` while not in an exception
handler.

I don't know whether including the full traceback makes sense in the
logging, but that could also be possible by adding `exc_info=exc`
2023-04-24 16:48:36 +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
Ruwann
97e8a8e7f8 Remove context keyword from security handlers (#1690)
Follow-up on #1671 

Since the request context is available globally, we can remove this
complexity from the security handlers ("There should be one-- and
preferably only one --obvious way to do it.")

In addition it seems like there weren't any tests for the context in
security handler functions, and I don't think there's a lot of value in
a test for checking the context in security functions specifically.
3.0.0a5
2023-04-22 22:03:01 +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.
3.0.0a4
2023-03-30 22:12:56 +02:00
Andrew Chong
8cebebc3a4 Fix examples links in security doc page (#1677)
Contributes to #1531 

The links in security doc were pointing at an old repo and folders.
These links could be changed down the road to use relative paths since
they point to the repo internally.
3.0.0a3
2023-03-24 10:55:21 +01: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
cd64611747 Add explicit asgiref dependency (#1667)
We use `asgiref` as a direct dependency

ab94e2aaa6/connexion/decorators/main.py (L7)

So should add it explicitly as well.

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.
3.0.0a2
2023-03-06 22:19:13 +01:00
Robbe Sneyders
e9b28d486e Update Operations to act as wrapper of wrapped view function (#1669)
Fixes #1666 

The `FlaskOperation` and `AsyncOperation` classes act as decorators for
their wrapped view functions, so their metadata should reflect this,
similar to what `functools.wraps` does.
2023-03-06 21:47:36 +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
291d9b0139 Update docs index page (#1665)
Contributes to https://github.com/spec-first/connexion/issues/1531

This PR updates the index page for Connexion 3. We'll need to update the
content table as we go.
2023-03-06 21:44:56 +01:00