From f9dfe67eebfe6862917890abe29cf5b98f9b2a80 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 20 Nov 2023 21:40:07 +0100 Subject: [PATCH] feat: generate multi-schema files for each API resource (#54) Reviewed-on: https://gitea.rknet.org/infra/crds-catalog/pulls/54 Co-authored-by: Robert Kaussow Co-committed-by: Robert Kaussow --- generate.sh | 16 ++++++++++++++++ templates/all.json.tmpl | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 templates/all.json.tmpl diff --git a/generate.sh b/generate.sh index cd51e45..e2c28a4 100755 --- a/generate.sh +++ b/generate.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s globstar +generate_all() { + export SOURCE=$1 + + export TYPE=anyOf + gomplate -d source=env:SOURCE -d type=env:TYPE -o "$SOURCE/all-$TYPE.json" -f templates/all.json.tmpl + + export TYPE=oneOf + gomplate -d source=env:SOURCE -d type=env:TYPE -o "$SOURCE/all-$TYPE.json" -f templates/all.json.tmpl +} + default_openapi_handler() { printf "Processing %s ...\n" $API mkdir -p "${WORKDIR}" @@ -19,6 +29,8 @@ default_openapi_handler() { mv "$FILE" "$TARGET_DIR/$FILENAME" done + + generate_all "$TARGET_DIR" } ## Calico @@ -43,6 +55,8 @@ for FILE in "${WORKDIR}"/*.json; do mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}" done +generate_all "$TARGET_DIR" + ## Flux2 API=toolkit.fluxcd.io WORKDIR="${TMP_CRD_DIR}/flux" @@ -64,6 +78,8 @@ for FILE in "${WORKDIR}"/*.json; do mkdir -p "$TARGET_DIR" mv "$FILE" "$TARGET_NAME" + + generate_all "$TARGET_DIR" done ## Cloudnative-PG diff --git a/templates/all.json.tmpl b/templates/all.json.tmpl new file mode 100644 index 0000000..4e87fef --- /dev/null +++ b/templates/all.json.tmpl @@ -0,0 +1,13 @@ +{ + "{{ ds "type" }}": [ + {{- $path := ds "source" }} + {{- $filelist := file.ReadDir $path }} + {{- $length := len $filelist}} + {{- range $i, $item := $filelist }} + {{- if $i }},{{ end }} + { + "$ref": "https://gitea.rknet.org/infra/crds-catalog/raw/branch/catalog/{{ $path | path.Base }}/{{ $item }}" + } + {{- end }} + ] +}