-
-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that ConnexionMiddleware might require to specifiy routes explicitly #1886
Comments
Thanks for the report @abstractbyte. 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 That being said, it's indeed not straightforward to host static files currently. For now, you should be able to do it like this: app = AsyncApp(...)
app._middleware_app.router.mount("/", app=StaticFiles(directory="static", html=True), name="static") We should provide a |
Thanks for the fast reply, @RobbeSneyders! The proposed workaround via |
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: