Optimize swagger doc generator for Fission CR types (#2123)

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2021-07-22 19:05:37 +05:30
committed by GitHub
parent d4d58e166b
commit a7f819a78e
15 changed files with 92 additions and 187 deletions
+15
View File
@@ -0,0 +1,15 @@
/*
Copyright The Fission Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
-10
View File
@@ -1,10 +0,0 @@
if [ ! -d "../code-generator" ]; then
echo "Please get code-generator from fission org"
exit 1
fi
export GOPATH=$(go env GOPATH)
../code-generator/generate-groups.sh all \
github.com/fission/fission/pkg/generated \
github.com/fission/fission/pkg/apis "core:v1" \
--go-header-file ./pkg/apis/boilerplate.txt
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
API_GROUP_VERSIONS="
core/v1
"
API_PACKAGES="
"
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
if [ ! -d "../code-generator" ]; then
echo "Please get code-generator from fission org"
exit 1
fi
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/fission/fission/pkg/generated \
github.com/fission/fission/pkg/apis \
"core:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \
--go-header-file "$(dirname "${BASH_SOURCE[0]}")/boilerplate.txt"
+56
View File
@@ -0,0 +1,56 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
# 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.
kube::swagger::gen_types_swagger_doc() {
local group_version=$1
local gv_dir=$2
local TMPFILE="${TMPDIR:-/tmp}/zz_generated.swagger_doc_generated.$(date +%s).go"
echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
sed 's/YEAR/2017/' hack/boilerplate.txt > "$TMPFILE"
echo "package ${group_version##*/}" >> "$TMPFILE"
cat >> "$TMPFILE" <<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-swagger-docs.sh
// AUTO-GENERATED FUNCTIONS START HERE
EOF
go run tools/genswaggertypedocs/swagger_type_docs.go -s \
${gv_dir}/types*.go \
-f - \
>> "$TMPFILE"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "$TMPFILE"
gofmt -w -s "$TMPFILE"
mv "$TMPFILE" ""${gv_dir}"/zz_generated.swagger_doc_generated.go"
}
util::group-version-to-pkg-path() {
local group_version="$1"
echo "pkg/apis/${group_version}"
}
for gv in ${API_GROUP_VERSIONS}; do
rm -f "${SCRIPT_ROOT}/${gv}/zz_generated.swagger_doc_generated.go"
util::group-version-to-pkg-path "${gv}"
kube::swagger::gen_types_swagger_doc "${gv}" "$(util::group-version-to-pkg-path "${gv}")"
done
-21
View File
@@ -1,21 +0,0 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
find_files() {
find . -not \( \
\( \
-wholename '*/vendor/*' \
\) -prune \
\) -name '*.go'
}
GOFMT="gofmt -s"
bad_files=$(find_files | xargs $GOFMT -l)
if [[ -n "${bad_files}" ]]; then
echo "!!! '$GOFMT' needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi
-7
View File
@@ -1,7 +0,0 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
go vet -v $(go list ./...| grep -v "vendor" | grep -v "examples" | grep -v "genclient" | grep -v "demos" | grep -v "test")
-7
View File
@@ -1,7 +0,0 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
go list ./...| grep -v vendor | grep -v "examples" | grep -v "demos" | grep -v "genclient" | grep -v "test" | xargs -I@ staticcheck @