Skip to content

Commit 6aa23e4

Browse files
author
Chao Xu
committed
refacotr update-api-reference-docs.sh
1 parent c70c7fd commit 6aa23e4

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed
File renamed without changes.

Diff for: hack/after-build/update-swagger-spec.sh

+28-7
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,36 @@ APISERVER_PID=$!
6464
kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver: "
6565

6666
SWAGGER_API_PATH="http://127.0.0.1:${API_PORT}/swaggerapi/"
67+
DEFAULT_GROUP_VERSIONS="v1 extensions/v1beta1"
68+
VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}
69+
6770
kube::log::status "Updating " ${SWAGGER_ROOT_DIR}
68-
curl -fs ${SWAGGER_API_PATH} > ${SWAGGER_ROOT_DIR}/resourceListing.json
69-
curl -fs ${SWAGGER_API_PATH}version > ${SWAGGER_ROOT_DIR}/version.json
70-
curl -fs ${SWAGGER_API_PATH}api > ${SWAGGER_ROOT_DIR}/api.json
71-
curl -fs ${SWAGGER_API_PATH}api/v1 > ${SWAGGER_ROOT_DIR}/v1.json
72-
curl -fs ${SWAGGER_API_PATH}apis > ${SWAGGER_ROOT_DIR}/apis.json
73-
curl -fs ${SWAGGER_API_PATH}apis/extensions > ${SWAGGER_ROOT_DIR}/extensions.json
74-
curl -fs ${SWAGGER_API_PATH}apis/extensions/v1beta1 > ${SWAGGER_ROOT_DIR}/v1beta1.json
7571

72+
for ver in ${VERSIONS}; do
73+
# fetch the swagger spec for each group version.
74+
if [[ ${ver} == "v1" ]]; then
75+
SUBPATH="api"
76+
else
77+
SUBPATH="apis"
78+
fi
79+
SUBPATH="${SUBPATH}/${ver}"
80+
SWAGGER_JSON_NAME="$(kube::util::gv-to-swagger-name ${ver}).json"
81+
curl -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}"
82+
83+
# fetch the swagger spec for the discovery mechanism at group level.
84+
if [[ ${ver} == "v1" ]]; then
85+
continue
86+
fi
87+
SUBPATH="apis/"${ver%/*}
88+
SWAGGER_JSON_NAME="${ver%/*}.json"
89+
curl -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}"
90+
done
91+
92+
# fetch swagger specs for other discovery mechanism.
93+
curl -fs "${SWAGGER_API_PATH}" > "${SWAGGER_ROOT_DIR}/resourceListing.json"
94+
curl -fs "${SWAGGER_API_PATH}version" > "${SWAGGER_ROOT_DIR}/version.json"
95+
curl -fs "${SWAGGER_API_PATH}api" > "${SWAGGER_ROOT_DIR}/api.json"
96+
curl -fs "${SWAGGER_API_PATH}apis" > "${SWAGGER_ROOT_DIR}/apis.json"
7697
kube::log::status "SUCCESS"
7798

7899
# ex: ts=2 sw=2 et filetype=sh

Diff for: hack/gen-swagger-doc/gen-swagger-docs.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ for i in {1..3}; do
3333
done
3434

3535
# gendocs takes "input.json" as the input swagger spec.
36+
# $1 is expected to be <group>_<version>
3637
cp /swagger-source/"$1".json input.json
3738

3839
./gradle-2.5/bin/gradle gendocs --info
@@ -41,20 +42,24 @@ cp /swagger-source/"$1".json input.json
4142
buf="== Top Level API Objects\n\n"
4243
top_level_models=$(grep GetObjectKind ./register.go | sed 's/func (obj \*\(.*\)) GetObjectKind(\(.*\)) .*/\1/g' \
4344
| tr -d '()' | tr -d '{}' | tr -d ' ')
45+
46+
# check if the top level models exist in the definitions.adoc. If they exist,
47+
# their name will be <version>.<model_name>
48+
VERSION="${1#*_}"
4449
for m in $top_level_models
4550
do
46-
if grep -xq "=== $1.$m" ./definitions.adoc
51+
if grep -xq "=== ${VERSION}.$m" ./definitions.adoc
4752
then
48-
buf+="* <<$1."$m">>\n"
53+
buf+="* <<${VERSION}.$m>>\n"
4954
fi
5055
done
5156
sed -i "1i $buf" ./definitions.adoc
5257

