Generate and verify openapi specs in source tree at api/openapi-spec
This commit is contained in:
@@ -387,6 +387,59 @@ kube::util::fetch-swagger-spec() {
|
||||
curl -w "\n" -fs "${SWAGGER_API_PATH}logs" > "${SWAGGER_ROOT_DIR}/logs.json"
|
||||
}
|
||||
|
||||
# Takes a group/version and returns the openapi-spec file name.
|
||||
# default behavior: extensions/v1beta1 -> v1beta1.extensions
|
||||
# special case for v1: v1 -> v1
|
||||
kube::util::gv-to-openapi-name() {
|
||||
local group_version="$1"
|
||||
case "${group_version}" in
|
||||
v1)
|
||||
echo "v1"
|
||||
;;
|
||||
*)
|
||||
echo "${group_version#*/}.${group_version%/*}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# Fetches openapi spec from apiserver.
|
||||
# Assumed vars:
|
||||
# OPENAPI_API_PATH: Base path for openapi on apiserver. normally APIServer root. i.e., http://localhost:8080/
|
||||
# OPENAPI_ROOT_DIR: Root dir where we want to to save the fetched spec.
|
||||
# VERSIONS: Array of group versions to include in swagger spec.
|
||||
kube::util::fetch-openapi-spec() {
|
||||
for ver in ${VERSIONS}; do
|
||||
if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${ver} "* ]]; then
|
||||
continue
|
||||
fi
|
||||
# fetch the openapi spec for each group version.
|
||||
if [[ ${ver} == "v1" ]]; then
|
||||
SUBPATH="api"
|
||||
else
|
||||
SUBPATH="apis"
|
||||
fi
|
||||
SUBPATH="${SUBPATH}/${ver}"
|
||||
OPENAPI_JSON_NAME="$(kube::util::gv-to-openapi-name ${ver}).json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}${SUBPATH}/swagger.json" > "${OPENAPI_ROOT_DIR}/${OPENAPI_JSON_NAME}"
|
||||
|
||||
# fetch the openapi spec for the discovery mechanism at group level.
|
||||
if [[ ${ver} == "v1" ]]; then
|
||||
continue
|
||||
fi
|
||||
SUBPATH="apis/"${ver%/*}
|
||||
OPEAN_JSON_NAME="${ver%/*}.json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}${SUBPATH}/swagger.json" > "${OPENAPI_ROOT_DIR}/${OPENAPI_JSON_NAME}"
|
||||
done
|
||||
|
||||
# fetch openapi specs for other discovery mechanism.
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}swagger.json" > "${OPENAPI_ROOT_DIR}/root_swagger.json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}version/swagger.json" > "${OPENAPI_ROOT_DIR}/version.json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}api/swagger.json" > "${OPENAPI_ROOT_DIR}/api.json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}apis/swagger.json" > "${OPENAPI_ROOT_DIR}/apis.json"
|
||||
curl -w "\n" -fs "${OPENAPI_PATH}logs/swagger.json" > "${OPENAPI_ROOT_DIR}/logs.json"
|
||||
}
|
||||
|
||||
|
||||
# Returns the name of the upstream remote repository name for the local git
|
||||
# repo, e.g. "upstream" or "origin".
|
||||
|
Reference in New Issue
Block a user