#!/bin/bash # Copyright 2014 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Script to generate docs from the latest swagger spec. set -o errexit set -o nounset set -o pipefail cd /build # gendocs takes "input.json" as the input swagger spec. # $1 is expected to be _ cp /swagger-source/"$1".json input.json ./gradle-2.5/bin/gradle gendocs --info #insert a TOC for top level API objects global buf := '"== Top Level API Objects\n'\n" global top_level_models := $[grep '&[A-Za-z]*{},' /register.go | sed 's/.*&//;s/{},//] # check if the top level models exist in the definitions.adoc. If they exist, # their name will be . global VERSION := $(1#*_) for m in [$top_level_models] { if grep -xq "=== $(VERSION).$m" ./definitions.adoc { global buf := ""* <<$(VERSION).$m>>"\n" } } sed -i "1i $buf" ./definitions.adoc # fix the links in .adoc, replace <> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:../definitions#_\L\1_\2\E[\1.\2]|g' ./paths.adoc # fix the link to <> sed -i -e 's|<>|link:#_any[any]|g' ./definitions.adoc sed -i -e 's|<>|link:../definitions#_any[any]|g' ./paths.adoc # change the title of paths.adoc from "paths" to "operations" sed -i 's|== Paths|== Operations|g' ./paths.adoc # $$ has special meaning in asciidoc, we need to escape it sed -i 's|\$\$|+++$$+++|g' ./definitions.adoc 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 asciidoctor definitions.adoc asciidoctor paths.adoc cp definitions.html /output/ cp paths.html /output/operations.html echo "SUCCESS" (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (C {(cd)} {(/build)}) (C {(cp)} {(/swagger-source/) (DQ ($ VSub_Number "$1")) (.json)} {(input.json)}) (C {(./gradle-2.5/bin/gradle)} {(gendocs)} {(--info)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:buf) op: Equal rhs: { (DQ ("== Top Level API Objects") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ) } spids: [99] ) ] spids: [99] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:top_level_models) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(SQ <"&[A-Za-z]*{},">)} {(/register.go)}) (C {(sed)} {(SQ <"s/.*&//;s/{},//">)}) ] negated: False ) ] ) left_token: spids: [107 123] ) } spids: [106] ) ] spids: [106] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:VERSION) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Pound arg_word:{("*_")}) spids: [134 138] ) ) } spids: [132] ) ] spids: [132] ) (ForEach iter_name: m iter_words: [{($ VSub_Name "$top_level_models")}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (C {(grep)} {(-xq)} {(DQ ("=== ") (${ VSub_Name VERSION) (.) ($ VSub_Name "$m"))} {(./definitions.adoc)} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:buf) op: PlusEqual rhs: { (DQ ("* <<") (${ VSub_Name VERSION) (.) ($ VSub_Name "$m") (">>") (EscapedLiteralPart token: ) ) } spids: [173] ) ] spids: [173] ) ] spids: [-1 170] ) ] spids: [-1 186] ) ] spids: [149 188] ) spids: [146 -1] ) (C {(sed)} {(-i)} {(DQ ("1i ") ($ VSub_Name "$buf"))} {(./definitions.adoc)}) (C {(sed)} {(-i)} {(-e)} {(SQ <"s|<<\\(.*\\)\\.\\(.*\\)>>|link:#_\\L\\1_\\2\\E[\\1.\\2]|g">)} {(./definitions.adoc)} ) (C {(sed)} {(-i)} {(-e)} {(SQ <"s|<<\\(.*\\)\\.\\(.*\\)>>|link:../definitions#_\\L\\1_\\2\\E[\\1.\\2]|g">)} {(./paths.adoc)} ) (C {(sed)} {(-i)} {(-e)} {(SQ <"s|<>|link:#_any[any]|g">)} {(./definitions.adoc)}) (C {(sed)} {(-i)} {(-e)} {(SQ <"s|<>|link:../definitions#_any[any]|g">)} {(./paths.adoc)}) (C {(sed)} {(-i)} {(SQ <"s|== Paths|== Operations|g">)} {(./paths.adoc)}) (C {(sed)} {(-i)} {(SQ <"s|\\$\\$|+++$$+++|g">)} {(./definitions.adoc)}) (SimpleCommand words: [ {(echo)} {(-e)} { (DQ ("=== any") (EscapedLiteralPart token:) ( "Represents an untyped JSON map - see the description of the field for more info about the structure of this object." ) ) } ] redirects: [(Redir op_id:Redir_DGreat fd:-1 arg_word:{(./definitions.adoc)} spids:[296])] ) (C {(asciidoctor)} {(definitions.adoc)}) (C {(asciidoctor)} {(paths.adoc)}) (C {(cp)} {(definitions.html)} {(/output/)}) (C {(cp)} {(paths.html)} {(/output/operations.html)}) (C {(echo)} {(DQ (SUCCESS))}) ] )