graphql-engine/metadata-api-types/scripts/generate-typescript-types.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
902 B
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# Get path to schema file as an argument, and expand the path relative to the
# working directory the script was run from.
SCHEMA_FILE=$(readlink -f "$1")
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )" # ... https://stackoverflow.com/a/246128/176841
cd "$PROJECT_ROOT/typescript"
echo "Deleting existing generated model..."
rm -rf src
echo "Generating model from $SCHEMA_FILE..."
npx openapi \
--useUnionTypes \
--input "$SCHEMA_FILE" \
--output src \
--exportServices false \
--exportCore false \
--indent 2
# To make a patch, commit the unpatched file, make the changes you want, and run
# `git diff > patches/my-patch.patch`
echo "Applying patches to generated files..."
for PATCH in patches/*.patch; do
# Don't crash if there are no patches.
if [ -f "$PATCH" ]; then
git apply "$PATCH"
fi
done