Skip to content

Commit

Permalink
Fix: incorrect API response mark (#864)
Browse files Browse the repository at this point in the history
Co-authored-by: Z Zhang <zuoning@AndrewZs-MacBook-Air.local>
  • Loading branch information
zuoningz and Z Zhang authored Jul 27, 2023
1 parent 3978079 commit d0b2a3b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
18 changes: 10 additions & 8 deletions pkg/server/interfaces/api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("page", "query the page number").DataType("integer")).
Param(ws.QueryParameter("pageSize", "query the page size number").DataType("integer")).
Returns(200, "OK", apis.ListWorkflowRecordsResponse{}).
Writes(apis.ListWorkflowRecordsResponse{}).Do(returns200, returns500))
Writes(apis.ListWorkflowRecordsResponse{}).Do(returns500))

ws.Route(ws.GET("/{appName}/workflows").To(c.WorkflowAPI.listApplicationWorkflows).
Doc("list application workflow").
Expand All @@ -475,7 +475,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Param(ws.PathParameter("appName", "identifier of the application.").DataType("string").Required(true)).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", apis.ListWorkflowResponse{}).
Writes(apis.ListWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.ListWorkflowResponse{}).Do(returns500))

ws.Route(ws.POST("/{appName}/workflows").To(c.WorkflowAPI.createOrUpdateApplicationWorkflow).
Doc("create application workflow").
Expand All @@ -486,7 +486,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Param(ws.PathParameter("appName", "identifier of the application.").DataType("string").Required(true)).
Returns(200, "create success", apis.DetailWorkflowResponse{}).
Returns(400, "create failure", bcode.Bcode{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.DetailWorkflowResponse{}).Do(returns500))

ws.Route(ws.GET("/{appName}/workflows/{workflowName}").To(c.WorkflowAPI.detailWorkflow).
Doc("detail application workflow").
Expand All @@ -498,7 +498,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(c.WorkflowAPI.workflowCheckFilter).
Returns(200, "create success", apis.DetailWorkflowResponse{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.DetailWorkflowResponse{}).Do(returns500))

ws.Route(ws.PUT("/{appName}/workflows/{workflowName}").To(c.WorkflowAPI.updateWorkflow).
Doc("update application workflow config").
Expand All @@ -510,7 +510,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Param(ws.PathParameter("workflowName", "identifier of the workflow").DataType("string")).
Reads(apis.UpdateWorkflowRequest{}).
Returns(200, "OK", apis.DetailWorkflowResponse{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.DetailWorkflowResponse{}).Do(returns500))

ws.Route(ws.DELETE("/{appName}/workflows/{workflowName}").To(c.WorkflowAPI.deleteWorkflow).
Doc("deletet workflow").
Expand All @@ -520,7 +520,6 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Filter(c.WorkflowAPI.workflowCheckFilter).
Param(ws.PathParameter("appName", "identifier of the application.").DataType("string").Required(true)).
Param(ws.PathParameter("workflowName", "identifier of the workflow").DataType("string")).
Returns(200, "OK", apis.EmptyResponse{}).
Writes(apis.EmptyResponse{}).Do(returns200, returns500))

ws.Route(ws.GET("/{appName}/workflows/{workflowName}/records").To(c.WorkflowAPI.listWorkflowRecords).
Expand All @@ -534,7 +533,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("page", "query the page number").DataType("integer")).
Param(ws.QueryParameter("pageSize", "query the page size number").DataType("integer")).
Returns(200, "OK", apis.ListWorkflowRecordsResponse{}).
Writes(apis.ListWorkflowRecordsResponse{}).Do(returns200, returns500))
Writes(apis.ListWorkflowRecordsResponse{}).Do(returns500))

ws.Route(ws.GET("/{appName}/workflows/{workflowName}/records/{record}").To(c.WorkflowAPI.detailWorkflowRecord).
Doc("query application workflow execution record detail").
Expand All @@ -546,7 +545,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
Filter(c.appCheckFilter).
Filter(c.WorkflowAPI.workflowCheckFilter).
Returns(200, "OK", apis.DetailWorkflowRecordResponse{}).
Writes(apis.DetailWorkflowRecordResponse{}).Do(returns200, returns500))
Writes(apis.DetailWorkflowRecordResponse{}).Do(returns500))

