functionbuilder again
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-11-21 14:14:28 +11:00
parent d431eadbcc
commit e4392acbe3
5 changed files with 292 additions and 122 deletions

View File

@@ -9,7 +9,6 @@ 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"
@@ -21,34 +20,23 @@ import (
// swagger:model postParamsBody
type PostParamsBody struct {
// File to create before running commands.
Files []apps.DirektivFile `json:"files"`
// Name of the json input file to utilise
Infile string `json:"infile,omitempty"`
// the filename of the output spreadsheet
// Required: true
OutFilename *string `json:"out-filename"`
// Label for the worksheet created in the spreadsheet
// Required: true
WorksheetName *string `json:"worksheet-name"`
// Array of worksheets to create in spreadsheet
Sheets []*PostParamsBodySheetsItems `json:"sheets"`
}
// Validate validates this post params body
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)
}
if err := m.validateWorksheetName(formats); err != nil {
if err := m.validateSheets(formats); err != nil {
res = append(res, err)
}
@@ -58,27 +46,6 @@ 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 {
@@ -88,10 +55,27 @@ func (m *PostParamsBody) validateOutFilename(formats strfmt.Registry) error {
return nil
}
func (m *PostParamsBody) validateWorksheetName(formats strfmt.Registry) error {
func (m *PostParamsBody) validateSheets(formats strfmt.Registry) error {
if swag.IsZero(m.Sheets) { // not required
return nil
}
for i := 0; i < len(m.Sheets); i++ {
if swag.IsZero(m.Sheets[i]) { // not required
continue
}
if m.Sheets[i] != nil {
if err := m.Sheets[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("sheets" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("sheets" + "." + strconv.Itoa(i))
}
return err
}
}
if err := validate.Required("worksheet-name", "body", m.WorksheetName); err != nil {
return err
}
return nil
@@ -101,7 +85,7 @@ func (m *PostParamsBody) validateWorksheetName(formats strfmt.Registry) error {
func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateFiles(ctx, formats); err != nil {
if err := m.contextValidateSheets(ctx, formats); err != nil {
res = append(res, err)
}
@@ -111,17 +95,19 @@ func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Reg
return nil
}
func (m *PostParamsBody) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {
func (m *PostParamsBody) contextValidateSheets(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.Files); i++ {
for i := 0; i < len(m.Sheets); 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))
if m.Sheets[i] != nil {
if err := m.Sheets[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("sheets" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("sheets" + "." + strconv.Itoa(i))
}
return err
}
return err
}
}