Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Created July 4, 2023 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsanh/ea57c4f2c9e37ff125a9273b3dbce67a to your computer and use it in GitHub Desktop.
Save tamsanh/ea57c4f2c9e37ff125a9273b3dbce67a to your computer and use it in GitHub Desktop.
Generate an openapi client for python
#!/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