swagger.sh 2.2 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. # Generates types_swagger_doc_generated file for the given group version.
  21. # $1: Name of the group version
  22. # $2: Path to the directory where types.go for that group version exists. This
  23. # is the directory where the file will be generated.
  24. kube::swagger::gen_types_swagger_doc() {
  25. local group_version=$1
  26. local gv_dir=$2
  27. local TMPFILE
  28. TMPFILE="${TMPDIR:-/tmp}/types_swagger_doc_generated.$(date +%s).go"
  29. echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
  30. {
  31. echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n"
  32. echo "package ${group_version##*/}"
  33. cat <<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. } > "${TMPFILE}"
  46. go run cmd/genswaggertypedocs/swagger_type_docs.go -s \
  47. "${gv_dir}/types.go" \
  48. -f - \
  49. >> "${TMPFILE}"
  50. echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${TMPFILE}"
  51. gofmt -w -s "${TMPFILE}"
  52. mv "${TMPFILE}" "${gv_dir}/types_swagger_doc_generated.go"
  53. }