-
|
Description Is it possible to use a schema first approach with FastAPI? We design the APIs(using OpenAPI spec) for a service first and we expect FastAPI to handle the incoming requests based on it. Additional context Checkout a similar f/w: https://github.com/zalando/connexion |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
|
It's actually the exact opposite that happens, you write your endpoints and the schema is created for you In theory nothing prevents you from deriving your endpoints coding from it, there's just no automation benefit which would transform the schema into endpoints. Well to be very clear I'm not aware of such a thing should it exist. |
Beta Was this translation helpful? Give feedback.
-
|
@jugaadi I think it would be interesting to have a server stubs generator for FastAPI. Currently, I don't think this exists, but I think it would be pretty easy to throw together a set of templates for this that would be compatible with You can take a look at https://github.com/dmontagu/fastapi_client for an example of what this looks like when generating a client; tweaking it to generate a server shouldn't be too hard beyond modifying the templates and language passed to the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @dmontagu and @euri10 ! 👏 🙇 Thanks for reporting back and closing the issue @jugaadi 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I was just looking for something along the same lines and it looks like there is an attempt here: |
Beta Was this translation helpful? Give feedback.
-
|
For spec-first, connexion do the job: https://github.com/spec-first/connexion , however, it's not faspi :( https://pypi.org/project/fastapi-code-generator/ do the job, but i don't see the point to automatize this using fastapi. |
Beta Was this translation helpful? Give feedback.
-
|
🙌 Inspired by this Issue, my team built this. A schema-first approach to FastAPI that generates server interfaces for you to implement. Fern: https://github.com/fern-api/fern/ |
Beta Was this translation helpful? Give feedback.
-
|
Based on experimentation I have quite some doubts about code-generators (inflexible, cumbersome integration in workflow, generated code "trustworthy"?, ...). As a consequence I'm kind of old-school when it comes to back-end implementation and prefer implement it myself (using AI/IDE to prevent from boring boilerplate copy&paste kind of operations of course). If there would be some CI integration for FastAPI which checks the "implemented openapi spec" against a "design first openapi spec" I'd be more than happy. In addition this would prevent people from moving towards an openapi spec first alternative framework. @tiangolo What do you think about this idea? |
Beta Was this translation helpful? Give feedback.
@jugaadi I think it would be interesting to have a server stubs generator for FastAPI. Currently, I don't think this exists, but I think it would be pretty easy to throw together a set of templates for this that would be compatible with
openapi-generator, which has server stubs generation for other python frameworks.You can take a look at https://github.com/dmontagu/fastapi_client for an example of what this looks like when generating a client; tweaking it to generate a server shouldn't be too hard beyond modifying the templates and language passed to the
openapi-generatorcall.