k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/gen-swagger-doc/gen-swagger-docs.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2014 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Script to generate docs from the latest swagger spec. 18 19 set -o errexit 20 set -o nounset 21 set -o pipefail 22 23 cd /build 24 25 # gendocs takes "input.json" as the input swagger spec. 26 # $1 is expected to be <group>_<version> 27 cp /swagger-source/"$1".json input.json 28 29 ./gradle-2.5/bin/gradle gendocs --info 30 31 #insert a TOC for top level API objects 32 buf="== Top Level API Objects\n\n" 33 top_level_models=$(grep '&[A-Za-z]*{},' /register.go | sed 's/.*&//;s/{},//') 34 35 # check if the top level models exist in the definitions.adoc. If they exist, 36 # their name will be <version>.<model_name> 37 VERSION="${1#*_}" 38 for m in ${top_level_models} 39 do 40 if grep -xq "=== ${VERSION}.${m}" ./definitions.adoc 41 then 42 buf+="* <<${VERSION}.${m}>>\n" 43 fi 44 done 45 sed -i "1i ${buf}" ./definitions.adoc 46 47 # fix the links in .adoc, replace <<x.y>> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part 48 sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc 49 sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:../definitions#_\L\1_\2\E[\1.\2]|g' ./paths.adoc 50 51 # fix the link to <<any>> 52 sed -i -e 's|<<any>>|link:#_any[any]|g' ./definitions.adoc 53 sed -i -e 's|<<any>>|link:../definitions#_any[any]|g' ./paths.adoc 54 55 # change the title of paths.adoc from "paths" to "operations" 56 sed -i 's|== Paths|== Operations|g' ./paths.adoc 57 58 # $$ has special meaning in asciidoc, we need to escape it 59 sed -i 's|\$\$|+++$$+++|g' ./definitions.adoc 60 61 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 62 63 asciidoctor definitions.adoc 64 asciidoctor paths.adoc 65 66 cp definitions.html /output/ 67 cp paths.html /output/operations.html 68 69 echo "SUCCESS"