-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-types.sh
More file actions
61 lines (52 loc) · 1.76 KB
/
generate-types.sh
File metadata and controls
61 lines (52 loc) · 1.76 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
#!/bin/bash
## This script goes throuch each Sources folder and checks for two files:
## openapi.yaml openapi-generator-config.yml
## If those files exist, it runs the generator in that folder location
## and outputs to GeneratedSources folder
## Names
YAML_NAME="openapi.yaml"
CONFIG_NAME="openapi-generator-config.yaml"
OUTPUTDIR_NAME="GeneratedSources"
## Locations
# /home/someone/MWServer-Models/
SCRIPT_LOCATION=$(dirname "$0")
# /home/someone/MWServer-Models/Sources
SOURCES_PATH="$SCRIPT_LOCATION/Sources"
## Make sure we have sources path, aka the script is in the right location
if [ ! -d "$SOURCES_PATH" ]; then
echo "Sources does not exist!"
exit
fi
## Go through search folder in Sources
for SOURCE in "$SOURCES_PATH"/*; do
## The yaml should be at Sources/$Source/openapi.yaml
YAML_LOCATION="$SOURCE/$YAML_NAME"
## The config file should be Sources/$Source/openapi-generator-config.yaml
SOURCE_CONFIG_PATH="$SOURCE/$CONFIG_NAME"
## The output dir should be Sources/$Source/GeneratedSources
OUTPUT_DIR="$SOURCE/$OUTPUTDIR_NAME"
## If the yaml file, or config doesn't exist, the generator will fail.
if ! [ -e $YAML_LOCATION ];
then
echo "No yaml found at $YAML_LOCATION"
continue
fi;
if ! [ -e $SOURCE_CONFIG_PATH ];
then
echo "No config found at $SOURCE_CONFIG_PATH"
continue
fi
echo "Building $SOURCE at $OUTPUT_DIR"
## If this command executes successfully
if swift run swift-openapi-generator generate \
--config "$SOURCE_CONFIG_PATH" \
--output-directory="$OUTPUT_DIR" \
"$YAML_LOCATION";
then
echo "Successful output for $SOURCE at $OUTPUT_DIR"
else
echo "Command failed"
exit
## if this says no yaml found, you need the yaml in each root folder: /Sources/<folder>/openapi.yaml
fi
done