[#15] Use status code 200 with payload on success
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
686588bc1a
commit
e28c6e5375
10 changed files with 249 additions and 47 deletions
|
@ -464,7 +464,9 @@ func restObjectDelete(ctx context.Context, t *testing.T, p *pool.Pool, cnrID *ci
|
|||
require.NoError(t, err)
|
||||
prepareCommonHeaders(request.Header, bearerToken)
|
||||
|
||||
doRequest(t, httpClient, request, http.StatusNoContent, nil)
|
||||
resp := &models.SuccessResponse{}
|
||||
doRequest(t, httpClient, request, http.StatusOK, resp)
|
||||
require.True(t, *resp.Success)
|
||||
|
||||
var addr address.Address
|
||||
addr.SetContainerID(cnrID)
|
||||
|
@ -605,7 +607,9 @@ func restContainerDelete(ctx context.Context, t *testing.T, clientPool *pool.Poo
|
|||
request = request.WithContext(ctx)
|
||||
prepareCommonHeaders(request.Header, bearerToken)
|
||||
|
||||
doRequest(t, httpClient, request, http.StatusNoContent, nil)
|
||||
resp := &models.SuccessResponse{}
|
||||
doRequest(t, httpClient, request, http.StatusOK, resp)
|
||||
require.True(t, *resp.Success)
|
||||
|
||||
var prm pool.PrmContainerGet
|
||||
prm.SetContainerID(*cnrID)
|
||||
|
@ -649,7 +653,9 @@ func restContainerEACLPut(ctx context.Context, t *testing.T, clientPool *pool.Po
|
|||
request = request.WithContext(ctx)
|
||||
prepareCommonHeaders(request.Header, bearerToken)
|
||||
|
||||
doRequest(t, httpClient, request, http.StatusOK, nil)
|
||||
resp := &models.SuccessResponse{}
|
||||
doRequest(t, httpClient, request, http.StatusOK, resp)
|
||||
require.True(t, *resp.Success)
|
||||
|
||||
var prm pool.PrmContainerEACL
|
||||
prm.SetContainerID(*cnrID)
|
||||
|
|
71
gen/models/success_response.go
Normal file
71
gen/models/success_response.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// SuccessResponse success response
|
||||
//
|
||||
// swagger:model SuccessResponse
|
||||
type SuccessResponse struct {
|
||||
|
||||
// success
|
||||
// Required: true
|
||||
Success *bool `json:"success"`
|
||||
}
|
||||
|
||||
// Validate validates this success response
|
||||
func (m *SuccessResponse) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateSuccess(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SuccessResponse) validateSuccess(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("success", "body", m.Success); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this success response based on context it is used
|
||||
func (m *SuccessResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *SuccessResponse) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *SuccessResponse) UnmarshalBinary(b []byte) error {
|
||||
var res SuccessResponse
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
|
@ -241,8 +241,11 @@ func init() {
|
|||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Successul deletion"
|
||||
"200": {
|
||||
"description": "Successful deletion",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -303,7 +306,10 @@ func init() {
|
|||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successfule EACL upading"
|
||||
"description": "Successful EACL updating",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -472,8 +478,11 @@ func init() {
|
|||
"summary": "Remove object from NeoFS",
|
||||
"operationId": "deleteObject",
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Successful deletion"
|
||||
"200": {
|
||||
"description": "Successful deletion",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -950,6 +959,17 @@ func init() {
|
|||
"MatchCommonPrefix"
|
||||
]
|
||||
},
|
||||
"SuccessResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Target": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -1318,8 +1338,11 @@ func init() {
|
|||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Successul deletion"
|
||||
"200": {
|
||||
"description": "Successful deletion",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -1396,7 +1419,10 @@ func init() {
|
|||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successfule EACL upading"
|
||||
"description": "Successful EACL updating",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -1600,8 +1626,11 @@ func init() {
|
|||
"summary": "Remove object from NeoFS",
|
||||
"operationId": "deleteObject",
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "Successful deletion"
|
||||
"200": {
|
||||
"description": "Successful deletion",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/SuccessResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -2098,6 +2127,17 @@ func init() {
|
|||
"MatchCommonPrefix"
|
||||
]
|
||||
},
|
||||
"SuccessResponse": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"success"
|
||||
],
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Target": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
|
@ -13,28 +13,48 @@ import (
|
|||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||
)
|
||||
|
||||
// DeleteContainerNoContentCode is the HTTP code returned for type DeleteContainerNoContent
|
||||
const DeleteContainerNoContentCode int = 204
|
||||
// DeleteContainerOKCode is the HTTP code returned for type DeleteContainerOK
|
||||
const DeleteContainerOKCode int = 200
|
||||
|
||||
/*DeleteContainerNoContent Successul deletion
|
||||
/*DeleteContainerOK Successful deletion
|
||||
|
||||
swagger:response deleteContainerNoContent
|
||||
swagger:response deleteContainerOK
|
||||
*/
|
||||
type DeleteContainerNoContent struct {
|
||||
type DeleteContainerOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.SuccessResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewDeleteContainerNoContent creates DeleteContainerNoContent with default headers values
|
||||
func NewDeleteContainerNoContent() *DeleteContainerNoContent {
|
||||
// NewDeleteContainerOK creates DeleteContainerOK with default headers values
|
||||
func NewDeleteContainerOK() *DeleteContainerOK {
|
||||
|
||||
return &DeleteContainerNoContent{}
|
||||
return &DeleteContainerOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the delete container o k response
|
||||
func (o *DeleteContainerOK) WithPayload(payload *models.SuccessResponse) *DeleteContainerOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the delete container o k response
|
||||
func (o *DeleteContainerOK) SetPayload(payload *models.SuccessResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DeleteContainerNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
func (o *DeleteContainerOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(204)
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteContainerBadRequestCode is the HTTP code returned for type DeleteContainerBadRequest
|
||||
|
|
|
@ -13,28 +13,48 @@ import (
|
|||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||
)
|
||||
|
||||
// DeleteObjectNoContentCode is the HTTP code returned for type DeleteObjectNoContent
|
||||
const DeleteObjectNoContentCode int = 204
|
||||
// DeleteObjectOKCode is the HTTP code returned for type DeleteObjectOK
|
||||
const DeleteObjectOKCode int = 200
|
||||
|
||||
/*DeleteObjectNoContent Successful deletion
|
||||
/*DeleteObjectOK Successful deletion
|
||||
|
||||
swagger:response deleteObjectNoContent
|
||||
swagger:response deleteObjectOK
|
||||
*/
|
||||
type DeleteObjectNoContent struct {
|
||||
type DeleteObjectOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.SuccessResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewDeleteObjectNoContent creates DeleteObjectNoContent with default headers values
|
||||
func NewDeleteObjectNoContent() *DeleteObjectNoContent {
|
||||
// NewDeleteObjectOK creates DeleteObjectOK with default headers values
|
||||
func NewDeleteObjectOK() *DeleteObjectOK {
|
||||
|
||||
return &DeleteObjectNoContent{}
|
||||
return &DeleteObjectOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the delete object o k response
|
||||
func (o *DeleteObjectOK) WithPayload(payload *models.SuccessResponse) *DeleteObjectOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the delete object o k response
|
||||
func (o *DeleteObjectOK) SetPayload(payload *models.SuccessResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DeleteObjectNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
func (o *DeleteObjectOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(204)
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteObjectBadRequestCode is the HTTP code returned for type DeleteObjectBadRequest
|
||||
|
|
|
@ -16,11 +16,16 @@ import (
|
|||
// PutContainerEACLOKCode is the HTTP code returned for type PutContainerEACLOK
|
||||
const PutContainerEACLOKCode int = 200
|
||||
|
||||
/*PutContainerEACLOK Successfule EACL upading
|
||||
/*PutContainerEACLOK Successful EACL updating
|
||||
|
||||
swagger:response putContainerEAclOK
|
||||
*/
|
||||
type PutContainerEACLOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.SuccessResponse `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewPutContainerEACLOK creates PutContainerEACLOK with default headers values
|
||||
|
@ -29,12 +34,27 @@ func NewPutContainerEACLOK() *PutContainerEACLOK {
|
|||
return &PutContainerEACLOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the put container e Acl o k response
|
||||
func (o *PutContainerEACLOK) WithPayload(payload *models.SuccessResponse) *PutContainerEACLOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the put container e Acl o k response
|
||||
func (o *PutContainerEACLOK) SetPayload(payload *models.SuccessResponse) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *PutContainerEACLOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PutContainerEACLBadRequestCode is the HTTP code returned for type PutContainerEACLBadRequest
|
||||
|
|
|
@ -109,7 +109,7 @@ func (a *API) PutContainerEACL(params operations.PutContainerEACLParams, princip
|
|||
return operations.NewPutContainerEACLBadRequest().WithPayload(util.NewError(err))
|
||||
}
|
||||
|
||||
return operations.NewPutContainerEACLOK()
|
||||
return operations.NewPutContainerEACLOK().WithPayload(util.NewSuccessResponse())
|
||||
}
|
||||
|
||||
// GetContainerEACL handler that returns container eacl.
|
||||
|
@ -208,7 +208,7 @@ func (a *API) DeleteContainer(params operations.DeleteContainerParams, principal
|
|||
return operations.NewDeleteContainerBadRequest().WithPayload(util.NewError(err))
|
||||
}
|
||||
|
||||
return operations.NewDeleteContainerNoContent()
|
||||
return operations.NewDeleteContainerOK().WithPayload(util.NewSuccessResponse())
|
||||
}
|
||||
|
||||
func getContainerBaseInfo(ctx context.Context, p *pool.Pool, cnrID cid.ID) (*models.ContainerBaseInfo, error) {
|
||||
|
|
|
@ -199,7 +199,7 @@ func (a *API) DeleteObject(params operations.DeleteObjectParams, principal *mode
|
|||
return errorResponse.WithPayload(util.NewError(err))
|
||||
}
|
||||
|
||||
return operations.NewDeleteObjectNoContent()
|
||||
return operations.NewDeleteObjectOK().WithPayload(util.NewSuccessResponse())
|
||||
}
|
||||
|
||||
// SearchObjects handler that removes object from NeoFS.
|
||||
|
|
|
@ -440,7 +440,19 @@ func NewInteger(val int64) *int64 {
|
|||
return &val
|
||||
}
|
||||
|
||||
// NewBool returns pointer to provided bool.
|
||||
func NewBool(val bool) *bool {
|
||||
return &val
|
||||
}
|
||||
|
||||
// NewError wraps error into models.Error.
|
||||
func NewError(err error) models.Error {
|
||||
return models.Error(err.Error())
|
||||
}
|
||||
|
||||
// NewSuccessResponse forms model.SuccessResponse.
|
||||
func NewSuccessResponse() *models.SuccessResponse {
|
||||
return &models.SuccessResponse{
|
||||
Success: NewBool(true),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,8 +202,10 @@ paths:
|
|||
operationId: deleteObject
|
||||
summary: Remove object from NeoFS
|
||||
responses:
|
||||
204:
|
||||
200:
|
||||
description: Successful deletion
|
||||
schema:
|
||||
$ref: '#/definitions/SuccessResponse'
|
||||
400:
|
||||
description: Bad request
|
||||
schema:
|
||||
|
@ -312,8 +314,10 @@ paths:
|
|||
- $ref: '#/parameters/signatureKeyParam'
|
||||
- $ref: '#/parameters/signatureScheme'
|
||||
responses:
|
||||
204:
|
||||
description: Successul deletion
|
||||
200:
|
||||
description: Successful deletion
|
||||
schema:
|
||||
$ref: '#/definitions/SuccessResponse'
|
||||
400:
|
||||
description: Bad request
|
||||
schema:
|
||||
|
@ -336,7 +340,9 @@ paths:
|
|||
$ref: '#/definitions/Eacl'
|
||||
responses:
|
||||
200:
|
||||
description: Successfule EACL upading
|
||||
description: Successful EACL updating
|
||||
schema:
|
||||
$ref: '#/definitions/SuccessResponse'
|
||||
400:
|
||||
description: Bad request
|
||||
schema:
|
||||
|
@ -706,3 +712,10 @@ definitions:
|
|||
type: string
|
||||
Error:
|
||||
type: string
|
||||
SuccessResponse:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
|
|
Reference in a new issue