gen-swagger-docs.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env 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. # Script to generate docs from the latest swagger spec.
  16. set -o errexit
  17. set -o nounset
  18. set -o pipefail
  19. cd /build
  20. # gendocs takes "input.json" as the input swagger spec.
  21. # $1 is expected to be <group>_<version>
  22. cp /swagger-source/"$1".json input.json
  23. ./gradle-2.5/bin/gradle gendocs --info
  24. #insert a TOC for top level API objects
  25. buf="== Top Level API Objects\n\n"
  26. top_level_models=$(grep '&[A-Za-z]*{},' /register.go | sed 's/.*&//;s/{},//')
  27. # check if the top level models exist in the definitions.adoc. If they exist,
  28. # their name will be <version>.<model_name>
  29. VERSION="${1#*_}"
  30. for m in ${top_level_models}
  31. do
  32. if grep -xq "=== ${VERSION}.${m}" ./definitions.adoc
  33. then
  34. buf+="* <<${VERSION}.${m}>>\n"
  35. fi
  36. done
  37. sed -i "1i ${buf}" ./definitions.adoc
  38. # fix the links in .adoc, replace <<x.y>> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part
  39. sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc
  40. sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:../definitions#_\L\1_\2\E[\1.\2]|g' ./paths.adoc
  41. # fix the link to <<any>>
  42. sed -i -e 's|<<any>>|link:#_any[any]|g' ./definitions.adoc
  43. sed -i -e 's|<<any>>|link:../definitions#_any[any]|g' ./paths.adoc
  44. # change the title of paths.adoc from "paths" to "operations"
  45. sed -i 's|== Paths|== Operations|g' ./paths.adoc
  46. # $$ has special meaning in asciidoc, we need to escape it
  47. sed -i 's|\$\$|+++$$+++|g' ./definitions.adoc
  48. echo -e "=== any\nRepresents an untyped JSON map - see the description of the field for more info about the structure of this object." >> ./definitions.adoc
  49. asciidoctor definitions.adoc
  50. asciidoctor paths.adoc
  51. cp definitions.html /output/
  52. cp paths.html /output/operations.html
  53. echo "SUCCESS"