...
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
19set -o errexit
20set -o nounset
21set -o pipefail
22
23cd /build
24
25# gendocs takes "input.json" as the input swagger spec.
26# $1 is expected to be <group>_<version>
27cp /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
32buf="== Top Level API Objects\n\n"
33top_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>
37VERSION="${1#*_}"
38for m in ${top_level_models}
39do
40 if grep -xq "=== ${VERSION}.${m}" ./definitions.adoc
41 then
42 buf+="* <<${VERSION}.${m}>>\n"
43 fi
44done
45sed -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
48sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc
49sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:../definitions#_\L\1_\2\E[\1.\2]|g' ./paths.adoc
50
51# fix the link to <<any>>
52sed -i -e 's|<<any>>|link:#_any[any]|g' ./definitions.adoc
53sed -i -e 's|<<any>>|link:../definitions#_any[any]|g' ./paths.adoc
54
55# change the title of paths.adoc from "paths" to "operations"
56sed -i 's|== Paths|== Operations|g' ./paths.adoc
57
58# $$ has special meaning in asciidoc, we need to escape it
59sed -i 's|\$\$|+++$$+++|g' ./definitions.adoc
60
61echo -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
63asciidoctor definitions.adoc
64asciidoctor paths.adoc
65
66cp definitions.html /output/
67cp paths.html /output/operations.html
68
69echo "SUCCESS"
View as plain text