53-
#fix the links in .adoc, replace <<x.y>> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part
58+
# fix the links in .adoc, replace <<x.y>> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part
5459
sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc
5560
sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:definitions.html#_\L\1_\2\E[\1.\2]|g' ./paths.adoc
5661

57-
#fix the link to <<any>>
62+
# fix the link to <<any>>
5863
sed -i -e 's|<<any>>|link:#_any[any]|g' ./definitions.adoc
5964
sed -i -e 's|<<any>>|link:definitions.html#_any[any]|g' ./paths.adoc
6065

Diff for: hack/lib/util.sh

+15
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,19 @@ kube::util::group-version-to-pkg-path() {
297297
esac
298298
}
299299

300+
# Takes a group/version and returns the swagger-spec file name.
301+
# default behavior: extensions/v1beta1 -> extensions_v1beta1
302+
# special case for v1: v1 -> v1
303+
kube::util::gv-to-swagger-name() {
304+
local group_version="$1"
305+
case "${group_version}" in
306+
v1)
307+
echo "v1"
308+
;;
309+
*)
310+
echo "${group_version%/*}_${group_version#*/}"
311+
;;
312+
esac
313+
}
314+
300315
# ex: ts=2 sw=2 et filetype=sh

Diff for: hack/update-api-reference-docs.sh

+23-13
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ OUTPUT_TMP="${KUBE_ROOT}/${TMP_SUBPATH}"
4040

4141
echo "Generating api reference docs at ${OUTPUT_TMP}"
4242

43-
V1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/v1/"
44-
V1_TMP="${OUTPUT_TMP}/v1/"
45-
mkdir -p ${V1_TMP}
46-
V1BETA1_TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/extensions/v1beta1/"
47-
V1BETA1_TMP="${OUTPUT_TMP}/extensions/v1beta1/"
48-
mkdir -p ${V1BETA1_TMP}
43+
DEFAULT_GROUP_VERSIONS="v1 extensions/v1beta1"
44+
VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}
45+
for ver in $VERSIONS; do
46+
mkdir -p "${OUTPUT_TMP}/${ver}"
47+
done
48+
4949
SWAGGER_PATH="${REPO_DIR}/api/swagger-spec/"
5050

5151
echo "Reading swagger spec from: ${SWAGGER_PATH}"
@@ -56,13 +56,23 @@ if [[ $(uname) == "Darwin" ]]; then
5656
user_flags=""
5757
fi
5858

59-
docker run ${user_flags} --rm -v $V1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4.2 \
60-
v1 \
61-
https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/api/v1/register.go
59+
for ver in $VERSIONS; do
60+
TMP_IN_HOST="${OUTPUT_TMP_IN_HOST}/${ver}"
61+
REGISTER_FILE_URL="https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg"
62+
if [[ ${ver} == "v1" ]]; then
63+
REGISTER_FILE_URL="${REGISTER_FILE_URL}/api/${ver}/register.go"
64+
else
65+
REGISTER_FILE_URL="${REGISTER_FILE_URL}/apis/${ver}/register.go"
66+
fi
67+
SWAGGER_JSON_NAME="$(kube::util::gv-to-swagger-name "${ver}")"
6268

63-
docker run ${user_flags} --rm -v $V1BETA1_TMP_IN_HOST:/output:z -v ${SWAGGER_PATH}:/swagger-source:z gcr.io/google_containers/gen-swagger-docs:v4.2 \
64-
v1beta1 \
65-
https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/apis/extensions/v1beta1/register.go
69+
docker run ${user_flags} \
70+
--rm -v "${TMP_IN_HOST}":/output:z \
71+
-v "${SWAGGER_PATH}":/swagger-source:z \
72+
gcr.io/google_containers/gen-swagger-docs:v5 \
73+
"${SWAGGER_JSON_NAME}" \
74+
"${REGISTER_FILE_URL}"
75+
done
6676

6777
# Check if we actually changed anything
6878
pushd "${OUTPUT_TMP}" > /dev/null
@@ -93,6 +103,6 @@ done <"${OUTPUT_TMP}/.generated_html"
93103
echo "Moving api reference docs from ${OUTPUT_TMP} to ${OUTPUT}"
94104

95105
cp -af "${OUTPUT_TMP}"/* "${OUTPUT}"
96-
rm -r ${OUTPUT_TMP}
106+
rm -r "${OUTPUT_TMP}"
97107

98108
# ex: ts=2 sw=2 et filetype=sh

0 commit comments

Comments
 (0)