Browse code

Added verification script for Swagger API object descriptions

Steve Kuznetsov authored on 2015/07/23 00:29:47
Showing 5 changed files
... ...
@@ -65,6 +65,7 @@ check-test:
65 65
 	hack/verify-generated-completions.sh
66 66
 	hack/verify-generated-docs.sh
67 67
 	hack/verify-generated-swagger-spec.sh
68
+	hack/verify-api-descriptions.sh
68 69
 	hack/test-cmd.sh
69 70
 	KUBE_RACE=" " hack/test-integration.sh
70 71
 .PHONY: check-test
... ...
@@ -93,6 +94,7 @@ test:
93 93
 	hack/verify-generated-completions.sh
94 94
 	hack/verify-generated-docs.sh
95 95
 	hack/verify-generated-swagger-spec.sh
96
+	hack/verify-api-descriptions.sh
96 97
 	hack/test-cmd.sh
97 98
 	KUBE_RACE=" " hack/test-integration-docker.sh
98 99
 	hack/test-end-to-end-docker.sh
99 100
new file mode 100644
... ...
@@ -0,0 +1,221 @@
0
+## ---------------------------------------------- ##
1
+## THIS WHITELIST ALLOWS FOR THE VERIFY SCRIPT TO ##
2
+## SUCCEED WHILE DESCRIPTIONS ARE ADDED. IF A NEW ##
3
+## DESCRIPTION IS ADDED, THE CORRESPONDING ENTRY  ##
4
+## IN THIS LIST SHOULD BE REMOVED.                ##
5
+## ADDING NEW ENTRIES TO THIS LIST IS DISALLOWED  ##
6
+## ---------------------------------------------- ##
7
+api.patch
8
+integer
9
+json.watchevent
10
+patch.object
11
+runtime.rawextension
12
+v1.awselasticblockstorevolumesource
13
+v1.binding
14
+v1.build
15
+v1.buildconfiglist
16
+v1.buildconfigspec
17
+v1.buildconfigstatus
18
+v1.buildlist
19
+v1.buildlog
20
+v1.buildoutput
21
+v1.buildrequest
22
+v1.buildsource
23
+v1.buildspec
24
+v1.buildstatus
25
+v1.buildstrategy
26
+v1.buildtriggerpolicy
27
+v1.capabilities
28
+v1.capability
29
+v1.cephfsvolumesource
30
+v1.clusternetwork
31
+v1.clusternetworklist
32
+v1.clusterpolicy
33
+v1.clusterpolicybinding
34
+v1.clusterpolicybindinglist
35
+v1.clusterpolicylist
36
+v1.clusterrole
37
+v1.clusterrolebinding
38
+v1.clusterrolebindinglist
39
+v1.clusterrolelist
40
+v1.componentcondition
41
+v1.componentstatus
42
+v1.componentstatuslist
43
+v1.container
44
+v1.containerport
45
+v1.containerstate
46
+v1.containerstaterunning
47
+v1.containerstateterminated
48
+v1.containerstatewaiting
49
+v1.containerstatus
50
+v1.custombuildstrategy
51
+v1.customdeploymentstrategyparams
52
+v1.deleteoptions
53
+v1.deploymentcause
54
+v1.deploymentcauseimagetrigger
55
+v1.deploymentconfiglist
56
+v1.deploymentconfigrollback
57
+v1.deploymentconfigrollbackspec
58
+v1.deploymentconfigspec
59
+v1.deploymentconfigstatus
60
+v1.deploymentdetails
61
+v1.deploymentstrategy
62
+v1.deploymenttriggerimagechangeparams
63
+v1.deploymenttriggerpolicy
64
+v1.dockerbuildstrategy
65
+v1.emptydirvolumesource
66
+v1.endpointaddress
67
+v1.endpointport
68
+v1.endpoints
69
+v1.endpointslist
70
+v1.endpointsubset
71
+v1.envvar
72
+v1.envvarsource
73
+v1.event
74
+v1.eventlist
75
+v1.eventsource
76
+v1.execaction
77
+v1.execnewpodhook
78
+v1.finalizername
79
+v1.gcepersistentdiskvolumesource
80
+v1.gitbuildsource
81
+v1.gitrepovolumesource
82
+v1.gitsourcerevision
83
+v1.glusterfsvolumesource
84
+v1.group
85
+v1.grouplist
86
+v1.handler
87
+v1.hostpathvolumesource
88
+v1.hostsubnet
89
+v1.hostsubnetlist
90
+v1.httpgetaction
91
+v1.identity
92
+v1.identitylist
93
+v1.image
94
+v1.imagechangetrigger
95
+v1.imagelist
96
+v1.imagestream
97
+v1.imagestreamimage
98
+v1.imagestreamlist
99
+v1.imagestreammapping
100
+v1.imagestreamspec
101
+v1.imagestreamstatus
102
+v1.imagestreamtag
103
+v1.iscsivolumesource
104
+v1.lifecycle
105
+v1.lifecyclehook
106
+v1.limitrange
107
+v1.limitrangeitem
108
+v1.limitrangelist
109
+v1.limitrangespec
110
+v1.listmeta
111
+v1.loadbalanceringress
112
+v1.loadbalancerstatus
113
+v1.localobjectreference
114
+v1.metadatafile
115
+v1.metadatavolumesource
116
+v1.namedclusterrole
117
+v1.namedclusterrolebinding
118
+v1.namedrole
119
+v1.namedrolebinding
120
+v1.namedtageventlist
121
+v1.namedtagreference
122
+v1.namespace
123
+v1.namespacelist
124
+v1.namespacespec
125
+v1.namespacestatus
126
+v1.nfsvolumesource
127
+v1.nodeaddress
128
+v1.nodecondition
129
+v1.nodelist
130
+v1.nodespec
131
+v1.nodestatus
132
+v1.nodesysteminfo
133
+v1.oauthaccesstoken
134
+v1.oauthaccesstokenlist
135
+v1.oauthauthorizetoken
136
+v1.oauthauthorizetokenlist
137
+v1.oauthclient
138
+v1.oauthclientauthorization
139
+v1.oauthclientauthorizationlist
140
+v1.oauthclientlist
141
+v1.objectfieldselector
142
+v1.objectmeta
143
+v1.objectreference
144
+v1.parameter
145
+v1.persistentvolumeaccessmode
146
+v1.persistentvolumeclaimlist
147
+v1.persistentvolumeclaimspec
148
+v1.persistentvolumeclaimstatus
149
+v1.persistentvolumeclaimvolumesource
150
+v1.persistentvolumelist
151
+v1.persistentvolumespec
152
+v1.persistentvolumestatus
153
+v1.podcondition
154
+v1.podlist
155
+v1.podspec
156
+v1.podstatus
157
+v1.podtemplate
158
+v1.podtemplatelist
159
+v1.podtemplatespec
160
+v1.policy
161
+v1.policybinding
162
+v1.policybindinglist
163
+v1.policylist
164
+v1.policyrule
165
+v1.probe
166
+v1.projectlist
167
+v1.projectrequest
168
+v1.projectspec
169
+v1.projectstatus
170
+v1.rbdvolumesource
171
+v1.recreatedeploymentstrategyparams
172
+v1.replicationcontroller
173
+v1.replicationcontrollerlist
174
+v1.replicationcontrollerspec
175
+v1.replicationcontrollerstatus
176
+v1.resourceaccessreview
177
+v1.resourcequota
178
+v1.resourcequotalist
179
+v1.resourcequotaspec
180
+v1.resourcequotastatus
181
+v1.resourcerequirements
182
+v1.role
183
+v1.rolebinding
184
+v1.rolebindinglist
185
+v1.rolelist
186
+v1.rollingdeploymentstrategyparams
187
+v1.routespec
188
+v1.routestatus
189
+v1.runasuserstrategyoptions
190
+v1.secret
191
+v1.secretlist
192
+v1.secretvolumesource
193
+v1.securitycontext
194
+v1.securitycontextconstraints
195
+v1.securitycontextconstraintslist
196
+v1.selinuxcontextstrategyoptions
197
+v1.selinuxoptions
198
+v1.serviceaccount
199
+v1.serviceaccountlist
200
+v1.servicelist
201
+v1.serviceport
202
+v1.servicespec
203
+v1.servicestatus
204
+v1.sourcebuildstrategy
205
+v1.sourcecontroluser
206
+v1.sourcerevision
207
+v1.status
208
+v1.statuscause
209
+v1.statusdetails
210
+v1.subjectaccessreview
211
+v1.tagevent
212
+v1.tcpsocketaction
213
+v1.template
214
+v1.templatelist
215
+v1.tlsconfig
216
+v1.useridentitymapping
217
+v1.userlist
218
+v1.volume
219
+v1.volumemount
220
+v1.webhooktrigger
0 221
new file mode 100644
... ...
@@ -0,0 +1,13 @@
0
+import json;
1
+import sys;
2
+import string;
3
+
4
+if len(sys.argv)!=2:
5
+	print("Useage: python hack/list-swagger-objects.py <swagger-spec-location>")
6
+	sys.exit(1)
7
+
8
+swagger_spec_location=sys.argv[1]
9
+
10
+with open(swagger_spec_location, 'r') as source:
11
+	for model in json.load(source)["models"]:
12
+		print(string.lower(model))
0 13
\ No newline at end of file
... ...
@@ -61,8 +61,15 @@ popd > /dev/null
61 61
 wait_for_url "${HOST}/healthz" "apiserver: " 0.25 80
