You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From reading the documentation, I was under the assumption that API paths defined in the OpenAPI specification don't need to be registered explicitly.
Using Starlette with the ConnexionMiddleware however, I seem to have to explicitly add Routes to each API endpoint, otherwise, the server returns 404. This is not the case for the Swagger UI, which is served correctly without being registered explicitly.
It does not seem to be caused by Connexion not finding / resolving the python functions correctly: If I don't provide a correct operationId or configure a Resolver, Connexion would warn Failed to add operation for GET /api/v1/example and raise a ResolverError when trying to access the API.
Expected behaviour
From the documentation and the fact that the Swagger UI is served automatically, I would expect the following code to return "Hello World!" when sending a GET request to /api/v1/example (OpenAPI spec can be found under "Steps to reproduce"):
Remove the routes=[...] argument and try to access the example endpoint.
Additional info:
I'm new to ASGI, Starlette and Connexion, please excuse any obvious things I missed.
I am only using Starlette in the first place to host a static HTML file and some resources next to the API, because I couldn't get that working with the AsyncApp. If this is possible, feel free to point me in the right direction.
Agree that we can add a note on this in the documentation.
This way of using Connexion is mostly meant if you already have a Starlette application and want to start leveraging Connexion though. If you're starting from scratch, the AsyncApp is the recommended way to go.
That being said, it's indeed not straightforward to host static files currently. For now, you should be able to do it like this:
Thanks for the fast reply, @RobbeSneyders! The proposed workaround via _middleware_app works well.
When I'm done with my project I'll try to look more into Connexion and maybe I'll be able to open a PR.
Description
From reading the documentation, I was under the assumption that API paths defined in the OpenAPI specification don't need to be registered explicitly.
Using Starlette with the
ConnexionMiddleware
however, I seem to have to explicitly addRoute
s to each API endpoint, otherwise, the server returns 404. This is not the case for the Swagger UI, which is served correctly without being registered explicitly.It does not seem to be caused by Connexion not finding / resolving the python functions correctly: If I don't provide a correct
operationId
or configure a Resolver, Connexion would warnFailed to add operation for GET /api/v1/example
and raise aResolverError
when trying to access the API.Expected behaviour
From the documentation and the fact that the Swagger UI is served automatically, I would expect the following code to return "Hello World!" when sending a GET request to
/api/v1/example
(OpenAPI spec can be found under "Steps to reproduce"):Actual behaviour
I need to explicitly add the route of the endpoint:
If this is expected behavior, maybe that necessity could be mentioned in the documentation.
Steps to reproduce
Install
connexion[swagger-ui]
,uvicorn
andstarlette
and runuvicorn app:app
with the following files:api/openapi.yaml
Full
app.py
Remove the
routes=[...]
argument and try to access the example endpoint.Additional info:
I'm new to ASGI, Starlette and Connexion, please excuse any obvious things I missed.
I am only using Starlette in the first place to host a static HTML file and some resources next to the API, because I couldn't get that working with the
AsyncApp
. If this is possible, feel free to point me in the right direction.My current setup would look something like this:
Output of the commands:
python --version
Python 3.11.6
pip show connexion | grep "^Version\:"
Version: 3.0.6
The text was updated successfully, but these errors were encountered: