@@ -165,10 +165,8 @@ ifdef DEPS_PLAYWRIGHT
165165endif
166166
167167SWAGGER_SPEC := templates/swagger/v1_json.tmpl
168- SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
169- SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
168+ SWAGGER_SPEC_INPUT := templates/swagger/v1_input.json
170169SWAGGER_EXCLUDE := code.gitea.io/sdk
171- SWAGGER_NEWLINE_COMMAND := -e '$$a\'
172170
173171TEST_MYSQL_HOST ?= mysql:3306
174172TEST_MYSQL_DBNAME ?= testgitea
@@ -271,10 +269,8 @@ endif
271269.PHONY : generate-swagger
272270generate-swagger : $(SWAGGER_SPEC ) # # generate the swagger spec from code comments
273271
274- $(SWAGGER_SPEC ) : $(GO_SOURCES_NO_BINDATA )
275- $(GO ) run $(SWAGGER_PACKAGE ) generate spec -x " $( SWAGGER_EXCLUDE) " -o ' ./$(SWAGGER_SPEC)'
276- $(SED_INPLACE ) ' $(SWAGGER_SPEC_S_TMPL)' ' ./$(SWAGGER_SPEC)'
277- $(SED_INPLACE ) $(SWAGGER_NEWLINE_COMMAND ) ' ./$(SWAGGER_SPEC)'
272+ $(SWAGGER_SPEC ) : $(GO_SOURCES_NO_BINDATA ) $(SWAGGER_SPEC_INPUT )
273+ $(GO ) run $(SWAGGER_PACKAGE ) generate spec --exclude " $( SWAGGER_EXCLUDE) " --input " $( SWAGGER_SPEC_INPUT) " --output ' ./$(SWAGGER_SPEC)'
278274
279275.PHONY : swagger-check
280276swagger-check : generate-swagger
@@ -287,9 +283,11 @@ swagger-check: generate-swagger
287283
288284.PHONY : swagger-validate
289285swagger-validate : # # check if the swagger spec is valid
290- $(SED_INPLACE ) ' $(SWAGGER_SPEC_S_JSON)' ' ./$(SWAGGER_SPEC)'
286+ @# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}"
287+ @$(SED_INPLACE ) -E -e ' s|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' ' ./$(SWAGGER_SPEC)' # add a prefix slash to basePath
288+ @# FIXME: there are some warnings
291289 $(GO ) run $(SWAGGER_PACKAGE ) validate ' ./$(SWAGGER_SPEC)'
292- $(SED_INPLACE ) ' $(SWAGGER_SPEC_S_TMPL) ' ' ./$(SWAGGER_SPEC)'
290+ @ $(SED_INPLACE ) -E -e ' s|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g ' ' ./$(SWAGGER_SPEC)' # remove the prefix slash from basePath
293291
294292.PHONY : checks
295293checks : checks-frontend checks-backend # # run various consistency checks
@@ -381,6 +379,7 @@ lint-go-gopls: ## lint go files with gopls
381379
382380.PHONY : lint-editorconfig
383381lint-editorconfig :
382+ @echo " Running editorconfig check..."
384383 @$(GO ) run $(EDITORCONFIG_CHECKER_PACKAGE ) $(EDITORCONFIG_FILES )
385384
386385.PHONY : lint-actions
@@ -472,7 +471,9 @@ tidy-check: tidy
472471go-licenses : $(GO_LICENSE_FILE ) # # regenerate go licenses
473472
474473$(GO_LICENSE_FILE ) : go.mod go.sum
475- -$(GO ) run $(GO_LICENSES_PACKAGE ) save . --force --save_path=$(GO_LICENSE_TMP_DIR ) 2> /dev/null
474+ @rm -rf $(GO_LICENSE_FILE )
475+ $(GO ) install $(GO_LICENSES_PACKAGE )
476+ -GOOS=linux CGO_ENABLED=1 go-licenses save . --force --save_path=$(GO_LICENSE_TMP_DIR ) 2> /dev/null
476477 $(GO ) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR ) $(GO_LICENSE_FILE )
477478 @rm -rf $(GO_LICENSE_TMP_DIR )
478479
0 commit comments