#!/usr/bin/env bash
set -eu

# This script uses schematyper, which must be installed and in the PATH, to
# convert the json schema stored in schema/ignition.json into go structs for
# json deserialization in config/types/schema.go.
#
# This script should be run whenever schema/ignition.json is modified.

hash schematyper 2>/dev/null || {
    echo >&2 "schematyper must be installed and in the PATH to use this script: https://github.com/idubinskiy/schematyper"
    exit 1
}

echo "Generating schema..."
schematyper --package=types schema/ignition.json -o internal/config/types/schema.go --root-type=Config
cp internal/config/types/schema.go $(find config -name \*_experimental -type d)/types/schema.go
