Skip to content

Commit 50bae0c

Browse files
Mo3m3noktalz
authored andcommitted
MINOR: cr: Update helper script for CR spec
1 parent fb118ea commit 50bae0c

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

crs/get-crd-schema.sh

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -o errexit
44
set -o pipefail
55

6+
command -v swagger >/dev/null 2>&1 || { echo >&2 "swagger not installed. Aborting."; exit 1; }
67
command -v yq >/dev/null 2>&1 || { echo >&2 "yq not installed. Aborting."; exit 1; }
78
command -v jq >/dev/null 2>&1 || { echo >&2 "jq not installed. Aborting."; exit 1; }
89

@@ -11,30 +12,22 @@ CN_COMMIT=$(go list -m github.com/haproxytech/client-native/v3 | sed 's/^.*-//')
1112
if [ -z "$1" ]; then echo >&2 "No model name supplied. Aborting."; exit 1; fi
1213
if [ -z "$CN_COMMIT" ]; then echo >&2 "Unable to get git commit for CN module. Aborting."; exit 1; fi
1314

14-
curl -sk https://raw.githubusercontent.com/haproxytech/client-native/$CN_COMMIT/specification/models/configuration.yaml |
15+
swagger expand https://raw.githubusercontent.com/haproxytech/client-native/$CN_COMMIT/specification/build/haproxy_spec.yaml |
1516
yq |
16-
jq --arg MODEL $1 '.|
17-
reduce paths as $p(.;
18-
if $p[0] == $MODEL and $p[-1] == "$ref" then
19-
setpath($p[0:-1];getpath(getpath($p) | split("/")[-1]| split(" ")))
20-
else
21-
.
22-
end
23-
) |
24-
.[$MODEL] |
25-
walk(
26-
if type == "object" then with_entries(
27-
if .key == "x-nullable" then
28-
if .value == false then
29-
empty
30-
else
31-
.key = "nullable"
32-
end
33-
elif (.key | contains("x-")) then
34-
empty
35-
else
36-
.
37-
end
38-
) else . end
39-
)' |
17+
jq --arg MODEL $1 '.["definitions"][$MODEL]|
18+
walk(
19+
if type == "object" then with_entries(
20+
if .key == "x-nullable" then
21+
if .value == false then
22+
empty
23+
else
24+
.key = "nullable"
25+
end
26+
elif (.key | contains("x-")) then
27+
empty
28+
else
29+
.
30+
end
31+
) else . end
32+
)' |
4033
yq -y

0 commit comments

Comments
 (0)