-
Notifications
You must be signed in to change notification settings - Fork 3
/
refresh.sh
executable file
·37 lines (27 loc) · 1.16 KB
/
refresh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
GEN_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'k8')
echo "Generating full client from OpenAPI spec..."
npx @openapitools/openapi-generator-cli generate \
-i $SCRIPT_DIR/swagger.json \
-o $GEN_DIR \
-g python \
-c $SCRIPT_DIR/config.json \
--skip-validate-spec
TARGET_DIR=$SCRIPT_DIR/src
echo "Copying client from $GEN_DIR to $TARGET_DIR..."
rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR/k8
mv $GEN_DIR/client/models/*.py $TARGET_DIR/k8
# The default __init__.py includes all modules, this is an easy footgun as it's a large import cost
# eliminate the option so clients must include individual models.
echo "Removing __init__.py footgun..."
echo "" > $TARGET_DIR/k8/__init__.py
# Correct all import references
echo "Correcting all import references..."
find $TARGET_DIR -type f -name "*.py" -exec sed -i '' 's/client.models\./\./g' {} +
echo "Fixing IntOrStr"
sed -i "" -E 's|Dict\[str, Any\]( = Field\(description="It'"'"'s an int or a string."\))|int \| str\1|g' $TARGET_DIR/k8/v1_http_get_action.py
echo "Add py.typed"
touch $TARGET_DIR/k8/py.typed
echo "done."