-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema-create
executable file
·68 lines (61 loc) · 1.12 KB
/
schema-create
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
62
63
64
65
66
67
68
#!/bin/bash
APP="$(basename "${PWD}" | sed -e "s/^osiota-app-//g" -e "s/^er-app-//g")"
TARGET="index.js"
if test "x$1" != "x"
then
TARGET="$1"
fi
SCHEMAFILE="schema.json"
if test "x${TARGET}" != "xindex.js"
then
SCHEMAFILE="$(echo "${TARGET}" | sed -e "s/\.js/-schema.json/g")"
fi
echo "schema: ${SCHEMAFILE}"
if test -f "${SCHEMAFILE}"
then
echo "Error: ${SCHEMAFILE} already exists."
exit 1
fi
KEYS="$(grep -o "app_config\.[a-zA-Z0-9_]*" "${TARGET}" | sort | uniq | sed -e "s/app_config\.//g")"
(
cat <<EOF
{
"\$schema": "http://json-schema.org/draft/2019-09/schema#",
"type": "object",
"title": "osiota application ${APP}",
"description": "This application ... .",
"properties": {
EOF
for key in ${KEYS}
do
if test "x${key}" == "xmap"
then
cat <<EOF
"${key}": {
"type": "array",
"description": "Mapping elements",
"items": {
"type": "object",
"properties": {
"key": {
"type": "string"
}
}
}
}
EOF
else
cat <<EOF
"${key}": {
"type": "string",
"description": "Debug output text",
"examples": [ "Hello World!" ]
}
EOF
fi
done
cat <<EOF
}
}
EOF
) > "${SCHEMAFILE}"