-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
50 lines (40 loc) · 1.78 KB
/
generate.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
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
OPENAPI_URL="https://api.sevdesk.de/openapi.yaml"
OPENAPI_FILE="openapi.yaml"
# Target directories
TYPES_DIR="./types"
CLIENT_DIR="./client"
SERVER_DIR="./server"
# Colors for output
GREEN='\033[0;32m'
NC='\033[0m'
RED='\033[0;31m'
abort() {
echo -e "${RED}Error: $1${NC}"
exit 1
}
# Check if the OpenAPI file exists
if [ -f "$OPENAPI_FILE" ]; then
echo -e "${GREEN}$OPENAPI_FILE already exists. Skipping download.${NC}"
else
# Download the OpenAPI definition
echo "Downloading OpenAPI definition from $OPENAPI_URL ..."
curl -o "$OPENAPI_FILE" "$OPENAPI_URL" || abort "Failed to download OpenAPI definition."
echo -e "${GREEN}OpenAPI definition successfully downloaded to $OPENAPI_FILE${NC}"
fi
# Create target directories if they don't exist
echo "Creating target directories ..."
mkdir -p "$TYPES_DIR" "$CLIENT_DIR" "$SERVER_DIR" || abort "Failed to create target directories."
# Generate Go files for types
echo "Generating Go files for types ..."
oapi-codegen -generate types -o "$TYPES_DIR/types.go" -package types "$OPENAPI_FILE" || abort "Error generating types files."
echo -e "${GREEN}Types files successfully generated in $TYPES_DIR/types.go${NC}"
# Generate Go files for client
echo "Generating Go files for client ..."
oapi-codegen -generate client -o "$CLIENT_DIR/client.go" -package client "$OPENAPI_FILE" || abort "Error generating client files."
echo -e "${GREEN}Client files successfully generated in $CLIENT_DIR/client.go${NC}"
# Generate Go files for server
echo "Generating Go files for server ..."
oapi-codegen -generate server -o "$SERVER_DIR/server.go" -package server "$OPENAPI_FILE" || abort "Error generating server files."
echo -e "${GREEN}Server files successfully generated in $SERVER_DIR/server.go${NC}"
echo -e "${GREEN}All steps completed successfully.${NC}"