diff --git a/Makefile b/Makefile index 1b4ba9c8..824691b8 100644 --- a/Makefile +++ b/Makefile @@ -192,10 +192,42 @@ gen_repo_fields: docker_gen_swag: $(DOCKER) run -v $(shell pwd):/universe --rm $(DMS_GO_COMPILER_IMAGE) sh -c "cd /universe &&make gen_swag" -gen_swag: +gen_swag: check_swag_version ./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} generate spec -m -w ./internal/apiserver/cmd/server/ -o ./api/swagger.yaml ./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} generate spec -i ./api/swagger.yaml -o ./api/swagger.json +check_swag_version: + @SWAG_BIN=./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH}; \ + SWAG_VER=$$($$SWAG_BIN version | grep 'version:' | awk '{print $$2}'); \ + MATCHING_GO_VER="unknown"; \ + MAPPINGS="v0.33.1:1.24.0 v0.31.0:1.22 v0.30.4:1.19 v0.29.0:1.18"; \ + for m in $$MAPPINGS; do \ + v=$${m%%:*}; g=$${m#*:}; \ + if [ "$$v" = "$$SWAG_VER" ]; then MATCHING_GO_VER="$$g"; break; fi; \ + done; \ + if [ "$$MATCHING_GO_VER" = "unknown" ]; then \ + echo "Fetching Go version for $$SWAG_VER from GitHub..."; \ + MATCHING_GO_VER=$$(curl -sL --connect-timeout 2 https://raw.githubusercontent.com/go-swagger/go-swagger/$$SWAG_VER/go.mod | grep "^go " | awk '{print $$2}' 2>/dev/null); \ + if [ -z "$$MATCHING_GO_VER" ]; then MATCHING_GO_VER="unknown"; fi; \ + fi; \ + PROJECT_GO_VER=$$(grep "^go " go.mod | awk '{print $$2}'); \ + SYSTEM_GO_VER=$$(go version | awk '{print $$3}' | sed 's/go//'); \ + echo "Project go.mod Version: $$PROJECT_GO_VER"; \ + echo "Swagger Version: $$SWAG_VER (Expected Go: $$MATCHING_GO_VER)"; \ + echo "System Go Version: $$SYSTEM_GO_VER"; \ + if [ "$$MATCHING_GO_VER" != "unknown" ]; then \ + PROJECT_GO_MAJOR=$$(echo $$PROJECT_GO_VER | cut -d. -f1,2); \ + MATCH_GO_VER_MAJOR=$$(echo $$MATCHING_GO_VER | cut -d. -f1,2); \ + SYSTEM_GO_MAJOR=$$(echo $$SYSTEM_GO_VER | cut -d. -f1,2); \ + if [ "$$PROJECT_GO_MAJOR" != "$$MATCH_GO_VER_MAJOR" ]; then \ + echo "Warning: Current Swagger generator ($$SWAG_VER, Go $$MATCHING_GO_VER) does not match project's go.mod ($$PROJECT_GO_VER)."; \ + echo "Please update the Swagger generator to match the project Go version."; \ + fi; \ + if [ "$$PROJECT_GO_MAJOR" != "$$SYSTEM_GO_MAJOR" ]; then \ + echo "Warning: Your system Go version ($$SYSTEM_GO_VER) does not match project's go.mod ($$PROJECT_GO_VER)."; \ + fi; \ + fi + open_swag_server: ./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} serve --no-open -F=swagger --port 36666 ./api/swagger.yaml diff --git a/api/dms/service/v1/db_service.go b/api/dms/service/v1/db_service.go index d25f69c1..fcacffa1 100644 --- a/api/dms/service/v1/db_service.go +++ b/api/dms/service/v1/db_service.go @@ -264,7 +264,7 @@ type ListDBServiceTipsReq struct { // in:query FilterDBType string `json:"filter_db_type" query:"filter_db_type"` // Required: false - // enum: save_audit_plan,create_workflow,create_export_task + // enum: ["save_audit_plan","create_workflow","create_export_task"] // in:query FunctionalModule string `json:"functional_module" query:"functional_module" validate:"omitempty,oneof=save_audit_plan create_workflow create_export_task"` } @@ -360,7 +360,7 @@ type ListGlobalDBServicesReq struct { // in:query OrderBy dmsCommonV1.DBServiceOrderByField `query:"order_by" json:"order_by"` // the db service connection - // enum: connect_success,connect_failed + // enum: ["connect_success","connect_failed"] // in:query FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"` // TODO This parameter is deprecated and will be removed soon. diff --git a/api/dms/service/v1/operation_record.go b/api/dms/service/v1/operation_record.go index 1d284b1a..1ab6d268 100644 --- a/api/dms/service/v1/operation_record.go +++ b/api/dms/service/v1/operation_record.go @@ -67,7 +67,7 @@ type OperationRecordListItem struct { OperationAction string `json:"operation_action"` OperationContent string `json:"operation_content"` ProjectName string `json:"project_name"` - // enum: succeeded,failed + // enum: ["succeeded","failed"] Status string `json:"status"` } diff --git a/api/dms/service/v2/db_service.go b/api/dms/service/v2/db_service.go index 396b2b3f..c5986c19 100644 --- a/api/dms/service/v2/db_service.go +++ b/api/dms/service/v2/db_service.go @@ -21,7 +21,7 @@ type ListGlobalDBServicesReq struct { // in:query OrderBy dmsCommonV1.DBServiceOrderByField `query:"order_by" json:"order_by"` // the db service connection - // enum: connect_success,connect_failed + // enum: ["connect_success","connect_failed"] // in:query FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"` // filter db services by environment tag diff --git a/api/swagger.json b/api/swagger.json index 0077be0a..05a40727 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -8624,6 +8624,12 @@ }, "x-go-package": "github.com/actiontech/dms/api/dms/service/v1" }, + "DateTime": { + "description": "DateTime is a time but it serializes to ISO8601 format with millis\nIt knows how to read 3 different variations of a RFC3339 date time.\nMost APIs we encounter want either millisecond or second precision times.\nThis just tries to make it worry-free.", + "type": "string", + "format": "date-time", + "x-go-package": "github.com/go-openapi/strfmt" + }, "DbServiceConnections": { "type": "object", "properties": { @@ -9922,10 +9928,6 @@ "x-go-package": "github.com/actiontech/dms/api/dms/service/v1" }, "I18nStr": { - "type": "object", - "additionalProperties": { - "type": "string" - }, "x-go-package": "github.com/actiontech/dms/pkg/dms-common/i18nPkg" }, "ImportDBService": { diff --git a/api/swagger.yaml b/api/swagger.yaml index 59088b16..e6c660b7 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1375,6 +1375,15 @@ definitions: x-go-name: Params type: object x-go-package: github.com/actiontech/dms/api/dms/service/v1 + DateTime: + description: |- + DateTime is a time but it serializes to ISO8601 format with millis + It knows how to read 3 different variations of a RFC3339 date time. + Most APIs we encounter want either millisecond or second precision times. + This just tries to make it worry-free. + format: date-time + type: string + x-go-package: github.com/go-openapi/strfmt DbServiceConnections: properties: db_service_uid: @@ -2394,9 +2403,6 @@ definitions: type: object x-go-package: github.com/actiontech/dms/api/dms/service/v1 I18nStr: - additionalProperties: - type: string - type: object x-go-package: github.com/actiontech/dms/pkg/dms-common/i18nPkg ImportDBService: properties: diff --git a/internal/apiserver/cmd/swag/swagger_linux_amd64 b/internal/apiserver/cmd/swag/swagger_linux_amd64 index d76a17ac..9411d740 100755 Binary files a/internal/apiserver/cmd/swag/swagger_linux_amd64 and b/internal/apiserver/cmd/swag/swagger_linux_amd64 differ diff --git a/pkg/dms-common/api/dms/v1/db_service.go b/pkg/dms-common/api/dms/v1/db_service.go index 4f71e0bf..444815ed 100644 --- a/pkg/dms-common/api/dms/v1/db_service.go +++ b/pkg/dms-common/api/dms/v1/db_service.go @@ -54,7 +54,7 @@ type ListDBServiceReq struct { // in:query FilterByBusiness string `query:"filter_by_business" json:"filter_by_business"` // the db service connection - // enum: connect_success,connect_failed + // enum: ["connect_success","connect_failed"] // in:query FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"` // the db service host diff --git a/pkg/dms-common/api/dms/v2/db_service.go b/pkg/dms-common/api/dms/v2/db_service.go index c4f84296..c0445372 100644 --- a/pkg/dms-common/api/dms/v2/db_service.go +++ b/pkg/dms-common/api/dms/v2/db_service.go @@ -19,7 +19,7 @@ type ListDBServiceReq struct { // in:query OrderBy v1.DBServiceOrderByField `query:"order_by" json:"order_by"` // the db service connection - // enum: connect_success,connect_failed + // enum: ["connect_success","connect_failed"] // in:query FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"` // the db service host @@ -110,4 +110,4 @@ type ListDBService struct { LastConnectionTestStatus v1.LastConnectionTestStatus `json:"last_connection_test_status"` // DB connect test error message LastConnectionTestErrorMessage string `json:"last_connection_test_error_message,omitempty"` -} \ No newline at end of file +}