forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
78 lines (57 loc) · 2.39 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
include ../../../../../.bingo/Variables.mk
.DEFAULT_GOAL := openapi
API_DIR = definitions
GO_PKG_FILES = $(shell find $(API_DIR) -name *.go -print)
PATH_DOWN = pkg/services/ngalert/api/tooling
PATH_UP = ../../../../..
.DEFAULT_GOAL := all
GENERATED_GO_MATCHERS = ./go/*.go
SED_INPLACE := -i
ifneq ($(OS),Windows_NT)
# If we're not using the GNU version of sed, we need to specify an argument to -i
UNAME := $(shell uname)
isGNU := $(shell sed --help 2>&1 | grep -c GNU)
ifneq ($(isGNU),0)
# Do nothing
else ifeq ($(UNAME),Darwin)
SED_INPLACE = -i ''
endif
endif
spec.json spec-stable.json: $(GO_PKG_FILES) $(SWAGGER)
SWAGGER_GENERATE_EXTENSION=false $(SWAGGER) generate spec -m -w $(API_DIR) -o spec.json && SWAGGER_GENERATE_EXTENSION=false $(SWAGGER) generate spec -m --include-tag=stable -o spec-stable.json
post.json: spec.json
go run cmd/clean-swagger/main.go -if $(<) -of $@
api.json: spec-stable.json
go run cmd/clean-swagger/main.go -if $(<) -of $@
validate-stable: spec-stable.json $(SWAGGER)
$(SWAGGER) validate $(<)
validate: spec.json $(SWAGGER)
$(SWAGGER) validate $(<)
swagger-codegen-api:
docker run --rm -v $$(pwd):/local --user $$(id -u):$$(id -g) parsertongue/swagger-codegen-cli:3.0.32 generate \
-i /local/post.json \
-l go-server \
-Dapis \
-o /local \
--additional-properties packageName=api \
-t /local/swagger-codegen/templates \
# --import-mappings eval.RelativeTimeRange="github.com/grafana/grafana/pkg/services/ngalert/eval" \
# --type-mappings RelativeTimeRange=eval.RelativeTimeRange
copy-files:
ls -1 go | xargs -n 1 -I {} mv go/{} ../generated_base_{}
fix:
sed $(SED_INPLACE) -e 's/apimodels\.\[\]PostableAlert/apimodels.PostableAlerts/' $(GENERATED_GO_MATCHERS)
sed $(SED_INPLACE) -e 's/apimodels\.\[\]UpdateDashboardACLCommand/apimodels.Permissions/' $(GENERATED_GO_MATCHERS)
sed $(SED_INPLACE) -e 's/apimodels\.\[\]PostableApiReceiver/apimodels.TestReceiversConfigParams/' $(GENERATED_GO_MATCHERS)
goimports -w -v $(GENERATED_GO_MATCHERS)
clean: clean-go
rm -f spec.json
rm -f spec-stable.json
clean-go:
rm -rf ./go
serve: post.json
docker run --rm -p 80:8080 -v $$(pwd):/tmp -e SWAGGER_FILE=/tmp/$(<) swaggerapi/swagger-editor
serve-stable: api.json
docker run --rm -p 80:8080 -v $$(pwd):/tmp -e SWAGGER_FILE=/tmp/$(<) swaggerapi/swagger-editor
gen: swagger-codegen-api fix copy-files clean-go
all: clean spec.json spec-stable.json post.json api.json gen