Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema HTML viewer generator script supports generating for one particular CDX version #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 59 additions & 8 deletions docgen/json/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ THIS_PATH="$(realpath "$(dirname "$0")")"
SCHEMA_PATH="$(realpath "$THIS_PATH/../../schema")"
DOCS_PATH="$THIS_PATH/docs"
TEMPLATES_PATH="$THIS_PATH/templates"

rm -f -R "$DOCS_PATH"
mkdir -p "$DOCS_PATH/"{1.2,1.3,1.4,1.5,1.6}
VALID_CYCLONEDX_VERSIONS=(1.2 1.3 1.4 1.5 1.6)
DRAFT_CYCLONEDX_VERSIONS=()

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

# Function to check if a version is in an array
version_in_list() {
local version="$1"
shift
local list=("$@")
for item in "${list[@]}"; do
if [[ "$item" == "$version" ]]; then
return 0
fi
done
return 1
}

generate () {
version="$1"

# Check if the version match a valid CycloneDX version or a draft under development
if ! version_in_list "$version" "${VALID_CYCLONEDX_VERSIONS[@]}" && ! version_in_list "$version" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; then
echo "Failed: wrong CycloneDX version: $version"
exit 1
fi

echo "Create folder $DOCS_PATH/$version"
mkdir -p "$DOCS_PATH/$version"

title="CycloneDX v${version} JSON Reference"
echo "Generating: $title"

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

generate 1.2
generate 1.3
generate 1.4
generate 1.5
generate 1.6
USAGE_HELP="Generate HTML JSON Schema navigator for CyccloneDX
Usage: $0 <version> : runs only for <version>
$0 : loops over all valid and draft CycloneDX versions"

# Main logic to handle the argument using a switch case
case "$#" in
0)
# No arguments provided: Loop over all VALID_CYCLONEDX_VERSIONS and DRAFT_CYCLONEDX_VERSIONS
echo "Deleting folder $DOCS_PATH"
rm -f -R "$DOCS_PATH"
for version in "${VALID_CYCLONEDX_VERSIONS[@]}" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; do
generate "$version"
done
;;
1)
case "$1" in
"-h"|"--help")
echo "Usage: $USAGE_HELP"
exit 1
;;
*)
# One argument provided: Call generate with the specific version
echo "Deleting folder $DOCS_PATH"
rm -f -R "$DOCS_PATH"
generate "$1"
;;
esac
;;
*)
# More than one argument provided: Show usage help
echo "Usage: $USAGE_HELP"
exit 1
;;
esac
Loading