-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_models.sh
executable file
·47 lines (35 loc) · 1.36 KB
/
generate_models.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
#!/bin/bash
# Define the source directories
source_dirs=("Sources/ValhallaModels" "Sources/ValhallaConfigModels")
if [ "$1" == "clean" ]; then
echo "Cleaning openapi models..."
rm -rf .openapi-temp
for dir in "${source_dirs[@]}"; do
rm -rf "$dir/Models"
rm -rf "$dir/Support"
done
fi
mkdir -p .openapi-temp
for dir in "${source_dirs[@]}"; do
echo "Generating Swift models for $dir..."
# Check if openapi.yaml exists in the current directory
if [ ! -f "$dir/openapi.yaml" ]; then
echo "Error: openapi.yaml not found in $dir"
continue
fi
# Create necessary directories
mkdir -p "$dir/Models"
mkdir -p "$dir/Support"
# Generate models
openapi-generator generate -i "$dir/openapi.yaml" -g swift5 --strict-spec=true \
-o .openapi-temp --model-package Models --skip-validate-spec --additional-properties=useJsonEncodable=false
# Format generated files
swiftformat .openapi-temp/OpenAPIClient/Classes/OpenAPIsModels
# Move the generated files to the correct directory
mv .openapi-temp/OpenAPIClient/Classes/OpenAPIsModels/* "$dir/Models/"
mv .openapi-temp/OpenAPIClient/Classes/OpenAPIs/Validation.swift "$dir/Support/Validation.swift"
echo "Done generating models for $dir"
done
# Clean up temporary directory
rm -rf .openapi-temp
echo "All models generated successfully"