Skip to content

Commit 78867dc

Browse files
Merge pull request #582 from actiontech/commit/update-swagger-generator
Commit/update swagger generator
2 parents 67b34f5 + 85df8cd commit 78867dc

9 files changed

Lines changed: 55 additions & 15 deletions

File tree

Makefile

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,42 @@ gen_repo_fields:
192192
docker_gen_swag:
193193
$(DOCKER) run -v $(shell pwd):/universe --rm $(DMS_GO_COMPILER_IMAGE) sh -c "cd /universe &&make gen_swag"
194194

195-
gen_swag:
195+
gen_swag: check_swag_version
196196
./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} generate spec -m -w ./internal/apiserver/cmd/server/ -o ./api/swagger.yaml
197197
./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} generate spec -i ./api/swagger.yaml -o ./api/swagger.json
198198

199+
check_swag_version:
200+
@SWAG_BIN=./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH}; \
201+
SWAG_VER=$$($$SWAG_BIN version | grep 'version:' | awk '{print $$2}'); \
202+
MATCHING_GO_VER="unknown"; \
203+
MAPPINGS="v0.33.1:1.24.0 v0.31.0:1.22 v0.30.4:1.19 v0.29.0:1.18"; \
204+
for m in $$MAPPINGS; do \
205+
v=$${m%%:*}; g=$${m#*:}; \
206+
if [ "$$v" = "$$SWAG_VER" ]; then MATCHING_GO_VER="$$g"; break; fi; \
207+
done; \
208+
if [ "$$MATCHING_GO_VER" = "unknown" ]; then \
209+
echo "Fetching Go version for $$SWAG_VER from GitHub..."; \
210+
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); \
211+
if [ -z "$$MATCHING_GO_VER" ]; then MATCHING_GO_VER="unknown"; fi; \
212+
fi; \
213+
PROJECT_GO_VER=$$(grep "^go " go.mod | awk '{print $$2}'); \
214+
SYSTEM_GO_VER=$$(go version | awk '{print $$3}' | sed 's/go//'); \
215+
echo "Project go.mod Version: $$PROJECT_GO_VER"; \
216+
echo "Swagger Version: $$SWAG_VER (Expected Go: $$MATCHING_GO_VER)"; \
217+
echo "System Go Version: $$SYSTEM_GO_VER"; \
218+
if [ "$$MATCHING_GO_VER" != "unknown" ]; then \
219+
PROJECT_GO_MAJOR=$$(echo $$PROJECT_GO_VER | cut -d. -f1,2); \
220+
MATCH_GO_VER_MAJOR=$$(echo $$MATCHING_GO_VER | cut -d. -f1,2); \
221+
SYSTEM_GO_MAJOR=$$(echo $$SYSTEM_GO_VER | cut -d. -f1,2); \
222+
if [ "$$PROJECT_GO_MAJOR" != "$$MATCH_GO_VER_MAJOR" ]; then \
223+
echo "Warning: Current Swagger generator ($$SWAG_VER, Go $$MATCHING_GO_VER) does not match project's go.mod ($$PROJECT_GO_VER)."; \
224+
echo "Please update the Swagger generator to match the project Go version."; \
225+
fi; \
226+
if [ "$$PROJECT_GO_MAJOR" != "$$SYSTEM_GO_MAJOR" ]; then \
227+
echo "Warning: Your system Go version ($$SYSTEM_GO_VER) does not match project's go.mod ($$PROJECT_GO_VER)."; \
228+
fi; \
229+
fi
230+
199231
open_swag_server:
200232
./internal/apiserver/cmd/swag/swagger_${HOST_OS}_${HOST_ARCH} serve --no-open -F=swagger --port 36666 ./api/swagger.yaml
201233

