Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix missing response types in Swagger API endpoints #7611

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/app/api/v1/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// @Summary List apps
// @Accept json
// @Param request body request.AppSearch true "request"
// @Success 200
// @Success 200 {object} response.AppRes
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/search [post]
Expand Down Expand Up @@ -183,7 +183,7 @@ func (b *BaseApi) GetAppTags(c *gin.Context) {

// @Tags App
// @Summary Get app list update
// @Success 200
// @Success 200 {object} response.AppUpdateRes
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/checkupdate [get]
Expand Down
8 changes: 4 additions & 4 deletions backend/app/api/v1/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// @Summary Page app installed
// @Accept json
// @Param request body request.AppInstalledSearch true "request"
// @Success 200
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/search [post]
Expand Down Expand Up @@ -45,7 +45,7 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) {
// @Tags App
// @Summary List app installed
// @Accept json
// @Success 200 array dto.AppInstallInfo
// @Success 200 {array} dto.AppInstallInfo
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/list [get]
Expand Down Expand Up @@ -105,7 +105,7 @@ func (b *BaseApi) LoadPort(c *gin.Context) {
// @Accept json
// @Param request body dto.OperationWithNameAndType true "request"
// @Param key path string true "key"
// @Success 200 {string} response.DatabaseConn
// @Success 200 {object} response.DatabaseConn
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/conninfo/{key} [get]
Expand Down Expand Up @@ -266,7 +266,7 @@ func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
// @Summary Search params by appInstallId
// @Accept json
// @Param appInstallId path string true "request"
// @Success 200 {object} response.AppParam
// @Success 200 {object} response.AppConfig
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/params/{appInstallId} [get]
Expand Down
6 changes: 3 additions & 3 deletions backend/app/api/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,23 @@ func (b *BaseApi) GetResponsePage(c *gin.Context) {

// @Tags Auth
// @Summary Check System isDemo
// @Success 200
// @Success 200 {boolean} isDemo
// @Router /auth/demo [get]
func (b *BaseApi) CheckIsDemo(c *gin.Context) {
helper.SuccessWithData(c, global.CONF.System.IsDemo)
}

// @Tags Auth
// @Summary Check System isIntl
// @Success 200
// @Success 200 {boolean} isIntl
// @Router /auth/intl [get]
func (b *BaseApi) CheckIsIntl(c *gin.Context) {
helper.SuccessWithData(c, global.CONF.System.IsIntl)
}

// @Tags Auth
// @Summary Load System Language
// @Success 200
// @Success 200 {string} language
// @Router /auth/language [get]
func (b *BaseApi) GetLanguage(c *gin.Context) {
settingInfo, err := settingService.GetSettingInfo()
Expand Down
8 changes: 4 additions & 4 deletions backend/app/api/v1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (b *BaseApi) RefreshOneDriveToken(c *gin.Context) {
// @Summary List buckets
// @Accept json
// @Param request body dto.ForBuckets true "request"
// @Success 200 {array} string
// @Success 200 {array} object
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /settings/backup/search [post]
Expand Down Expand Up @@ -140,7 +140,7 @@ func (b *BaseApi) DeleteBackup(c *gin.Context) {
// @Summary Page backup records
// @Accept json
// @Param request body dto.RecordSearch true "request"
// @Success 200
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /settings/backup/record/search [post]
Expand All @@ -166,7 +166,7 @@ func (b *BaseApi) SearchBackupRecords(c *gin.Context) {
// @Summary Page backup records by cronjob
// @Accept json
// @Param request body dto.RecordSearchByCronjob true "request"
// @Success 200
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /settings/backup/record/search/bycronjob [post]
Expand All @@ -192,7 +192,7 @@ func (b *BaseApi) SearchBackupRecordsByCronjob(c *gin.Context) {
// @Summary Download backup record
// @Accept json
// @Param request body dto.DownloadRecord true "request"
// @Success 200
// @Success 200 {string} filePath
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /settings/backup/record/download [post]
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/v1/clam.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (b *BaseApi) SearchClamRecord(c *gin.Context) {
// @Summary Load clam record detail
// @Accept json
// @Param request body dto.ClamLogReq true "request"
// @Success 200
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/clam/record/log [post]
Expand All @@ -214,7 +214,7 @@ func (b *BaseApi) LoadClamRecordLog(c *gin.Context) {
// @Summary Load clam file
// @Accept json
// @Param request body dto.ClamFileReq true "request"
// @Success 200 {object} dto.PageResult
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/clam/file/search [post]
Expand Down
8 changes: 4 additions & 4 deletions backend/app/api/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (b *BaseApi) SearchContainer(c *gin.Context) {
// @Summary List containers
// @Accept json
// @Produce json
// @Success 200
// @Success 200 {array} string
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/list [post]
Expand Down Expand Up @@ -83,7 +83,7 @@ func (b *BaseApi) SearchCompose(c *gin.Context) {
// @Summary Test compose
// @Accept json
// @Param request body dto.ComposeCreate true "request"
// @Success 200
// @Success 200 {boolean} isOK
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/compose/test [post]
Expand All @@ -106,7 +106,7 @@ func (b *BaseApi) TestCompose(c *gin.Context) {
// @Summary Create compose
// @Accept json
// @Param request body dto.ComposeCreate true "request"
// @Success 200
// @Success 200 {string} log
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/compose [post]
Expand Down Expand Up @@ -312,7 +312,7 @@ func (b *BaseApi) CleanContainerLog(c *gin.Context) {
// @Summary Load container log
// @Accept json
// @Param request body dto.OperationWithNameAndType true "request"
// @Success 200
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/load/log [post]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (b *BaseApi) SearchJobRecords(c *gin.Context) {
// @Summary Load Cronjob record log
// @Accept json
// @Param request body dto.OperateByID true "request"
// @Success 200
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /cronjobs/records/log [post]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *BaseApi) CreateDatabase(c *gin.Context) {
// @Summary Check database
// @Accept json
// @Param request body dto.DatabaseCreate true "request"
// @Success 200
// @Success 200 {boolean} isOk
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /databases/db/check [post]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/database_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (b *BaseApi) LoadDBBaseInfo(c *gin.Context) {
// @Summary Load Database conf
// @Accept json
// @Param request body dto.OperationWithNameAndType true "request"
// @Success 200
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /databases/common/load/file [post]
Expand Down
6 changes: 3 additions & 3 deletions backend/app/api/v1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (b *BaseApi) LoadTimeOption(c *gin.Context) {
// @Summary load conf
// @Accept json
// @Param request body dto.OperationWithName true "request"
// @Success 200
// @Success 200 {array} string
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/device/conf [post]
Expand Down Expand Up @@ -185,7 +185,7 @@ func (b *BaseApi) UpdateDeviceSwap(c *gin.Context) {
// @Summary Check device DNS conf
// @Accept json
// @Param request body dto.SettingUpdate true "request"
// @Success 200
// @Success 200 {boolean} data
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/device/check/dns [post]
Expand All @@ -206,7 +206,7 @@ func (b *BaseApi) CheckDNS(c *gin.Context) {

// @Tags Device
// @Summary Scan system
// @Success 200
// @Success 200 {object} dto.CleanData
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/scan [post]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/fail2ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (b *BaseApi) UpdateFail2BanConf(c *gin.Context) {
// @Tags Fail2ban
// @Summary Load fail2ban conf
// @Accept json
// @Success 200
// @Success 200 {string} file
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /toolbox/fail2ban/load/conf [get]
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/v1/favorite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// @Summary List favorites
// @Accept json
// @Param request body dto.PageInfo true "request"
// @Success 200
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/favorite/search [post]
Expand All @@ -36,7 +36,7 @@ func (b *BaseApi) SearchFavorite(c *gin.Context) {
// @Summary Create favorite
// @Accept json
// @Param request body request.FavoriteCreate true "request"
// @Success 200
// @Success 200 {object} model.Favorite
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/favorite [post]
Expand Down
14 changes: 7 additions & 7 deletions backend/app/api/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func (b *BaseApi) ListFiles(c *gin.Context) {
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
files, err := fileService.GetFileList(req)
fileList, err := fileService.GetFileList(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, files)
helper.SuccessWithData(c, fileList)
}

// @Tags File
// @Summary Page file
// @Accept json
// @Param request body request.SearchUploadWithPage true "request"
// @Success 200 {array} response.FileInfo
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/upload/search [post]
Expand Down Expand Up @@ -401,7 +401,7 @@ func (b *BaseApi) UploadFiles(c *gin.Context) {
// @Summary Check file exist
// @Accept json
// @Param request body request.FilePathCheck true "request"
// @Success 200
// @Success 200 {boolean} isOk
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/check [post]
Expand Down Expand Up @@ -442,7 +442,7 @@ func (b *BaseApi) ChangeFileName(c *gin.Context) {
// @Summary Wget file
// @Accept json
// @Param request body request.FileWget true "request"
// @Success 200
// @Success 200 {object} response.FileWgetRes
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/wget [post]
Expand Down Expand Up @@ -584,7 +584,7 @@ func (b *BaseApi) DownloadChunkFiles(c *gin.Context) {
// @Summary Load file size
// @Accept json
// @Param request body request.DirSizeReq true "request"
// @Success 200
// @Success 200 {object} response.DirSizeRes
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/size [post]
Expand Down Expand Up @@ -786,7 +786,7 @@ func (b *BaseApi) Keys(c *gin.Context) {
// @Tags File
// @Summary Read file by Line
// @Param request body request.FileReadByLineReq true "request"
// @Success 200
// @Success 200 {object} response.FileLineContent
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /files/read [post]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The first line of the ListFiles function should be changed to use a struct literal instead of casting.
files, err := fileService.GetFiles(req)

2.helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) can be simplified to helper.FailWithDetail(c, "internal server error", err)

err = fileService.GetFileList(req)
if err != nil {
        helper.FailWithDetail(c, "failed to get file list", err)
        return
}

helper.SuccessWithData(c, fileList)
  1. The change from using constant.ErrTypeInternalServer to just stating "internal server error" is more explicit and cleaner.

  2. In the Keys function, if there are multiple keys that need to be returned, it might be better to have those values stored in an array or map before passing them to SuccessWithData.

In summary, these changes streamline some boilerplate code such as logging errors or formatting responses and make them easier to read and maintain.

Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *BaseApi) SearchFirewallRule(c *gin.Context) {
// @Summary Page firewall status
// @Accept json
// @Param request body dto.FirewallOperation true "request"
// @Success 200 {object} dto.PageResult
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/firewall/operate [post]
Expand Down
6 changes: 3 additions & 3 deletions backend/app/api/v1/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// @Summary Create host
// @Accept json
// @Param request body dto.HostOperate true "request"
// @Success 200
// @Success 200 {object} dto.HostInfo
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts [post]
Expand All @@ -35,7 +35,7 @@ func (b *BaseApi) CreateHost(c *gin.Context) {
// @Summary Test host conn by info
// @Accept json
// @Param request body dto.HostConnTest true "request"
// @Success 200
// @Success 200 {boolean} connStatus
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/test/byinfo [post]
Expand Down Expand Up @@ -95,7 +95,7 @@ func (b *BaseApi) HostTree(c *gin.Context) {
// @Summary Page host
// @Accept json
// @Param request body dto.SearchHostWithPage true "request"
// @Success 200 {array} dto.HostTree
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/search [post]
Expand Down
10 changes: 5 additions & 5 deletions backend/app/api/v1/host_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// @Summary Get tool status
// @Accept json
// @Param request body request.HostToolReq true "request"
// @Success 200
// @Success 200 {object} response.HostToolRes
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /host/tool [post]
Expand Down Expand Up @@ -77,7 +77,7 @@ func (b *BaseApi) OperateTool(c *gin.Context) {
// @Summary Get tool config
// @Accept json
// @Param request body request.HostToolConfig true "request"
// @Success 200
// @Success 200 {object} response.HostToolConfig
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /host/tool/config [post]
Expand All @@ -100,7 +100,7 @@ func (b *BaseApi) OperateToolConfig(c *gin.Context) {
// @Summary Get tool logs
// @Accept json
// @Param request body request.HostToolLogReq true "request"
// @Success 200
// @Success 200 {string} logContent
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /host/tool/log [post]
Expand Down Expand Up @@ -144,7 +144,7 @@ func (b *BaseApi) OperateProcess(c *gin.Context) {
// @Tags Host tool
// @Summary Get Supervisor process config
// @Accept json
// @Success 200
// @Success 200 {object} response.SupervisorProcessConfig
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /host/tool/supervisor/process [get]
Expand All @@ -161,7 +161,7 @@ func (b *BaseApi) GetProcess(c *gin.Context) {
// @Summary Get Supervisor process config
// @Accept json
// @Param request body request.SupervisorProcessFileReq true "request"
// @Success 200
// @Success 200 {string} content
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /host/tool/supervisor/process/file [post]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no irregularities or significant issues with this Go/Gin API code snippet based on the provided knowledge cutoff of September 1, 2021. However, here are some minor observations:

  1. Comment Update: The comment block for /host/tool/supervisor/process should reflect that it serves "Supervisor process config" rather than just being true.
// @Summary Get Supervisor process config
// @Desc        Retrieve the configuration details for Supervisor processes.

This change ensures clarity about what this endpoint actually accomplishes.

  1. Response Type for /host/tool/log:

    • Currently, /host/tool/log uses "logContent" in its @Success tag, which is not consistent. It might be more appropriate to return the actual log content, not just a placeholder string. For example:
      ["error", "warning", "info"]
  2. Consistency Across Endpoints: Ensure that all endpoints use uniform JSON responses unless they have specific data formats. This can make them easier to consume across different client applications.

  3. Logging: Ensure proper logging throughout the endpoints if required for debugging or monitoring purposes.

  4. Error Handling: Consider implementing better error handling practices, especially around invalid input data or unexpected errors during API operations.

These points, while not breaking any fundamental aspects of the code, could improve readability, consistency, and maintainability.

Expand Down
Loading
Loading