How to use swagger 2 in FastAPI #7321
-
We need to use swagger2 in the FastAPI project, can we use Swagger 2 to replace the original OpenAPI |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
I've had the same issue and i fixed it by using https://github.com/LucyBot-Inc/api-spec-converter I did have to do some manual changes after that (some security stuff and empty body that gcp doesn't like) but that will be different for everyone I can give a more concrete example later if you wish |
Beta Was this translation helpful? Give feedback.
-
Can you provide an example |
Beta Was this translation helpful? Give feedback.
-
First i make the app fill the api data and create an endpoint which just returns a json of the schema
Then i have a function that goes to that url takes the schema and writes to a yaml file (json is also possible i believe)
Then i call the spec-converter as a CLI (requires a node env with npm install api-spec-converter)
After which you should have a version 2 swagger in the openapi.yaml :)
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the help here @ArcLightSlavik ! 👏 🙇 If that solves the original problem, then you can close this issue @somta ✔️ |
Beta Was this translation helpful? Give feedback.
-
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
-
I was trying to deploy a fastapi application behind Google API Gateway and ran into this issue. Instead of having to manually convert the spec everytime, I thought of writing an extension for fastapi which will generate the swagger2.0 spec. Its still work in progress, but does generate the basic spec for paths, params, etc. https://pypi.org/project/fastapi_swagger2/ Please do let me know your thoughts. |
Beta Was this translation helpful? Give feedback.
First i make the app fill the api data and create an endpoint which just returns a json of the schema
Then i have a function that goes to that url takes the schema and writes to a yaml file (json is also possible i believe)