Skip to content

Instantly share code, notes, and snippets.

@atomsfat
Last active February 12, 2020 04:13
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 atomsfat/d5c86064dbcf3764f89912ac8a6df33a to your computer and use it in GitHub Desktop.
Save atomsfat/d5c86064dbcf3764f89912ac8a6df33a to your computer and use it in GitHub Desktop.
Makefile to generate api-clients
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
.DEFAULT_GOAL := client-generated
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
ONLINE_GEN_URL=https://generator3.swagger.io/api/generate
# client specific
LANG:=javascript
CODE_GEN_VERSION=V3
API_DOC_URL:=http://localhost:8000/openapi.json
TYPE=CLIENT
openapi.json:
http $(API_DOC_URL) > $@
client-generated.zip: openapi.json
content='$(shell cat $<)'; \
echo "{\"spec\":$${content}, \"lang\":\"${LANG}\", \"codegenVersion\":\"${CODE_GEN_VERSION}\", \"type\":\"${TYPE}\"}" \
| http post ${ONLINE_GEN_URL} > $@
client-generated:client-generated.zip
unzip $< -d $@
clean:
-rm client-generated.zip openapi.json
-rm -r client-generated
.PHONY: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment