-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiff.sh
executable file
·54 lines (41 loc) · 1.13 KB
/
diff.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
53
54
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -e
usage () {
cat << EOF
DESCRIPTION:
Generates a diff description for the given OpenAPI spec files.
SYNOPSIS:
$0 file_old file_new
OPTIONS:
-h Show this message.
-? Show this message.
EXAMPLE:
SPEC_FILE_1=$(mktemp)
SPEC_FILE_2=$(mktemp)
git show HEAD~5:openapi.yaml > ${SPEC_FILE_1}
git show HEAD:openapi.yaml > ${SPEC_FILE_2}
./diff.sh ${SPEC_FILE_1} ${SPEC_FILE_2}
EOF
}
while getopts ":h" option ; do
case $option in
h ) usage
exit 0;;
\? ) usage
exit 0;;
esac
done
shift $((OPTIND -1))
SPEC_FILE_1=$1
SPEC_FILE_2=$2
if [[ ! -s ${SPEC_FILE_1} ]]; then
echo "Invalid first positional parameter for the old OpenAPI spec file: $SPEC_FILE_1" >&2
exit 1
fi
if [[ ! -s ${SPEC_FILE_2} ]]; then
echo "Invalid second positional parameter for the new OpenAPI spec file: $SPEC_FILE_2" >&2
exit 1
fi
RAW_DIFF=$(java -jar swagger-diff.jar -old "${SPEC_FILE_1}" -new "${SPEC_FILE_2}" -v 2.0 -output-mode markdown)
echo "${RAW_DIFF}" | python ${SCRIPT_DIR}/diff_normalizer.py