Skip to content

Instantly share code, notes, and snippets.

@Goldziher
Last active November 30, 2021 21:47
Show Gist options
  • Save Goldziher/364ff383ae96a532cb01a4fbf3406d33 to your computer and use it in GitHub Desktop.
Save Goldziher/364ff383ae96a532cb01a4fbf3406d33 to your computer and use it in GitHub Desktop.
Script to generate api specs from a given api using DTSGenerator
#!/bin/bash
SPECS_DOWNLOAD_URL="https://url-of-api.com/specs"
FILE="$PWD/src/my-api-specs.ts"
if [[ -f "$FILE" ]]; then
rm "$FILE"
fi
# use dtsgen to generate the target typescript file
dtsgen --url $SPECS_DOWNLOAD_URL >> "$FILE"
# rewrie namespaces to be exported, allowing for named imports
sed -i '' 's/namespace/export namespace/g' "$FILE"
sed -i '' 's/declare export/export declare/g' "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment