#!/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. set -o errexit set -o nounset set -o pipefail global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." source "$(KUBE_ROOT)/hack/lib/init.sh" kube::golang::setup_env make -C $(KUBE_ROOT) WHAT=cmd/genswaggertypedocs # Find binary global genswaggertypedocs := $[kube::util::find-binary "genswaggertypedocs] global gen_swagger_result := '0' global result := '0' proc find_files { find . -not '(' \ '(' \ -wholename './output' \ -o -wholename './_output' \ -o -wholename './_gopath' \ -o -wholename './release' \ -o -wholename './target' \ -o -wholename '*/third_party/*' \ -o -wholename '*/vendor/*' \ ')' -prune \ ')' \ '(' -wholename '*pkg/api/v*/types.go' \ -o -wholename '*pkg/apis/*/v*/types.go' \ -o -wholename '*pkg/api/unversioned/types.go' \ ')' } if [[ $# -eq 0 ]] { global versioned_api_files := $[find_files | egrep "pkg/.[^/]*/((v.[^/]*)|unversioned)/types\.go] } else { global versioned_api_files := $(*) } for file in [$versioned_api_files] { $genswaggertypedocs -v -s $(file) -f - || global gen_swagger_result := $Status if [[ "${gen_swagger_result}" -ne "0" ]] { echo "API file: $(file) is missing: $(gen_swagger_result) descriptions" global result := '1' } if grep json: $(file) | grep -v // | grep description: { echo "API file: $(file) should not contain descriptions in struct tags" global result := '1' } if grep json: $(file) | grep -Ee ",[[:space:]]+omitempty|omitempty[[:space:]]+" { echo "API file: $(file) should not contain leading or trailing spaces for omitempty directive" global result := '1' } } global internal_types_files := ""$(KUBE_ROOT)/pkg/api/types.go $(KUBE_ROOT)/pkg/apis/extensions/types.go"" for internal_types_file in [$internal_types_files] { if [[ ! -e $internal_types_file ]] { echo "Internal types file $(internal_types_file) does not exist" global result := '1' continue } if grep json: $(internal_types_file) | grep -v // | grep description: { echo "Internal API types should not contain descriptions" global result := '1' } } exit $(result) (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [64 72] ) (/..) } spids: [63] ) ] spids: [63] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/init.sh))}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (golang) (Lit_Other ":") (Lit_Other ":") (setup_env)}) (C {(make)} {(-C)} {(DQ (${ VSub_Name KUBE_ROOT))} {(Lit_VarLike "WHAT=") (cmd/genswaggertypedocs)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:genswaggertypedocs) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (find-binary) } {(DQ (genswaggertypedocs))} ) ] ) left_token: spids: [112 124] ) } spids: [111] ) ] spids: [111] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:gen_swagger_result) op:Equal rhs:{(0)} spids:[127])] spids: [127] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(0)} spids:[130])] spids: [130] ) (FuncDef name: find_files body: (BraceGroup children: [ (C {(find)} {(.)} {(-not)} {(EscapedLiteralPart token:)} {(EscapedLiteralPart token:)} {(-wholename)} {(SQ <./output>)} {(-o)} {(-wholename)} {(SQ <./_output>)} {(-o)} {(-wholename)} {(SQ <./_gopath>)} {(-o)} {(-wholename)} {(SQ <./release>)} {(-o)} {(-wholename)} {(SQ <./target>)} {(-o)} {(-wholename)} {(SQ <"*/third_party/*">)} {(-o)} {(-wholename)} {(SQ <"*/vendor/*">)} {(EscapedLiteralPart token:)} {(-prune)} {(EscapedLiteralPart token:)} {(EscapedLiteralPart token:)} {(-wholename)} {(SQ <"*pkg/api/v*/types.go">)} {(-o)} {(-wholename)} {(SQ <"*pkg/apis/*/v*/types.go">)} {(-o)} {(-wholename)} {(SQ <"*pkg/api/unversioned/types.go">)} {(EscapedLiteralPart token:)} ) ] spids: [138] ) spids: [134 137] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id:BoolBinary_eq left:{($ VSub_Pound "$#")} right:{(0)}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:versioned_api_files) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(find_files)}) (C {(egrep)} { (DQ ("pkg/.[^/]*/((v.[^/]*)|unversioned)/types") (EscapedLiteralPart token: ) (go) ) } ) ] negated: False ) ] ) left_token: spids: [285 297] ) } spids: [284] ) ] spids: [284] ) ] spids: [-1 281] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:versioned_api_files) op: Equal rhs: {(DQ (${ VSub_Star "*"))} spids: [302] ) ] spids: [302] ) ] spids: [299 309] ) (ForEach iter_name: file iter_words: [{($ VSub_Name "$versioned_api_files")}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (C {($ VSub_Name "$genswaggertypedocs")} {(-v)} {(-s)} {(DQ (${ VSub_Name file))} {(-f)} {(-)} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:gen_swagger_result) op: Equal rhs: {($ VSub_QMark "$?")} spids: [342] ) ] spids: [342] ) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_ne left: {(DQ (${ VSub_Name gen_swagger_result))} right: {(DQ (0))} ) ) terminator: ) ] action: [ (C {(echo)} { (DQ ("API file: ") (${ VSub_Name file) (" is missing: ") (${ VSub_Name gen_swagger_result) (" descriptions") ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[383])] spids: [383] ) ] spids: [-1 365] ) ] spids: [-1 387] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(grep)} {(json) (Lit_Other ":")} {(DQ (${ VSub_Name file))}) (C {(grep)} {(-v)} {(//)}) (C {(grep)} {(description) (Lit_Other ":")}) ] negated: False ) terminator: ) ] action: [ (C {(echo)} { (DQ ("API file: ") (${ VSub_Name file) (" should not contain descriptions in struct tags") ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[434])] spids: [434] ) ] spids: [-1 420] ) ] spids: [-1 438] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(grep)} {(json) (Lit_Other ":")} {(DQ (${ VSub_Name file))}) (C {(grep)} {(-Ee)} {(DQ (",[[:space:]]+omitempty|omitempty[[:space:]]+"))}) ] negated: False ) terminator: ) ] action: [ (C {(echo)} { (DQ ("API file: ") (${ VSub_Name file) ( " should not contain leading or trailing spaces for omitempty directive" ) ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[480])] spids: [480] ) ] spids: [-1 466] ) ] spids: [-1 484] ) ] spids: [321 486] ) spids: [317 319] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:internal_types_files) op: Equal rhs: { (DQ (${ VSub_Name KUBE_ROOT) ("/pkg/api/types.go ") (${ VSub_Name KUBE_ROOT) (/pkg/apis/extensions/types.go) ) } spids: [489] ) ] spids: [489] ) (ForEach iter_name: internal_types_file iter_words: [{($ VSub_Name "$internal_types_files")}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_e child: {($ VSub_Name "$internal_types_file")} ) ) ) terminator: ) ] action: [ (C {(echo)} { (DQ ("Internal types file ") (${ VSub_Name internal_types_file) (" does not exist") ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[540])] spids: [540] ) (ControlFlow token:) ] spids: [-1 526] ) ] spids: [-1 547] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(grep)} {(json) (Lit_Other ":")} {(DQ (${ VSub_Name internal_types_file))} ) (C {(grep)} {(-v)} {(//)}) (C {(grep)} {(description) (Lit_Other ":")}) ] negated: False ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Internal API types should not contain descriptions"))}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[591])] spids: [591] ) ] spids: [-1 581] ) ] spids: [-1 595] ) ] spids: [510 597] ) spids: [506 508] ) (C {(exit)} {(${ VSub_Name result)}) ] )