verify-description.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Copyright 2014 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. kube::golang::setup_env
  21. make -C "${KUBE_ROOT}" WHAT=cmd/genswaggertypedocs
  22. # Find binary
  23. genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs")
  24. gen_swagger_result=0
  25. result=0
  26. find_files() {
  27. find . -not \( \
  28. \( \
  29. -wholename './output' \
  30. -o -wholename './_output' \
  31. -o -wholename './_gopath' \
  32. -o -wholename './release' \
  33. -o -wholename './target' \
  34. -o -wholename '*/third_party/*' \
  35. -o -wholename '*/vendor/*' \
  36. \) -prune \
  37. \) \
  38. \( -wholename '*pkg/api/v*/types.go' \
  39. -o -wholename '*pkg/apis/*/v*/types.go' \
  40. -o -wholename '*pkg/api/unversioned/types.go' \
  41. \)
  42. }
  43. if [[ $# -eq 0 ]]; then
  44. versioned_api_files=$(find_files | egrep "pkg/.[^/]*/((v.[^/]*)|unversioned)/types\.go")
  45. else
  46. versioned_api_files="${*}"
  47. fi
  48. for file in $versioned_api_files; do
  49. $genswaggertypedocs -v -s "${file}" -f - || gen_swagger_result=$?
  50. if [[ "${gen_swagger_result}" -ne "0" ]]; then
  51. echo "API file: ${file} is missing: ${gen_swagger_result} descriptions"
  52. result=1
  53. fi
  54. if grep json: "${file}" | grep -v // | grep description: ; then
  55. echo "API file: ${file} should not contain descriptions in struct tags"
  56. result=1
  57. fi
  58. if grep json: "${file}" | grep -Ee ",[[:space:]]+omitempty|omitempty[[:space:]]+" ; then
  59. echo "API file: ${file} should not contain leading or trailing spaces for omitempty directive"
  60. result=1
  61. fi
  62. done
  63. internal_types_files="${KUBE_ROOT}/pkg/api/types.go ${KUBE_ROOT}/pkg/apis/extensions/types.go"
  64. for internal_types_file in $internal_types_files; do
  65. if [[ ! -e $internal_types_file ]]; then
  66. echo "Internal types file ${internal_types_file} does not exist"
  67. result=1
  68. continue
  69. fi
  70. if grep json: "${internal_types_file}" | grep -v // | grep description: ; then
  71. echo "Internal API types should not contain descriptions"
  72. result=1
  73. fi
  74. done
  75. exit ${result}