k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/verify-openapi-docs-urls.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2023 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This script checks the documentation (description) from the OpenAPI specification for URLs, and 18 # verifies those URLs are valid. 19 # Usage: `hack/verify-openapi-docs-links.sh`. 20 21 set -o errexit 22 set -o nounset 23 set -o pipefail 24 25 KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 26 source "${KUBE_ROOT}/hack/lib/init.sh" 27 28 SPECROOT="${KUBE_ROOT}/api/openapi-spec" 29 SPECV3PATH="${SPECROOT}/v3" 30 31 _tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")" 32 mkdir -p "${_tmpdir}" 33 trap 'rm -rf ${_tmpdir}' EXIT SIGINT 34 trap "echo Aborted; exit;" SIGINT SIGTERM 35 36 TMP_URLS="${_tmpdir}/docs_urls.txt" 37 touch "${TMP_URLS}" 38 39 40 for full_repo_path in "${SPECV3PATH}"/*.json; do 41 grep -oE '"description": ".*",?$' "$full_repo_path" | grep -oE 'https?:\/\/[-a-zA-Z0-9._+]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9:%_+.~&/=]*[a-zA-Z0-9])' >> "${TMP_URLS}" || true 42 done 43 sort -u "${TMP_URLS}" -o "${TMP_URLS}" 44 45 RESULT=0 46 while read -r URL; do 47 if ! curl --head --location --fail --silent "$URL" > /dev/null; then 48 echo "$URL not found" 49 RESULT=1 50 fi 51 done < "${TMP_URLS}" 52 53 exit $RESULT 54 55 # ex: ts=2 sw=2 et filetype=sh