Skip to content

Commit 36d8889

Browse files
committed
Use jq to patch swagger.json
Remove `gron` dependency and make it easier to maintain patches.
1 parent 1350ff7 commit 36d8889

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Experimenting with Kubernetes protobufs.
22

33
## Build Dependencies
44

5-
- [gron](https://github.com/tomnomnom/gron)
65
- [just](https://github.com/casey/just)
76
- [sd](https://github.com/chmln/sd)
87
- [jq](https://stedolan.github.io/jq/)

justfile

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ swagger-patch:
4343
#!/usr/bin/env bash
4444
set -exuo pipefail
4545
cd openapi
46-
# Fix path operation annotated with a `x-kubernetes-group-version-kind` that references a type that doesn't exist in the schema.
47-
# See https://github.com/Arnavion/k8s-openapi/blob/445e89ec444ebb1c68e61361e64eec4c4a3f4785/k8s-openapi-codegen/src/fixups/upstream_bugs.rs#L9
48-
gron swagger.json \
49-
| perl -pe 's/(?<=kind = ")(Pod|Node|Service)(?:Attach|Exec|PortForward|Proxy)Options(?=")/$1/' \
50-
| gron -u \
51-
> swagger-patched.json
46+
jq -f patches/patch-nonexistent-gvk.jq < swagger.json > swagger-patched.json
5247
mv swagger-patched.json swagger.json
5348

5449
# Transform swagger schema into api-resources.json
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Fix path operation annotated with a `x-kubernetes-group-version-kind` that references a type that doesn't exist in the schema.
2+
# See https://github.com/Arnavion/k8s-openapi/blob/445e89ec444ebb1c68e61361e64eec4c4a3f4785/k8s-openapi-codegen/src/fixups/upstream_bugs.rs#L9
3+
(.paths | .. | objects | select((.group? == "") and (.version? == "v1") and (.kind? | type) == "string")).kind |= (
4+
if . | test("^Pod(?:Attach|Exec|PortForward|Proxy)Options$") then
5+
"Pod"
6+
elif . == "NodeProxyOptions" then
7+
"Node"
8+
elif . == "ServiceProxyOptions" then
9+
"Service"
10+
else
11+
.
12+
end
13+
)

0 commit comments

Comments
 (0)