Skip to content

Commit dc39a2a

Browse files
Feat: the JSON Schema HTML viewer generator script now supports generating only for one particular CycloneDX version, including the possibility of generating the HTML only for draft version of CycloneDX during dev time.
Signed-off-by: Nicolas-Peiffer <[email protected]> Fix the deletion of the docs folder Signed-off-by: Nicolas-Peiffer <[email protected]> Move deletion of the docs folder to CLI Signed-off-by: Nicolas-Peiffer <[email protected]>
1 parent f18b992 commit dc39a2a

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

docgen/json/gen.sh

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ THIS_PATH="$(realpath "$(dirname "$0")")"
55
SCHEMA_PATH="$(realpath "$THIS_PATH/../../schema")"
66
DOCS_PATH="$THIS_PATH/docs"
77
TEMPLATES_PATH="$THIS_PATH/templates"
8-
9-
rm -f -R "$DOCS_PATH"
10-
mkdir -p "$DOCS_PATH/"{1.2,1.3,1.4,1.5,1.6}
8+
VALID_CYCLONEDX_VERSIONS=(1.2 1.3 1.4 1.5 1.6)
9+
DRAFT_CYCLONEDX_VERSIONS=()
1110

1211
# Check to see if generate-schema-doc is executable and is in the path. If not, install JSON Schema for Humans.
1312
if ! [ -x "$(command -v generate-schema-doc)" ]
@@ -16,8 +15,31 @@ then
1615
pip3 install -r "$THIS_PATH/requirements.txt"
1716
fi
1817

18+
# Function to check if a version is in an array
19+
version_in_list() {
20+
local version="$1"
21+
shift
22+
local list=("$@")
23+
for item in "${list[@]}"; do
24+
if [[ "$item" == "$version" ]]; then
25+
return 0
26+
fi
27+
done
28+
return 1
29+
}
30+
1931
generate () {
2032
version="$1"
33+
34+
# Check if the version match a valid CycloneDX version or a draft under development
35+
if ! version_in_list "$version" "${VALID_CYCLONEDX_VERSIONS[@]}" && ! version_in_list "$version" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; then
36+
echo "Failed: wrong CycloneDX version: $version"
37+
exit 1
38+
fi
39+
40+
echo "Create folder $DOCS_PATH/$version"
41+
mkdir -p "$DOCS_PATH/$version"
42+
2143
title="CycloneDX v${version} JSON Reference"
2244
echo "Generating: $title"
2345

@@ -45,8 +67,37 @@ generate () {
4567
sed -i -e "s/\${version}/$version/g" "$DOCS_PATH/$version/index.html"
4668
}
4769

48-
generate 1.2
49-
generate 1.3
50-
generate 1.4
51-
generate 1.5
52-
generate 1.6
70+
USAGE_HELP="Generate HTML JSON Schema navigator for CyccloneDX
71+
Usage: $0 <version> : runs only for <version>
72+
$0 : loops over all valid and draft CycloneDX versions"
73+
74+
# Main logic to handle the argument using a switch case
75+
case "$#" in
76+
0)
77+
# No arguments provided: Loop over all VALID_CYCLONEDX_VERSIONS and DRAFT_CYCLONEDX_VERSIONS
78+
echo "Deleting folder $DOCS_PATH"
79+
rm -f -R "$DOCS_PATH"
80+
for version in "${VALID_CYCLONEDX_VERSIONS[@]}" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; do
81+
generate "$version"
82+
done
83+
;;
84+
1)
85+
case "$1" in
86+
"-h"|"--help")
87+
echo "Usage: $USAGE_HELP"
88+
exit 1
89+
;;
90+
*)
91+
# One argument provided: Call generate with the specific version
92+
echo "Deleting folder $DOCS_PATH"
93+
rm -f -R "$DOCS_PATH"
94+
generate "$1"
95+
;;
96+
esac
97+
;;
98+
*)
99+
# More than one argument provided: Show usage help
100+
echo "Usage: $USAGE_HELP"
101+
exit 1
102+
;;
103+
esac

0 commit comments

Comments
 (0)