ws.Route(ws.GET("/{appName}/workflows/{workflowName}/records/{record}/resume").To(c.WorkflowAPI.resumeWorkflowRecord).
Doc("resume suspend workflow record").
Expand Down Expand Up @@ -684,16 +683,19 @@ func (c *application) createApplication(req *restful.Request, res *restful.Respo
// Verify the validity of parameters
var createReq apis.CreateApplicationRequest
if err := req.ReadEntity(&createReq); err != nil {
klog.Info("param err ", err)
bcode.ReturnError(req, res, err)
return
}
if err := validate.Struct(&createReq); err != nil {
klog.Info("validate struct err ", err)
bcode.ReturnError(req, res, err)
return
}
// Call the domain layer code
appBase, err := c.ApplicationService.CreateApplication(req.Request.Context(), createReq)
if err != nil {
klog.Info("Failure: ", err.Error())
klog.Errorf("create application failure %s", err.Error())
bcode.ReturnError(req, res, err)
return
Expand Down
5 changes: 1 addition & 4 deletions pkg/server/interfaces/api/cloudshell.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ func (c *CloudShell) GetWebServiceRoute() *restful.WebService {
Filter(c.RbacService.CheckPerm("cloudshell", "create")).
Returns(200, "OK", apis.CloudShellPrepareResponse{}).
Returns(400, "Bad Request", bcode.Bcode{}).
Writes(apis.CloudShellPrepareResponse{}).Do(returns200, returns500))
Writes(apis.CloudShellPrepareResponse{}).Do(returns500))

ws.Route(ws.DELETE("/").To(c.destroyCloudShell).
Doc("destroy the user's cloud shell environment").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(c.RbacService.CheckPerm("cloudshell", "delete")).
Returns(200, "OK", apis.EmptyResponse{}).
Returns(400, "Bad Request", bcode.Bcode{}).
Writes(apis.EmptyResponse{}).Do(returns200, returns500))

Expand Down Expand Up @@ -128,7 +127,6 @@ func (c *CloudShellView) GetWebServiceRoute() *restful.WebService {
Doc("prepare the user's cloud shell environment").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(c.RbacService.CheckPerm("cloudshell", "create")).
Returns(200, "OK", apis.EmptyResponse{}).
Returns(400, "Bad Request", bcode.Bcode{}).
Writes(apis.EmptyResponse{}).Do(returns200, returns500))

Expand All @@ -138,7 +136,6 @@ func (c *CloudShellView) GetWebServiceRoute() *restful.WebService {
Operation("proxyPath").
Param(ws.PathParameter("subpath", "subpath").DataType("string")).
Filter(c.RbacService.CheckPerm("cloudshell", "create")).
Returns(200, "OK", apis.EmptyResponse{}).
Returns(400, "Bad Request", bcode.Bcode{}).
Writes(apis.EmptyResponse{}).Do(returns200, returns500))

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/interfaces/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Cluster) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("pageSize", "PageSize for paging").DataType("integer").DefaultValue("20")).
Returns(200, "OK", apis.ListClusterResponse{}).
Returns(400, "Bad Request", bcode.Bcode{}).
Writes(apis.ListClusterResponse{}).Do(returns200, returns500))
Writes(apis.ListClusterResponse{}).Do(returns500))

ws.Route(ws.POST("/").To(c.createKubeCluster).
Doc("create cluster").
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/interfaces/api/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("ownerAddon", "query by which addon created the definition").DataType("string")).
Param(ws.QueryParameter("scope", "query by the specified scope like WorkflowRun or Application").DataType("string")).
Returns(200, "OK", apis.ListDefinitionResponse{}).
Writes(apis.ListDefinitionResponse{}).Do(returns200, returns500))
Writes(apis.ListDefinitionResponse{}).Do(returns500))

ws.Route(ws.GET("/{definitionName}").To(d.detailDefinition).
Doc("Detail a definition").
Expand All @@ -63,7 +63,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("type", "query the definition type").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "create successfully", apis.DetailDefinitionResponse{}).
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
Writes(apis.DetailDefinitionResponse{}).Do(returns500))

ws.Route(ws.PUT("/{definitionName}/uischema").To(d.updateUISchema).
Doc("Update the UI schema for a definition").
Expand All @@ -72,7 +72,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
Param(ws.PathParameter("definitionName", "identifier of the definition").DataType("string").Required(true)).
Reads(apis.UpdateUISchemaRequest{}).
Returns(200, "update successfully", schema.UISchema{}).
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
Writes(apis.DetailDefinitionResponse{}).Do(returns500))

ws.Route(ws.PUT("/{definitionName}/status").To(d.updateDefinitionStatus).
Doc("Update the status for a definition").
Expand All @@ -81,7 +81,7 @@ func (d *definition) GetWebServiceRoute() *restful.WebService {
Param(ws.PathParameter("definitionName", "identifier of the definition").DataType("string").Required(true)).
Reads(apis.UpdateDefinitionStatusRequest{}).
Returns(200, "update successfully", schema.UISchema{}).
Writes(apis.DetailDefinitionResponse{}).Do(returns200, returns500))
Writes(apis.DetailDefinitionResponse{}).Do(returns500))

ws.Filter(authCheckFilter)
return ws
Expand Down
26 changes: 17 additions & 9 deletions pkg/server/interfaces/api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ func (p *Plugin) GetWebServiceRoute() *restful.WebService {
Doc("List the enabled plugins").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", apis.ListPluginResponse{}).
Writes(apis.ListPluginResponse{}).Do(returns200, returns500))
Writes(apis.ListPluginResponse{}).Do(returns500))

