From 386f6af2d13fb5ca4b26d6ee80b034628ad7d03e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Feb 2025 07:24:32 +0800 Subject: [PATCH 1/5] fix --- Makefile | 16 +++++++--------- routers/api/v1/api.go | 2 -- templates/swagger/v1_input.json | 6 ++++++ templates/swagger/v1_json.tmpl | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 templates/swagger/v1_input.json diff --git a/Makefile b/Makefile index 89a6f1261fff8..ffaf03c4691d0 100644 --- a/Makefile +++ b/Makefile @@ -165,10 +165,8 @@ ifdef DEPS_PLAYWRIGHT endif SWAGGER_SPEC := templates/swagger/v1_json.tmpl -SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g -SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g +SWAGGER_SPEC_INPUT := templates/swagger/v1_input.json SWAGGER_EXCLUDE := code.gitea.io/sdk -SWAGGER_NEWLINE_COMMAND := -e '$$a\' TEST_MYSQL_HOST ?= mysql:3306 TEST_MYSQL_DBNAME ?= testgitea @@ -271,10 +269,8 @@ endif .PHONY: generate-swagger generate-swagger: $(SWAGGER_SPEC) ## generate the swagger spec from code comments -$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) - $(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)' - $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)' - $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)' +$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA) $(SWAGGER_SPEC_INPUT) + $(GO) run $(SWAGGER_PACKAGE) generate spec --exclude "$(SWAGGER_EXCLUDE)" --input "$(SWAGGER_SPEC_INPUT)" --output './$(SWAGGER_SPEC)' .PHONY: swagger-check swagger-check: generate-swagger @@ -287,9 +283,11 @@ swagger-check: generate-swagger .PHONY: swagger-validate swagger-validate: ## check if the swagger spec is valid - $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)' + @# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}" + $(SED_INPLACE) -e 's|"basePath": *".*"|"basePath": "/api/v1"|g' './$(SWAGGER_SPEC)' + @# FIXME: there are some warnings $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)' - $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)' + git restore './$(SWAGGER_SPEC)' .PHONY: checks checks: checks-frontend checks-backend ## run various consistency checks diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 907a2f08fe280..bc76b5285e5a2 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -7,8 +7,6 @@ // This documentation describes the Gitea API. // // Schemes: https, http -// BasePath: /api/v1 -// Version: {{AppVer | JSEscape}} // License: MIT http://opensource.org/licenses/MIT // // Consumes: diff --git a/templates/swagger/v1_input.json b/templates/swagger/v1_input.json new file mode 100644 index 0000000000000..1979febebb9db --- /dev/null +++ b/templates/swagger/v1_input.json @@ -0,0 +1,6 @@ +{ + "info": { + "version": "{{AppVer | JSEscape}}" + }, + "basePath": "{{AppSubUrl | JSEscape}}/api/v1" +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d173f3161b553..fd3e2a70f1337 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -27580,4 +27580,4 @@ "TOTPHeader": [] } ] -} +} \ No newline at end of file From 8d8eac849cfc0337b7b79d2458d3ff4053c00e98 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Feb 2025 08:28:04 +0800 Subject: [PATCH 2/5] fix --- .editorconfig | 1 + .github/workflows/files-changed.yml | 1 + Makefile | 1 + 3 files changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index c0946ac9975cd..e23e4cd649a42 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,6 +17,7 @@ insert_final_newline = false [templates/swagger/v1_json.tmpl] indent_style = space +insert_final_newline = false [templates/user/auth/oidc_wellknown.tmpl] indent_style = space diff --git a/.github/workflows/files-changed.yml b/.github/workflows/files-changed.yml index 7c1fb024421bc..b3ee93e6f8331 100644 --- a/.github/workflows/files-changed.yml +++ b/.github/workflows/files-changed.yml @@ -85,6 +85,7 @@ jobs: swagger: - "templates/swagger/v1_json.tmpl" + - "templates/swagger/v1_input.json" - "Makefile" - "package.json" - "package-lock.json" diff --git a/Makefile b/Makefile index ffaf03c4691d0..0eec07ef8f3a8 100644 --- a/Makefile +++ b/Makefile @@ -378,6 +378,7 @@ lint-go-gopls: ## lint go files with gopls .PHONY: lint-editorconfig lint-editorconfig: + @echo "Running editorconfig check..." @$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES) .PHONY: lint-actions From e1136b38009bbbf0d41edc383d193531944bbd99 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Feb 2025 13:18:47 +0800 Subject: [PATCH 3/5] improve swagger-validate --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0eec07ef8f3a8..21822d4410bf6 100644 --- a/Makefile +++ b/Makefile @@ -284,10 +284,10 @@ swagger-check: generate-swagger .PHONY: swagger-validate swagger-validate: ## check if the swagger spec is valid @# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}" - $(SED_INPLACE) -e 's|"basePath": *".*"|"basePath": "/api/v1"|g' './$(SWAGGER_SPEC)' + @$(SED_INPLACE) -E 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath @# FIXME: there are some warnings $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)' - git restore './$(SWAGGER_SPEC)' + @$(SED_INPLACE) -E 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath .PHONY: checks checks: checks-frontend checks-backend ## run various consistency checks From 258db018f35bb2ede503cd014085a9723aa3221e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Feb 2025 14:56:31 +0800 Subject: [PATCH 4/5] Update Makefile Co-authored-by: silverwind --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 21822d4410bf6..490a9c345ac50 100644 --- a/Makefile +++ b/Makefile @@ -287,7 +287,7 @@ swagger-validate: ## check if the swagger spec is valid @$(SED_INPLACE) -E 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath @# FIXME: there are some warnings $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)' - @$(SED_INPLACE) -E 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath + @$(SED_INPLACE) -E -e 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath .PHONY: checks checks: checks-frontend checks-backend ## run various consistency checks From be039e24bbfe53b3cb22ea6a630e470384d1554a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Feb 2025 14:57:27 +0800 Subject: [PATCH 5/5] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 490a9c345ac50..e38fb801c318a 100644 --- a/Makefile +++ b/Makefile @@ -284,7 +284,7 @@ swagger-check: generate-swagger .PHONY: swagger-validate swagger-validate: ## check if the swagger spec is valid @# swagger "validate" requires that the "basePath" must start with a slash, but we are using Golang template "{{...}}" - @$(SED_INPLACE) -E 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath + @$(SED_INPLACE) -E -e 's|"basePath":( *)"(.*)"|"basePath":\1"/\2"|g' './$(SWAGGER_SPEC)' # add a prefix slash to basePath @# FIXME: there are some warnings $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)' @$(SED_INPLACE) -E -e 's|"basePath":( *)"/(.*)"|"basePath":\1"\2"|g' './$(SWAGGER_SPEC)' # remove the prefix slash from basePath