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

🐛 POST analysis cannot return different resource. #352

Merged
merged 1 commit into from
May 26, 2023
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
1 change: 1 addition & 0 deletions addon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (r *Client) Post(path string, object interface{}) (err error) {
err = liberr.Wrap(err)
return
}
case http.StatusNoContent:
case http.StatusConflict:
err = &Conflict{Path: path}
default:
Expand Down
15 changes: 3 additions & 12 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ func (h AnalysisHandler) AppList(ctx *gin.Context) {
// @tags analyses
// @accept json
// @produce json
// @success 201 {object} api.Analysis
// @success 204
// @router /application/{id}/analyses [post]
// @param task body api.Analysis true "Analysis data"
// @param manifest body api.AnalysisManifest true "AnalysisManifest data"
func (h AnalysisHandler) AppCreate(ctx *gin.Context) {
id := h.pk(ctx)
r := &Analysis{}
Expand Down Expand Up @@ -276,17 +276,8 @@ func (h AnalysisHandler) AppCreate(ctx *gin.Context) {
return
}
}
//
// Fetch.
db = h.preLoad(h.DB(ctx), clause.Associations)
result := db.First(analysis, analysis.ID)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}
r.With(analysis)

h.Respond(ctx, http.StatusCreated, r)
h.Status(ctx, http.StatusNoContent)
}

// Delete godoc
Expand Down
1 change: 1 addition & 0 deletions binding/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (r *Client) Post(path string, object interface{}) (err error) {
err = liberr.Wrap(err)
return
}
case http.StatusNoContent:
case http.StatusConflict:
err = &Conflict{Path: path}
default:
Expand Down
38 changes: 29 additions & 9 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,18 @@ const docTemplate = `{
"summary": "Create an analysis.",
"parameters": [
{
"description": "Analysis data",
"name": "task",
"description": "AnalysisManifest data",
"name": "manifest",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.Analysis"
"$ref": "#/definitions/api.AnalysisManifest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/api.Analysis"
}
"204": {
"description": "No Content"
}
}
}
Expand Down Expand Up @@ -4540,6 +4537,29 @@ const docTemplate = `{
}
}
},
"api.AnalysisManifest": {
"type": "object",
"properties": {
"createTime": {
"type": "string"
},
"createUser": {
"type": "string"
},
"dependencies": {
"$ref": "#/definitions/api.Ref"
},
"id": {
"type": "integer"
},
"issues": {
"$ref": "#/definitions/api.Ref"
},
"updateUser": {
"type": "string"
}
}
},
"api.Application": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5297,7 +5317,7 @@ const docTemplate = `{
"rule": {
"type": "string"
},
"ruleSet": {
"ruleset": {
"type": "string"
}
}
Expand Down
38 changes: 29 additions & 9 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,18 @@
"summary": "Create an analysis.",
"parameters": [
{
"description": "Analysis data",
"name": "task",
"description": "AnalysisManifest data",
"name": "manifest",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.Analysis"
"$ref": "#/definitions/api.AnalysisManifest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/api.Analysis"
}
"204": {
"description": "No Content"
}
}
}
Expand Down Expand Up @@ -4528,6 +4525,29 @@
}
}
},
"api.AnalysisManifest": {
"type": "object",
"properties": {
"createTime": {
"type": "string"
},
"createUser": {
"type": "string"
},
"dependencies": {
"$ref": "#/definitions/api.Ref"
},
"id": {
"type": "integer"
},
"issues": {
"$ref": "#/definitions/api.Ref"
},
"updateUser": {
"type": "string"
}
}
},
"api.Application": {
"type": "object",
"required": [
Expand Down Expand Up @@ -5285,7 +5305,7 @@
"rule": {
"type": "string"
},
"ruleSet": {
"ruleset": {
"type": "string"
}
}
Expand Down
29 changes: 21 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ definitions:
updateUser:
type: string
type: object
api.AnalysisManifest:
properties:
createTime:
type: string
createUser:
type: string
dependencies:
$ref: '#/definitions/api.Ref'
id:
type: integer
issues:
$ref: '#/definitions/api.Ref'
updateUser:
type: string
type: object
api.Application:
properties:
binary:
Expand Down Expand Up @@ -527,7 +542,7 @@ definitions:
type: string
rule:
type: string
ruleSet:
ruleset:
type: string
type: object
api.RuleSet:
Expand Down Expand Up @@ -1187,19 +1202,17 @@ paths:
An issues file that multiple issue resources.
A dependencies file that contains an array of dependencies.
parameters:
- description: Analysis data
- description: AnalysisManifest data
in: body
name: task
name: manifest
required: true
schema:
$ref: '#/definitions/api.Analysis'
$ref: '#/definitions/api.AnalysisManifest'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/api.Analysis'
"204":
description: No Content
summary: Create an analysis.
tags:
- analyses
Expand Down