-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-schema.sh
More file actions
executable file
·74 lines (61 loc) · 2.2 KB
/
Copy pathbuild-schema.sh
File metadata and controls
executable file
·74 lines (61 loc) · 2.2 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Build HyperFleet Template OpenAPI schema (OpenAPI 3.0 + OpenAPI 2.0 Swagger)
# Usage: ./build-schema.sh
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if [ ! -x "${SCRIPT_DIR}/node_modules/.bin/tsp" ]; then
echo -e "${RED}Error: tsp not found in node_modules. Run 'npm install' first.${NC}"
exit 1
fi
TSP="${SCRIPT_DIR}/node_modules/.bin/tsp"
echo -e "${GREEN}Building HyperFleet Template API schema${NC}"
echo -e "${GREEN}Output formats: OpenAPI 3.0 + OpenAPI 2.0 (Swagger)${NC}"
echo ""
OUTPUT_DIR="schemas/template"
echo -e "${YELLOW}Step 1: Preparing output directory...${NC}"
mkdir -p "$OUTPUT_DIR"
echo -e "${GREEN}✓ Created output directory: ${OUTPUT_DIR}${NC}"
echo ""
echo -e "${YELLOW}Step 2: Compiling TypeSpec from main.tsp...${NC}"
TEMP_OUTPUT_DIR="tsp-output-template"
cleanup() {
rm -rf "$TEMP_OUTPUT_DIR"
}
trap cleanup EXIT
if "$TSP" compile main.tsp --output-dir "$TEMP_OUTPUT_DIR"; then
if [ -f "${TEMP_OUTPUT_DIR}/schema/openapi.yaml" ]; then
mv "${TEMP_OUTPUT_DIR}/schema/openapi.yaml" "${OUTPUT_DIR}/openapi.yaml"
echo ""
echo -e "${GREEN}✓ Successfully generated OpenAPI 3.0 schema${NC}"
echo -e "${GREEN}Output: ${OUTPUT_DIR}/openapi.yaml${NC}"
else
echo ""
echo -e "${RED}✗ Generated schema file not found at expected location${NC}"
echo "Expected: ${TEMP_OUTPUT_DIR}/schema/openapi.yaml"
exit 1
fi
else
echo ""
echo -e "${RED}✗ Failed to compile TypeSpec${NC}"
exit 1
fi
echo ""
echo -e "${YELLOW}Step 3: Converting to OpenAPI 2.0 (Swagger)...${NC}"
if node "${SCRIPT_DIR}/scripts/convert-to-swagger.mjs" \
"${OUTPUT_DIR}/openapi.yaml" \
"${OUTPUT_DIR}/swagger.yaml"; then
echo -e "${GREEN}✓ Successfully generated OpenAPI 2.0 (Swagger) schema${NC}"
echo -e "${GREEN}Output: ${OUTPUT_DIR}/swagger.yaml${NC}"
else
echo -e "${RED}✗ Failed to convert to OpenAPI 2.0 (Swagger)${NC}"
echo "The OpenAPI 3.0 schema may contain features not supported in OpenAPI 2.0"
rm -f "${OUTPUT_DIR}/swagger.yaml"
exit 1
fi
echo ""
echo -e "${GREEN}Build complete!${NC}"