Created
July 4, 2023 23:23
-
-
Save tamsanh/ea57c4f2c9e37ff125a9273b3dbce67a to your computer and use it in GitHub Desktop.
Generate an openapi client for python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $2 ]; then | |
echo "Usage: $0 [api_url] [package_name]" | |
echo "Creates a client in the local directory under a 'clients' module" | |
exit 1 | |
fi | |
api_url=${1} | |
package_name=${2} | |
set -ex | |
mkdir -p clients | |
touch clients/__init__.py | |
# Create the temp config file | |
echo "project_name_override: temp_client" >temp.yml | |
echo "package_name_override: ${package_name}" >>temp.yml | |
rm -rf temp_client | |
# installed via pip install openapi-python-client | |
openapi-python-client generate --url "${api_url}" --config temp.yml | |
rm -rf clients/${package_name} | |
mv temp_client/${package_name} clients/${package_name} | |
rm -rf temp_client | |
rm temp.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment