This commit is contained in:
@@ -7,7 +7,9 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/direktiv/apps/go/pkg/apps"
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
@@ -19,6 +21,9 @@ import (
|
||||
// swagger:model postParamsBody
|
||||
type PostParamsBody struct {
|
||||
|
||||
// File to create before running commands.
|
||||
Files []apps.DirektivFile `json:"files"`
|
||||
|
||||
// json input to convert to spreadsheet
|
||||
InData interface{} `json:"in-data,omitempty"`
|
||||
|
||||
@@ -38,6 +43,10 @@ type PostParamsBody struct {
|
||||
func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateFiles(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateOutFilename(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
@@ -52,6 +61,27 @@ func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PostParamsBody) validateFiles(formats strfmt.Registry) error {
|
||||
if swag.IsZero(m.Files) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.Files); i++ {
|
||||
|
||||
if err := m.Files[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("files" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("files" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PostParamsBody) validateOutFilename(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("out-filename", "body", m.OutFilename); err != nil {
|
||||
@@ -70,8 +100,35 @@ func (m *PostParamsBody) validateWorksheetName(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ContextValidate validates this post params body based on context it is used
|
||||
// ContextValidate validate this post params body based on the context it is used
|
||||
func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.contextValidateFiles(ctx, formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PostParamsBody) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {
|
||||
|
||||
for i := 0; i < len(m.Files); i++ {
|
||||
|
||||
if err := m.Files[i].ContextValidate(ctx, formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("files" + "." + strconv.Itoa(i))
|
||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||
return ce.ValidateName("files" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user