Skip to content

Instantly share code, notes, and snippets.

@neonichu
Last active December 11, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neonichu/f49f70c09be058319871 to your computer and use it in GitHub Desktop.
Save neonichu/f49f70c09be058319871 to your computer and use it in GitHub Desktop.
Parse an API blueprint hosted on Apiary via the API Blueprint API
#!/bin/sh
#BLUEPRINT=contentfulcda
#BLUEPRINT=contentfulcma
BLUEPRINT=$1
if [ -z "$BLUEPRINT" ]; then
echo "Usage: $0 blueprint-file" >&2
exit 1
fi
TMPFILE=`mktemp $TMPDIR/tmp.XXXXXX`
TMPFILE2=`mktemp $TMPDIR/tmp.XXXXXX`
curl -s "https://api.apiary.io/blueprint/get/$BLUEPRINT" \
--header "Authentication: Token $APIARY_API_KEY"|jq -r '.code' >"$TMPFILE"
#drafter -l "$TMPFILE"
curl -s -X POST --data-binary @"$TMPFILE" 'https://api.apiblueprint.org/parser' \
--header 'Content-Type: text/vnd.apiblueprint' \
--header 'Accept: application/vnd.refract.parse-result+json' >"$TMPFILE2"
cat "$TMPFILE2"|jq '.error.message'
cat "$TMPFILE2"|jq -e '.error.message | length == 0' >/dev/null
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
EXPRESSION='.content[] | select(.meta.classes[0] == "warning")'
cat "$TMPFILE2"|jq "$EXPRESSION | .content"
cat "$TMPFILE2"|jq -e "$EXPRESSION | length == 0" >/dev/null
EXIT_CODE=$?
fi
rm -f "$TMPFILE" "$TMPFILE2"
exit $EXIT_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment