@@ -57,124 +57,3 @@ We should be able to find the following:
57
57
- Namespaced if any possible path contains ` /namespaces/{namespace}/ `
58
58
- May also have paths for all namespaces for some verbs (e.g., ` list ` all pods)
59
59
- Subresource if path contains ` /{name}/ ` (` / ` after ` {name} ` )
60
-
61
- ### Transforming
62
-
63
- Transform ` swagger.json ` to something easier to explore.
64
-
65
- #### Like APIResourceList
66
-
67
- ``` bash
68
- cat swagger.json \
69
- | jq -f list-resources.jq \
70
- > api-resources.json
71
- ```
72
-
73
- ``` bash
74
- cat swagger.json | jq -f list-resources.jq | jq ' .[0]'
75
- ```
76
-
77
- ``` json
78
- {
79
- "apiGroupVersion" : " admissionregistration.k8s.io/v1" ,
80
- "resources" : [
81
- {
82
- "name" : " mutatingwebhookconfigurations" ,
83
- "namespaced" : false ,
84
- "apiGroupVersion" : " admissionregistration.k8s.io/v1" ,
85
- "group" : " admissionregistration.k8s.io" ,
86
- "version" : " v1" ,
87
- "kind" : " MutatingWebhookConfiguration" ,
88
- "verbs" : [
89
- " create" ,
90
- " delete" ,
91
- " deletecollection" ,
92
- " get" ,
93
- " list" ,
94
- " patch" ,
95
- " update"
96
- ]
97
- },
98
- {
99
- "name" : " validatingwebhookconfigurations" ,
100
- "namespaced" : false ,
101
- "apiGroupVersion" : " admissionregistration.k8s.io/v1" ,
102
- "group" : " admissionregistration.k8s.io" ,
103
- "version" : " v1" ,
104
- "kind" : " ValidatingWebhookConfiguration" ,
105
- "verbs" : [
106
- " create" ,
107
- " delete" ,
108
- " deletecollection" ,
109
- " get" ,
110
- " list" ,
111
- " patch" ,
112
- " update"
113
- ]
114
- }
115
- ]
116
- }
117
- ```
118
-
119
- #### Paths
120
-
121
- ``` typescript
122
- type ResourcePath = {
123
- // Request path.
124
- path: string ;
125
- // `x-kubernetes-action` or `method`.
126
- verb: string ;
127
- // Group and version of API. Can be different from `group` and `version` for subresources.
128
- apiGroupVersion: string ;
129
- // GVK
130
- group: string ;
131
- version: string ;
132
- kind: string ;
133
- // True if the path contains `/namespaces/{namespace}/`
134
- namespaced: boolean ;
135
- // True if the path contains a segment after `{name}`.
136
- subresource: boolean ;
137
- // MIME types of supported content types. Comma separated.
138
- consumes: string ;
139
- // MIME types of supported responses. Comma separated.
140
- produces: string ;
141
- // Plural name. Includes subresources like APIResourceList.
142
- name: string ;
143
- };
144
- ```
145
-
146
- ``` bash
147
- cat swagger.json | jq -f list-paths.jq
148
- ```
149
-
150
- ``` bash
151
- cat swagger.json \
152
- | jq -f list-paths.jq \
153
- | jq ' map(select(.kind == "Pod" and .verb == "get" and .subresource == false))'
154
- ```
155
-
156
- ``` json
157
- [
158
- {
159
- "path" : " /api/v1/namespaces/{namespace}/pods/{name}" ,
160
- "verb" : " get" ,
161
- "apiGroupVersion" : " v1" ,
162
- "group" : " " ,
163
- "version" : " v1" ,
164
- "kind" : " Pod" ,
165
- "namespaced" : true ,
166
- "subresource" : false ,
167
- "consumes" : " */*" ,
168
- "produces" : " application/json, application/yaml, application/vnd.kubernetes.protobuf" ,
169
- "name" : " pods"
170
- }
171
- ]
172
- ```
173
-
174
- Group by ` name ` :
175
-
176
- ``` bash
177
- cat swagger.json \
178
- | jq -f list-paths.jq \
179
- | jq ' group_by(.name)'
180
- ```
0 commit comments