Merge pull request #115246 from thockin/codegen-11-swagger-from-update-codegen

Generate swagger from update-codegen
This commit is contained in:
Kubernetes Prow Robot
2023-01-22 11:24:10 -08:00
committed by GitHub
59 changed files with 129 additions and 194 deletions

View File

@@ -118,6 +118,80 @@ function codegen::protobuf() {
build/run.sh hack/update-generated-protobuf-dockerized.sh "${apis[@]}"
}
# Generates types_swagger_doc_generated file for the given group version.
# $1: Name of the group version
# $2: Path to the directory where types.go for that group version exists. This
# is the directory where the file will be generated.
function gen_types_swagger_doc() {
# The tool used to generate swagger code.
local swagger_bin
swagger_bin="$(kube::util::find-binary "genswaggertypedocs")"
local group_version="$1"
local gv_dir="$2"
local tmpfile
tmpfile="${TMPDIR:-/tmp}/types_swagger_doc_generated.$(date +%s).go"
if [[ "${DBG_CODEGEN}" == 1 ]]; then
kube::log::status "DBG: running ${swagger_bin} for ${group_version} at ${gv_dir}"
fi
{
cat "${BOILERPLATE_FILENAME}"
echo
echo "package ${group_version##*/}"
# Indenting here prevents the boilerplate checker from thinking this file
# is generated - gofmt will fix the indents anyway.
cat <<EOF
// This file contains a collection of methods that can be used from go-restful to
// generate Swagger API documentation for its models. Please read this PR for more
// information on the implementation: https://github.com/emicklei/go-restful/pull/215
//
// TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
// they are on one line! For multiple line or blocks that you want to ignore use ---.
// Any context after a --- is ignored.
//
// Those methods can be generated by using hack/update-codegen.sh
// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
EOF
} > "${tmpfile}"
"${swagger_bin}" \
-s \
"${gv_dir}/types.go" \
-f - \
>> "${tmpfile}"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${tmpfile}"
gofmt -w -s "${tmpfile}"
mv "${tmpfile}" "${gv_dir}/types_swagger_doc_generated.go"
}
# swagger generation
#
# Some of the later codegens depend on the results of this, so it needs to come
# first in the case of regenerating everything.
function codegen::swagger() {
# Build the tool
GO111MODULE=on GOPROXY=off go install \
./cmd/genswaggertypedocs
local group_versions=()
IFS=" " read -r -a group_versions <<< "meta/v1 meta/v1beta1 ${KUBE_AVAILABLE_GROUP_VERSIONS}"
kube::log::status "Generating swagger for ${#group_versions[@]} targets"
git_find -z ':(glob)**/types_swagger_doc_generated.go' | xargs -0 rm -f
# Regenerate files.
for group_version in "${group_versions[@]}"; do
gen_types_swagger_doc "${group_version}" "$(kube::util::group-version-to-pkg-path "${group_version}")"
done
}
# prerelease-lifecycle generation
#
# Any package that wants prerelease-lifecycle functions generated must include a