-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate-docs-api.sh
executable file
·52 lines (43 loc) · 1.7 KB
/
generate-docs-api.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
51
52
#!/bin/bash -e
VERSION=${version:-master}
if [ ! -f /.dockerenv ]; then
docker build -t mesg/docs:local --build-arg version=$VERSION -f Dockerfile.docs .
docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/project mesg/docs:local ./generate-docs-api.sh
exit
fi
echo "Generate API documentation"
DEF_REPO="mesg-foundation/engine"
DEF_BRANCH="${1:-dev}"
PROTO_PATH="https://raw.githubusercontent.com/$DEF_REPO/$DEF_BRANCH/protobuf"
PROJECT="/project"
GRPC_CACHE=$PROJECT/protobuf
EXPORT_PATH=$PROJECT/api
rm -rf $EXPORT_PATH
mkdir -p $EXPORT_PATH
mkdir -p $GRPC_CACHE/api
mkdir -p $GRPC_CACHE/types
curl -o "$GRPC_CACHE/types/struct.proto" "$PROTO_PATH/types/struct.proto"
ressources="event execution instance runner service process"
for ressource in $ressources; do
curl -o "$GRPC_CACHE/api/$ressource.proto" "$PROTO_PATH/api/$ressource.proto"
curl -o "$GRPC_CACHE/types/$ressource.proto" "$PROTO_PATH/types/$ressource.proto"
protoc \
--doc_out="$EXPORT_PATH" \
--doc_opt="json","$ressource-api.json" \
--proto_path="$PROJECT" \
--gogo_out=plugins=grpc,paths=source_relative:. \
"$GRPC_CACHE/api/${ressource}.proto"
protoc \
--doc_out="$EXPORT_PATH" \
--doc_opt="json","$ressource-type.json" \
--proto_path="$PROJECT" \
--gogo_out=plugins=grpc,paths=source_relative:. \
"$GRPC_CACHE/types/$ressource.proto"
echo "# $ressource
<api-doc
:apifiles='$(cat $EXPORT_PATH/$ressource-api.json | jq -c . | sed "s/'/\’/g" )'
:typefiles='$(cat $EXPORT_PATH/$ressource-type.json | jq -c . | sed "s/'/\’/g" )'
/>" > $EXPORT_PATH/$ressource.md
rm $EXPORT_PATH/$ressource-api.json $EXPORT_PATH/$ressource-type.json
done
rm -rf $GRPC_CACHE