matrix-spec/packages/npm/openapi.sh
Michael Telatynski 81503232cc
Apply suggestions from code review
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2024-03-25 10:42:40 +00:00

31 lines
742 B
Bash
Executable file

#!/usr/bin/env bash
# Script to generate OpenAPI typescript definitions for the Matrix APIs
set -e
RELEASE="${npm_package_version%.*}"
SPEC_DIR="v${RELEASE}"
if [ "$RELEASE" == "0.0" ]; then
RELEASE="unstable"
SPEC_DIR="/unstable"
fi
BASE_URL="https://spec.matrix.org/$SPEC_DIR"
for api in application-service client-server push-gateway server-server; do
FILE="$api-api.json"
../../scripts/dump-openapi.py \
--base-url "$BASE_URL" \
--api "$api" \
-r "$RELEASE" \
-o "$FILE"
yarn openapi-typescript "$FILE" --output "$api.d.ts"
# We remove these lines to workaround dodgy types
sed -i.bak "/\[key: string\]: Record<string, never> \| undefined;/d" client-server.d.ts
rm "$api.d.ts.bak"
rm "$FILE"
done