feat: generate multi-schema files for each API resource (#54)
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #54
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
Co-committed-by: Robert Kaussow <mail@thegeeklab.de>
This commit is contained in:
Robert Kaussow 2023-11-20 21:40:07 +01:00 committed by Robert Kaussow
parent b453296209
commit f9dfe67eeb
2 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,16 @@
set -eo pipefail set -eo pipefail
shopt -s globstar 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() { default_openapi_handler() {
printf "Processing %s ...\n" $API printf "Processing %s ...\n" $API
mkdir -p "${WORKDIR}" mkdir -p "${WORKDIR}"
@ -19,6 +29,8 @@ default_openapi_handler() {
mv "$FILE" "$TARGET_DIR/$FILENAME" mv "$FILE" "$TARGET_DIR/$FILENAME"
done done
generate_all "$TARGET_DIR"
} }
## Calico ## Calico
@ -43,6 +55,8 @@ for FILE in "${WORKDIR}"/*.json; do
mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}" mv "$FILE" "$TARGET_DIR/${FILENAME//_v1/_v3}"
done done
generate_all "$TARGET_DIR"
## Flux2 ## Flux2
API=toolkit.fluxcd.io API=toolkit.fluxcd.io
WORKDIR="${TMP_CRD_DIR}/flux" WORKDIR="${TMP_CRD_DIR}/flux"
@ -64,6 +78,8 @@ for FILE in "${WORKDIR}"/*.json; do
mkdir -p "$TARGET_DIR" mkdir -p "$TARGET_DIR"
mv "$FILE" "$TARGET_NAME" mv "$FILE" "$TARGET_NAME"
generate_all "$TARGET_DIR"
done done
## Cloudnative-PG ## Cloudnative-PG

13
templates/all.json.tmpl Normal file
View File

@ -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 }}
]
}