Files
kumomta/docs/update-openapi.sh
Wez Furlong a768c6dc79 update-openapi.sh: only run when jq is available
This script is triggered as part of `make test` which is not
really a great place for it.

Its purpose is to extract the auto-generated openapi spec
from the kumod and tsa binaries and update the snapshot
that is present in the docs.

It needs kumod and tsa-daemon to have been built in debug mode
to run successfully.

It piggy-backs on `make test` on the assumption that it will
cause the person who is making changes to it to include those
spec updates in their commit/PR.

Since `make test` invokes it, the various builders may try
and fail to execute jq in the `test` step.  This is mostly
harmless, but looks noisy in the logs.

The ideal situation for this would be:

* at PR time and push time: add a check that runs this script and that
  fails if the specs are updated for the docs and are not part of the PR
  itself. (eg: status is dirty after running it).
  This way it will be visible from the CI state that something is awry.
2024-04-20 07:17:02 -07:00

37 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# This script updates the snapshot of the openapi specs for our
# various services, so that the mkdocs build can consume them
# to render the docs in the docs.
# It needs to be run manually after changing anything to do with the
# HTTP APIs.
# Only update the spec file if anything other than the version (which
# typically changes all the time during development, to track the current
# git hash) actually changed.
update_if_different() {
binary=$1
specfile=$2
candidate=$(mktemp)
trap "rm ${candidate}" "EXIT"
current=$(mktemp)
trap "rm ${current}" "EXIT"
$binary --dump-openapi-spec | blank_out_openapi_spec_version > $candidate
blank_out_openapi_spec_version < $specfile > $current
if ! cmp $candidate $current ; then
echo "$specfile updated"
$binary --dump-openapi-spec > $specfile
fi
}
# Replace info.version with "blank" in an openapi json doc
blank_out_openapi_spec_version() {
jq --arg version 'blank' '.info.version = $version'
}
if hash jq 2>/dev/null ; then
update_if_different ./target/debug/kumod docs/reference/kumod.openapi.json
update_if_different ./target/debug/tsa-daemon docs/reference/tsa-daemon.openapi.json
fi