Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow Makefile to install swagger if missing #468

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ build:

clean-generate: remove-generated generate

generate: specs/swagger-stripped-oauth.json
swagger generate client --skip-validation -f $^ -t falcon
generate: swagger-cli specs/swagger-stripped-oauth.json
$(SWAGGER) generate client --skip-validation -f $^ -t falcon

.PHONY: build generate remove-generated

Expand All @@ -27,3 +27,37 @@ specs/swagger-patched.json: specs/swagger.json ./specs/transformation.jq
specs/swagger.json:
@echo "Sorry swagger.json needs to be obtained manually at this moment"
@exit 1

##@ Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
SWAGGER = $(LOCALBIN)/swagger

## Tool Versions
SWAGGER_VERSION ?= v0.31.0

.PHONY: swagger-cli
swagger-cli: $(SWAGGER) ## Download swagger locally if necessary.
$(SWAGGER): $(LOCALBIN)
$(call go-install-tool,$(SWAGGER),github.com/go-swagger/go-swagger/cmd/swagger,$(SWAGGER_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
Loading