Skip to content

Commit 2bcd947

Browse files
sapkappleboy
authored andcommitted
Separate generate swagger + fix sed os specific (#1791)
* Separate generate-swagger * Remove go generate rules * Add missing definition replacement + remove use of -i sed flag for compatibility with mac os default sed version. This is a little hacky a better solution could be use. * Use custom SED_INPLACE depending of platform detection * Use SED_INPLACE for swagger-ui also
1 parent 01322af commit 2bcd947

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Makefile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
DIST := dist
22
IMPORT := code.gitea.io/gitea
3+
4+
SED_INPLACE := sed -i
5+
6+
ifeq ($(OS), Windows_NT)
7+
EXECUTABLE := gitea.exe
8+
else
9+
EXECUTABLE := gitea
10+
UNAME_S := $(shell uname -s)
11+
ifeq ($(UNAME_S),Darwin)
12+
SED_INPLACE := sed -i ''
13+
endif
14+
endif
15+
316
BINDATA := modules/{options,public,templates}/bindata.go
417
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
518
JAVASCRIPTS :=
@@ -59,11 +72,17 @@ generate:
5972
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
6073
go get -u github.com/jteeuwen/go-bindata/...; \
6174
fi
75+
go generate $(PACKAGES)
76+
77+
.PHONY: generate-swagger
78+
generate-swagger:
6279
@hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
6380
go get -u github.com/go-swagger/go-swagger/cmd/swagger; \
6481
fi
65-
go generate $(PACKAGES)
66-
82+
swagger generate spec -o ./public/swagger.v1.json
83+
$(SED_INPLACE) "s;\".ref\": \"#/definitions/GPGKey\";\"type\": \"object\";g" ./public/swagger.v1.json
84+
$(SED_INPLACE) "s;^ \".ref\": \"#/definitions/Repository\"; \"type\": \"object\";g" ./public/swagger.v1.json
85+
6786
.PHONY: errcheck
6887
errcheck:
6988
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
@@ -241,7 +260,7 @@ swagger-ui:
241260
git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git /tmp/swagger-ui
242261
mv /tmp/swagger-ui/dist public/assets/swagger-ui
243262
rm -Rf /tmp/swagger-ui
244-
sed -i "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
263+
$(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
245264

246265
.PHONY: assets
247266
assets: javascripts stylesheets

routers/api/v1/api.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//go:generate swagger generate spec -o ../../../public/swagger.v1.json
6-
//go:generate sed -i "s;\".ref\": \"#/definitions/GPGKey\";\"type\": \"object\";g" ../../../public/swagger.v1.json
7-
//go:generate sed -i "s;^ \".ref\": \"#/definitions/Repository\"; \"type\": \"object\";g" ../../../public/swagger.v1.json
8-
95
// Package v1 Gitea API.
106
//
117
// This provide API interface to communicate with this Gitea instance.

0 commit comments

Comments
 (0)