Optimize swagger doc generator for Fission CR types (#2123)
Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -114,7 +114,7 @@ reporter-multiarch-img: cmd/reporter/Dockerfile.reporter
|
|||||||
|
|
||||||
### Codegen
|
### Codegen
|
||||||
codegen:
|
codegen:
|
||||||
@./hack/codegen.sh
|
@./hack/update-codegen.sh
|
||||||
|
|
||||||
### CRDs
|
### CRDs
|
||||||
generate-crds:
|
generate-crds:
|
||||||
@@ -142,7 +142,7 @@ clean:
|
|||||||
|
|
||||||
### Misc
|
### Misc
|
||||||
generate-swagger-doc:
|
generate-swagger-doc:
|
||||||
@cd pkg/apis/core/v1/tool && ./update-generated-swagger-docs.sh
|
@./hack/update-swagger-docs.sh
|
||||||
|
|
||||||
all-generators: codegen generate-crds generate-swagger-doc
|
all-generators: codegen generate-crds generate-swagger-doc
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
API_GROUP_VERSIONS="
|
||||||
|
core/v1
|
||||||
|
"
|
||||||
|
API_PACKAGES="
|
||||||
|
"
|
||||||
Executable
+19
@@ -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"
|
||||||
Executable
+56
@@ -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
|
||||||
@@ -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
|
|
||||||
@@ -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")
|
|
||||||
@@ -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 @
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# How to update swagger (OpenAPI) struct description
|
|
||||||
|
|
||||||
Run `update-generated-swagger-docs.sh` and it will parse all comments in `types.go`.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./update-generated-swagger-docs.sh
|
|
||||||
```
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2019 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.
|
|
||||||
*/
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Copyright 2016 The Kubernetes 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.
|
|
||||||
|
|
||||||
#
|
|
||||||
# Please refer https://github.com/kubernetes/kubernetes/tree/master/hack for original file
|
|
||||||
#
|
|
||||||
|
|
||||||
# Contains swagger related util functions.
|
|
||||||
#
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# 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
|
|
||||||
TMPFILE="${TMPDIR:-/tmp}/types_swagger_doc_generated.$(date +%s).go"
|
|
||||||
|
|
||||||
echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
|
|
||||||
|
|
||||||
{
|
|
||||||
echo -e "$(cat boilerplate.generatego.txt)\n"
|
|
||||||
echo "package ${group_version##*/}"
|
|
||||||
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-generated-swagger-docs.sh
|
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
|
|
||||||
EOF
|
|
||||||
} > "${TMPFILE}"
|
|
||||||
|
|
||||||
go run ./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}/types_swagger_doc_generated.go"
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Copyright 2015 The Kubernetes 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.
|
|
||||||
|
|
||||||
# Generates `types_swagger_doc_generated.go` files for API group
|
|
||||||
# versions. That file contains functions on API structs that return
|
|
||||||
# the comments that should be surfaced for the corresponding API type
|
|
||||||
# in our API docs.
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Please refer https://github.com/kubernetes/kubernetes/tree/master/hack for original file
|
|
||||||
#
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
FISSION_CRD_VERSION=v1
|
|
||||||
|
|
||||||
source "swagger.sh"
|
|
||||||
|
|
||||||
# To avoid compile errors, remove the currently existing files.
|
|
||||||
|
|
||||||
for group_version in "${FISSION_CRD_VERSION}"; do
|
|
||||||
kube::swagger::gen_types_swagger_doc "${group_version}" ../../${FISSION_CRD_VERSION}
|
|
||||||
done
|
|
||||||
+3
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2019 The Fission Authors.
|
Copyright The Fission Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
// This file contains a collection of methods that can be used from go-restful to
|
// This file contains a collection of methods that can be used from go-restful to
|
||||||
@@ -24,9 +23,8 @@ package v1
|
|||||||
// they are on one line! For multiple line or blocks that you want to ignore use ---.
|
// they are on one line! For multiple line or blocks that you want to ignore use ---.
|
||||||
// Any context after a --- is ignored.
|
// Any context after a --- is ignored.
|
||||||
//
|
//
|
||||||
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
|
// Those methods can be generated by using hack/update-swagger-docs.sh
|
||||||
|
// AUTO-GENERATED FUNCTIONS START HERE
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
|
|
||||||
var map_Archive = map[string]string{
|
var map_Archive = map[string]string{
|
||||||
"": "Archive contains or references a collection of source or binary files.",
|
"": "Archive contains or references a collection of source or binary files.",
|
||||||
"type": "Type defines how the package is specified: literal or URL. Available value:\n - literal\n - url",
|
"type": "Type defines how the package is specified: literal or URL. Available value:\n - literal\n - url",
|
||||||
+1
-7
@@ -1,12 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015 The Kubernetes Authors.
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@@ -14,10 +11,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
// lifted from k8s.io/kubernetes so we can add methods to types
|
||||||
// Please refer https://github.com/kubernetes/kubernetes/blob/master/cmd/genswaggertypedocs/swagger_type_docs.go for original file
|
|
||||||
//
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
Reference in New Issue
Block a user