api/dms/service/v1/db_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ type ListDBServiceTipsReq struct {
264264
// in:query
265265
FilterDBType string `json:"filter_db_type" query:"filter_db_type"`
266266
// Required: false
267-
// enum: save_audit_plan,create_workflow,create_export_task
267+
// enum: ["save_audit_plan","create_workflow","create_export_task"]
268268
// in:query
269269
FunctionalModule string `json:"functional_module" query:"functional_module" validate:"omitempty,oneof=save_audit_plan create_workflow create_export_task"`
270270
}
@@ -360,7 +360,7 @@ type ListGlobalDBServicesReq struct {
360360
// in:query
361361
OrderBy dmsCommonV1.DBServiceOrderByField `query:"order_by" json:"order_by"`
362362
// the db service connection
363-
// enum: connect_success,connect_failed
363+
// enum: ["connect_success","connect_failed"]
364364
// in:query
365365
FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"`
366366
// TODO This parameter is deprecated and will be removed soon.

api/dms/service/v1/operation_record.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type OperationRecordListItem struct {
6767
OperationAction string `json:"operation_action"`
6868
OperationContent string `json:"operation_content"`
6969
ProjectName string `json:"project_name"`
70-
// enum: succeeded,failed
70+
// enum: ["succeeded","failed"]
7171
Status string `json:"status"`
7272
}
7373

api/dms/service/v2/db_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ListGlobalDBServicesReq struct {
2121
// in:query
2222
OrderBy dmsCommonV1.DBServiceOrderByField `query:"order_by" json:"order_by"`
2323
// the db service connection
24-
// enum: connect_success,connect_failed
24+
// enum: ["connect_success","connect_failed"]
2525
// in:query
2626
FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"`
2727
// filter db services by environment tag

api/swagger.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8624,6 +8624,12 @@
86248624
},
86258625
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
86268626
},
8627+
"DateTime": {
8628+
"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.",
8629+
"type": "string",
8630+
"format": "date-time",
8631+
"x-go-package": "github.com/go-openapi/strfmt"
8632+
},
86278633
"DbServiceConnections": {
86288634
"type": "object",
86298635
"properties": {
@@ -9922,10 +9928,6 @@
99229928
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
99239929
},
99249930
"I18nStr": {
9925-
"type": "object",
9926-
"additionalProperties": {
9927-
"type": "string"
9928-
},
99299931
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/i18nPkg"
99309932
},
99319933
"ImportDBService": {

api/swagger.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,15 @@ definitions:
13751375
x-go-name: Params
13761376
type: object
13771377
x-go-package: github.com/actiontech/dms/api/dms/service/v1
1378+
DateTime:
1379+
description: |-
1380+
DateTime is a time but it serializes to ISO8601 format with millis
1381+
It knows how to read 3 different variations of a RFC3339 date time.
1382+
Most APIs we encounter want either millisecond or second precision times.
1383+
This just tries to make it worry-free.
1384+
format: date-time
1385+
type: string
1386+
x-go-package: github.com/go-openapi/strfmt
13781387
DbServiceConnections:
13791388
properties:
13801389
db_service_uid:
@@ -2394,9 +2403,6 @@ definitions:
23942403
type: object
23952404
x-go-package: github.com/actiontech/dms/api/dms/service/v1
23962405
I18nStr:
2397-
additionalProperties:
2398-
type: string
2399-
type: object
24002406
x-go-package: github.com/actiontech/dms/pkg/dms-common/i18nPkg
24012407
ImportDBService:
24022408
properties:
-8.15 MB
Binary file not shown.

pkg/dms-common/api/dms/v1/db_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type ListDBServiceReq struct {
5454
// in:query
5555
FilterByBusiness string `query:"filter_by_business" json:"filter_by_business"`
5656
// the db service connection
57-
// enum: connect_success,connect_failed
57+
// enum: ["connect_success","connect_failed"]
5858
// in:query
5959
FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"`
6060
// the db service host

pkg/dms-common/api/dms/v2/db_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ListDBServiceReq struct {
1919
// in:query
2020
OrderBy v1.DBServiceOrderByField `query:"order_by" json:"order_by"`
2121
// the db service connection
22-
// enum: connect_success,connect_failed
22+
// enum: ["connect_success","connect_failed"]
2323
// in:query
2424
FilterLastConnectionTestStatus *string `query:"filter_last_connection_test_status" json:"filter_last_connection_test_status" validate:"omitempty,oneof=connect_success connect_failed"`
2525
// the db service host
@@ -110,4 +110,4 @@ type ListDBService struct {
110110
LastConnectionTestStatus v1.LastConnectionTestStatus `json:"last_connection_test_status"`
111111
// DB connect test error message
112112
LastConnectionTestErrorMessage string `json:"last_connection_test_error_message,omitempty"`
113-
}
113+
}

0 commit comments

Comments
 (0)