-
Notifications
You must be signed in to change notification settings - Fork 23
/
generate-openapi.sh
executable file
·46 lines (38 loc) · 1.25 KB
/
generate-openapi.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
#!/bin/bash
set -euo pipefail
FROM_REPO=$1;
if [ "$FROM_REPO" == 'chat' ]; then
PROTOCOL_REPO_DIR="../../../chat"
else
PROTOCOL_REPO_DIR="../../../protocol"
fi
if [ "$FROM_REPO" == 'chat' ]; then
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi-clientside.yaml"
elif [ "$FROM_REPO" == 'protocol' ]; then
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi-clientside.yaml"
else
SCHEMA_FILE=$FROM_REPO
fi
if [ "$FROM_REPO" == 'chat' ]; then
# Generate the Coordinator OpenAPI schema
make -C $PROTOCOL_REPO_DIR openapi
fi
OUTPUT_DIR="./src/gen/coordinator"
TEMP_OUTPUT_DIR="./src/gen/openapi-temp"
# Clean previous output
rm -rf $TEMP_OUTPUT_DIR
rm -rf $OUTPUT_DIR
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
# Generate the Coordinator API models
yarn openapi-generator-cli generate \
-i "$SCHEMA_FILE" \
-g typescript-fetch \
-o "$TEMP_OUTPUT_DIR" \
--additional-properties=supportsES6=true \
--additional-properties=modelPropertyNaming=original \
--additional-properties=enumPropertyNaming=UPPERCASE \
--additional-properties=withoutRuntimeChecks=true
# Remove the generated API client, just keep the models
cp -r $TEMP_OUTPUT_DIR/models $OUTPUT_DIR
rm -rf $TEMP_OUTPUT_DIR
yarn prettier --write $OUTPUT_DIR