62 62
 
63 63
 echo "Updating ${SWAGGER_SPEC_OUT_DIR}:"
64
-echo "Updating ${SWAGGER_SPEC_OUT_DIR}/oapi-v1.json from ${SWAGGER_API_PATH}oapi/v1..."
65
-curl "${SWAGGER_API_PATH}oapi/v1" > "${SWAGGER_SPEC_OUT_DIR}/oapi-v1.json"
66
-echo "Updating ${SWAGGER_SPEC_OUT_DIR}/api-v1.json from ${SWAGGER_API_PATH}api/v1..."
67
-curl "${SWAGGER_API_PATH}api/v1" > "${SWAGGER_SPEC_OUT_DIR}/api-v1.json"
64
+
65
+ENDPOINT_TYPES="oapi api"
66
+for type in $ENDPOINT_TYPES
67
+do
68
+    ENDPOINTS=$(curl "${HOST}" | grep -Po "(?<=\/${type}\/)[a-z0-9]+" | sed '/v1beta3/d')
69
+    for endpoint in $ENDPOINTS
70
+    do
71
+        echo "Updating ${SWAGGER_SPEC_OUT_DIR}/${type}-${endpoint}.json from ${SWAGGER_API_PATH}${type}/${endpoint}..."
72
+        curl "${SWAGGER_API_PATH}${type}/${endpoint}" > "${SWAGGER_SPEC_OUT_DIR}/${type}-${endpoint}.json"    
73
+    done
74
+done
68 75
 echo "SUCCESS"