ws.Route(ws.GET("/{pluginId}").To(p.detailPlugin).
Doc("Detail an installed plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.PluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Filter(authCheckFilter)
return ws
Expand All @@ -88,51 +89,57 @@ func (p *ManagePlugin) GetWebServiceRoute() *restful.WebService {
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(p.RBACService.CheckPerm("managePlugin", "list")).
Returns(200, "OK", apis.ListPluginResponse{}).
Writes(apis.ListManagedPluginResponse{}).Do(returns200, returns500))
Writes(apis.ListPluginResponse{}).Do(returns500))

ws.Route(ws.GET("/{pluginId}").To(p.detailPlugin).
Doc("Detail an installed plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(p.RBACService.CheckPerm("managePlugin", "detail")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.ManagedPluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Route(ws.POST("/{pluginId}/setting").To(p.pluginSetting).
Doc("Set an installed plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(p.RBACService.CheckPerm("managePlugin", "update")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.ManagedPluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Route(ws.POST("/{pluginId}/install").To(p.installPlugin).
Doc("Install one specific plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(apis.InstallPluginRequest{}).
Filter(p.RBACService.CheckPerm("managePlugin", "enable")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.ManagedPluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Route(ws.POST("/{pluginId}/uninstall").To(p.uninstallPlugin).
Doc("Uninstall one specific plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(p.RBACService.CheckPerm("managePlugin", "enable")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", struct{}{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Route(ws.POST("/{pluginId}/enable").To(p.enablePlugin).
Doc("Enable an installed plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(apis.PluginEnableRequest{}).
Filter(p.RBACService.CheckPerm("managePlugin", "enable")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.ManagedPluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Route(ws.POST("/{pluginId}/disable").To(p.disablePlugin).
Doc("Disable an installed plugin").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(p.RBACService.CheckPerm("managePlugin", "enable")).
Param(ws.PathParameter("pluginId", "identifier of the plugin.").DataType("string")).
Returns(200, "OK", apis.ManagedPluginDTO{}).
Writes(apis.PluginDTO{}).Do(returns200, returns500))
Writes(apis.PluginDTO{}).Do(returns500))

ws.Filter(authCheckFilter)
return ws
Expand Down Expand Up @@ -205,6 +212,7 @@ func (p *ManagePlugin) uninstallPlugin(req *restful.Request, res *restful.Respon
}

func (p *ManagePlugin) detailPlugin(req *restful.Request, res *restful.Response) {

plugin, err := p.PluginService.DetailInstalledPlugin(req.Request.Context(), req.PathParameter("pluginId"))
if err != nil {
bcode.ReturnError(req, res, err)
Expand Down
9 changes: 4 additions & 5 deletions pkg/server/interfaces/api/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (dt *Target) GetWebServiceRoute() *restful.WebService {
Param(ws.QueryParameter("pageSize", "PageSize for paging").DataType("integer")).
Param(ws.QueryParameter("project", "list targets by project name").DataType("string")).
Returns(200, "OK", apis.ListTargetResponse{}).
Writes(apis.ListTargetResponse{}).Do(returns200, returns500))
Writes(apis.ListTargetResponse{}).Do(returns500))

ws.Route(ws.POST("/").To(dt.createTarget).
Doc("create Target").
Expand All @@ -73,7 +73,7 @@ func (dt *Target) GetWebServiceRoute() *restful.WebService {
Filter(dt.RbacService.CheckPerm("target", "create")).
Returns(200, "create success", apis.DetailTargetResponse{}).
Returns(400, "create failure", bcode.Bcode{}).
Writes(apis.DetailTargetResponse{}).Do(returns200, returns500))
Writes(apis.DetailTargetResponse{}).Do(returns500))

ws.Route(ws.GET("/{targetName}").To(dt.detailTarget).
Doc("detail Target").
Expand All @@ -82,7 +82,7 @@ func (dt *Target) GetWebServiceRoute() *restful.WebService {
Filter(dt.targetCheckFilter).
Filter(dt.RbacService.CheckPerm("target", "detail")).
Returns(200, "create success", apis.DetailTargetResponse{}).
Writes(apis.DetailTargetResponse{}).Do(returns200, returns500))
Writes(apis.DetailTargetResponse{}).Do(returns500))

ws.Route(ws.PUT("/{targetName}").To(dt.updateTarget).
Doc("update application Target config").
Expand All @@ -92,15 +92,14 @@ func (dt *Target) GetWebServiceRoute() *restful.WebService {
Reads(apis.UpdateTargetRequest{}).
Filter(dt.RbacService.CheckPerm("target", "update")).
Returns(200, "OK", apis.DetailTargetResponse{}).
Writes(apis.DetailTargetResponse{}).Do(returns200, returns500))
Writes(apis.DetailTargetResponse{}).Do(returns500))

ws.Route(ws.DELETE("/{targetName}").To(dt.deleteTarget).
Doc("deletet Target").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(dt.targetCheckFilter).
Filter(dt.RbacService.CheckPerm("target", "delete")).
Param(ws.PathParameter("targetName", "identifier of the Target").DataType("string")).
Returns(200, "OK", apis.EmptyResponse{}).
Writes(apis.EmptyResponse{}).Do(returns200, returns500))

ws.Filter(authCheckFilter)
Expand Down

0 comments on commit d0b2a3b

Please sign in to comment.