#!/bin/bash
set -uo pipefail

if [ -z "${1:-}" ]; then
    SCHEMA="_build/emqx/lib/emqx_dashboard/priv/www/static/schema.json"
else
    SCHEMA="$1"
fi

docker run -d --name langtool "ghcr.io/emqx/emqx-schema-validate:0.3.3"

docker exec -i langtool ./emqx_schema_validate - < "${SCHEMA}"
success="$?"

docker kill langtool || true
docker rm langtool || true

echo "If this script finds a false positive (e.g. when it things that a protocol name is a typo),
make a PR here: https://github.com/emqx/emqx-schema-validate/blob/master/dict/en_spelling_additions.txt"

exit "$success"