69 76
\ No newline at end of file
70 77
new file mode 100755
... ...
@@ -0,0 +1,66 @@
0
+#!/bin/bash
1
+
2
+set -o errexit
3
+set -o nounset
4
+set -o pipefail
5
+
6
+OS_ROOT=$(dirname "${BASH_SOURCE}")/..
7
+source "${OS_ROOT}/hack/common.sh"
8
+
9
+cd "${OS_ROOT}"
10
+
11
+DEF_MISSING=false
12
+UPDATE_WHITELIST=false
13
+
14
+function verify-api-descriptions-for-spec ()
15
+{
16
+	SPEC=$1
17
+	echo "Verifying Descriptions for Spec: ${SPEC}"
18
+	OBJECTS=$(python hack/list-swagger-objects.py ${SPEC})
19
+	for object in $OBJECTS
20
+	do
21
+		desc_location="api/definitions/${object}"
22
+		if [ -d "${desc_location}" ]
23
+		then
24
+			if [ ! -s "${desc_location}/description.adoc" ]
25
+			then
26
+				if ! grep -qx "^${object}$" hack/api-description-whitelist.txt
27
+				then
28
+					echo "Description missing for: ${object}"
29
+					DEF_MISSING=true
30
+				fi
31
+			else
32
+				if grep -qx "^${object}$" hack/api-description-whitelist.txt
33
+				then
34
+					echo "Unnecessary whitelist entry for: ${object}"
35
+					UPDATE_WHITELIST=true
36
+				fi
37
+			fi
38
+		else
39
+			if ! grep -q "${object}" hack/api-description-whitelist.txt
40
+			then
41
+				echo "Description missing for: ${object}"
42
+				DEF_MISSING=true
43
+			fi
44
+		fi
45
+	done
46
+}
47
+
48
+SPECS="${OS_ROOT}/api/swagger-spec/*.json"
49
+for spec in $SPECS
50
+do
51
+	verify-api-descriptions-for-spec $spec
52
+done
53
+
54
+if $DEF_MISSING || $UPDATE_WHITELIST
55
+then
56
+	if $DEF_MISSING
57
+	then
58
+		echo "FAILURE: Add missing descriptions to api/definitions"
59
+	else
60
+		echo "FAILURE: Prune unnecessary whitelist entries"
61
+	fi
62
+	exit 1
63
+else
64
+	echo SUCCESS
65
+fi
0 66
\ No newline at end of file