swagger.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Copyright 2016 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. # Contains swagger related util functions.
  16. #
  17. set -o errexit
  18. set -o nounset
  19. set -o pipefail
  20. # The root of the build/dist directory
  21. KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.." && pwd -P)"
  22. # Generates types_swagger_doc_generated file for the given group version.
  23. # $1: Name of the group version
  24. # $2: Path to the directory where types.go for that group version exists. This
  25. # is the directory where the file will be generated.
  26. kube::swagger::gen_types_swagger_doc() {
  27. local group_version=$1
  28. local gv_dir=$2
  29. local TMPFILE="${TMPDIR:-/tmp}/types_swagger_doc_generated.$(date +%s).go"
  30. echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
  31. echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" > "${TMPFILE}"
  32. echo "package ${group_version##*/}" >> "${TMPFILE}"
  33. cat >> "${TMPFILE}" <<EOF
  34. // This file contains a collection of methods that can be used from go-restful to
  35. // generate Swagger API documentation for its models. Please read this PR for more
  36. // information on the implementation: https://github.com/emicklei/go-restful/pull/215
  37. //
  38. // TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if
  39. // they are on one line! For multiple line or blocks that you want to ignore use ---.
  40. // Any context after a --- is ignored.
  41. //
  42. // Those methods can be generated by using hack/update-generated-swagger-docs.sh
  43. // AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT.
  44. EOF
  45. go run cmd/genswaggertypedocs/swagger_type_docs.go -s \
  46. "${gv_dir}/types.go" \
  47. -f - \
  48. >> "${TMPFILE}"
  49. echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${TMPFILE}"
  50. gofmt -w -s "${TMPFILE}"
  51. mv "${TMPFILE}" ""${gv_dir}"/types_swagger_doc_generated.go"
  52. }