Generating FastAPI client code with GitHub Action. #2771
synchronizing
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Creating microservices is hard enough... creating boilerplate code to call your microservices from other microservices is just plain annoying. Sharing a quick and easy way to automate the generation of client code utilizing GitHub actions for anyone that might have use for it.
Using the FastAPI code example given here, we will have GitHub automatically generate the OpenAPI client code in a separate branch called
client
using OpenAPI Generator. This is the current project structure (GitHub link to project can be found here):requirements.txt
openapirc.yaml
main.py
The function at the bottom will rename the
operationId
configuration of the OpenAPI to that of the Python function name. Makes the function calls easier to read. Relevant docs can be found here.generate-client.yml
The relevant piece of code. Documentation for each step of the GitHub action can be found below.
Once
.github/workflows/generate-client.yml
file is added to your repo and modified for your use case it should automatically auto-generate your FastAPI client code into a branchclient
(unless changed).Example
master
: https://github.com/synchronizing/fastapi-gh-action-exampleclient
: https://github.com/synchronizing/fastapi-gh-action-example/tree/clientRelevant Documentation
Beta Was this translation helpful? Give feedback.
All reactions