Skip to content

[REQ] Python FastAPI Server Code Generator Library Mode #21079

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

Open
AdityaMayukhSom opened this issue Apr 12, 2025 · 1 comment · May be fixed by #21080
Open

[REQ] Python FastAPI Server Code Generator Library Mode #21079

AdityaMayukhSom opened this issue Apr 12, 2025 · 1 comment · May be fixed by #21080

Comments

@AdityaMayukhSom
Copy link

AdityaMayukhSom commented Apr 12, 2025

Is your feature request related to a problem? Please describe.

Currently the server stub generated by OpenAPI Generator for Python FastAPI generator only provides support for generating complete server where we need to modify the generated code. The Spring or ASP.NET server generators have options such as delegatePattern or isLibrary in the configuration file which allows us to generate only the interfaces which can be implemented through a concrete class, which lets us easily update the OpenAPI schema and generate new interfaces without modifying existing code by hand.

Describe the solution you'd like

An option to generate the models and APIs as a library which can be published to a package repository and can be consumed by the implementing application.

Describe alternatives you've considered

We are currently updating the generated code through a bash script but that feels like a monkey patching rather than a solution itself as the script depends on the structure of the generated file, which too will change when changing the OpenAPI schema. Implementing a robust solution on the generator itself should be the way to go.

cc: @multani @fa0311 @krjakbrjak @tomplus @cbornet

@ampedandwired
Copy link

I think this is already possible with the FastAPI generator? For me at least it generates a default_api.py file with the API endpoints and this delegates to a default_api_base.py which just has stubs that you subclass and override. I've been putting this implementation subclass in a separate project from the generated code with no problems. As long as your subclass is imported somewhere when the server starts up the FastAPI implementation should find it and invoke it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants