
.PHONY: swagger

swagger:
	cp ../auth/swagger/auth-vernonkeenan.yaml ./swagger
	cp ../auth/swagger/auth-vernonkeenan.yaml ./swagger/external
	cp ../crm/swagger/crm-vernonkeenan.yaml ./swagger
	cp ../crm/swagger/crm-vernonkeenan.yaml ./swagger/external
	cp ../stash/swagger/stash-vernonkeenan.yaml ./swagger
	cp ../stash/swagger/stash-vernonkeenan.yaml ./swagger/external
	cp ../sf-gate/swagger/sf-gate-vernonkeenan.yaml ./swagger
	cp ../sf-gate/swagger/sf-gate-vernonkeenan.yaml ./swagger/external
	cp ../research/swagger/research-vernonkeenan.yaml ./swagger
	cp ../research/swagger/research-vernonkeenan.yaml ./swagger/external
	cp ../members/swagger/members-vernonkeenan.yaml ./swagger
	cp ../members/swagger/members-vernonkeenan.yaml ./swagger/external
	cp ../plex/swagger/plex-vernonkeenan.yaml ./swagger
	cp ../plex/swagger/plex-vernonkeenan.yaml ./swagger/external
	#
	rm -rf api
	#
	# generate auth client
	#
	mkdir -p api/auth
	swagger generate client \
		--log-output=./swagger/logs/generate-auth-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=auth \
		--spec=./swagger/auth-vernonkeenan.yaml \
		--target=./api/auth \
		--client-package=auth-client \
		--model-package=auth-models \
		--principal=app.User
	#
	# update external auth client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/auth-vernonkeenan.yaml
	sed -i 's|auth.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/auth-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/auth/v1"|g' ./swagger/external/auth-vernonkeenan.yaml
	#
	# generate crm client
	#
	mkdir api/crm
	swagger generate client \
		--log-output=./swagger/logs/generate-crm-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=crm \
		--spec=./swagger/crm-vernonkeenan.yaml \
		--target=./api/crm \
		--client-package=crm-client \
		--model-package=crm-models \
		--principal=app.User
	#
	# update external crm client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/crm-vernonkeenan.yaml
	sed -i 's|crm.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/crm-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/crm/v1"|g' ./swagger/external/crm-vernonkeenan.yaml
	#
	# generate stash client
	#
	mkdir api/stash
	swagger generate client \
		--log-output=./swagger/logs/generate-stash-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=stash \
		--spec=./swagger/stash-vernonkeenan.yaml \
		--target=./api/stash \
		--client-package=stash-client \
		--model-package=stash-models \
		--principal=app.User
	#
	# update external stash client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/stash-vernonkeenan.yaml
	sed -i 's|stash.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/stash-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/stash/v1"|g' ./swagger/external/stash-vernonkeenan.yaml
	#
	# generate sfgate client
	#
	mkdir api/sfgate
	swagger generate client \
		--log-output=./swagger/logs/generate-sfgate-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=sfgate \
		--spec=./swagger/sf-gate-vernonkeenan.yaml \
		--target=./api/sfgate \
		--client-package=sfgate-client \
		--model-package=sfgate-models \
		--principal=app.User
	#
	# update external crm client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/sf-gate-vernonkeenan.yaml
	sed -i 's|sf-gate.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/sf-gate-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/sf-gate/v1"|g' ./swagger/external/sf-gate-vernonkeenan.yaml
	#
	# generate research client
	#
	mkdir api/research
	swagger generate client \
		--log-output=./swagger/logs/generate-research-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=research \
		--spec=./swagger/research-vernonkeenan.yaml \
		--target=./api/research \
		--client-package=research-client \
		--model-package=research-models \
		--principal=app.User
	#
	# update external research client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/research-vernonkeenan.yaml
	sed -i 's|research.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/research-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/research/v1"|g' ./swagger/external/research-vernonkeenan.yaml
	#
	# generate members client
	#
	mkdir api/members
	swagger generate client \
		--log-output=./swagger/logs/generate-members-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=members \
		--spec=./swagger/members-vernonkeenan.yaml \
		--target=./api/members \
		--client-package=members-client \
		--model-package=members-models \
		--principal=app.User
	#
	# update external members client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/members-vernonkeenan.yaml
	sed -i 's|members.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/members-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/members/v1"|g' ./swagger/external/members-vernonkeenan.yaml
	#
	# generate plex client
	#
	mkdir api/plex
	swagger generate client \
		--log-output=./swagger/logs/generate-plex-client.log \
		--copyright-file=./build/COPYRIGHT \
		--name=plex \
		--spec=./swagger/plex-vernonkeenan.yaml \
		--target=./api/plex \
		--client-package=plex-client \
		--model-package=plex-models \
		--principal=app.User
	#
	# update external plex client
	#
	sed -i 's|"http"|"https"|g' ./swagger/external/plex-vernonkeenan.yaml
	sed -i 's|plex.vernonkeenan.com:8080|gw.tnxs.net|g' ./swagger/external/plex-vernonkeenan.yaml
	sed -i 's|"/v1"|"/vk/plex/v1"|g' ./swagger/external/plex-vernonkeenan.yaml
	#
	# copy external swagger files
	#
	scp ./swagger/external/*.yaml root@whm.noc.tnxs.net:/home/taxassets/www/swagger/external
