...

Source file src/github.com/sigstore/rekor/pkg/generated/models/search_log_query.go

Documentation: github.com/sigstore/rekor/pkg/generated/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  //
     4  // Copyright 2021 The Sigstore Authors.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  //
    18  
    19  package models
    20  
    21  // This file was generated by the swagger tool.
    22  // Editing this file might prove futile when you re-run the swagger generate command
    23  
    24  import (
    25  	"bytes"
    26  	"context"
    27  	"encoding/json"
    28  	"io"
    29  	"strconv"
    30  
    31  	"github.com/go-openapi/errors"
    32  	"github.com/go-openapi/runtime"
    33  	"github.com/go-openapi/strfmt"
    34  	"github.com/go-openapi/swag"
    35  	"github.com/go-openapi/validate"
    36  )
    37  
    38  // SearchLogQuery search log query
    39  //
    40  // swagger:model SearchLogQuery
    41  type SearchLogQuery struct {
    42  	entriesField []ProposedEntry
    43  
    44  	// entry u UI ds
    45  	// Max Items: 10
    46  	// Min Items: 1
    47  	EntryUUIDs []string `json:"entryUUIDs"`
    48  
    49  	// log indexes
    50  	// Max Items: 10
    51  	// Min Items: 1
    52  	LogIndexes []*int64 `json:"logIndexes"`
    53  }
    54  
    55  // Entries gets the entries of this base type
    56  func (m *SearchLogQuery) Entries() []ProposedEntry {
    57  	return m.entriesField
    58  }
    59  
    60  // SetEntries sets the entries of this base type
    61  func (m *SearchLogQuery) SetEntries(val []ProposedEntry) {
    62  	m.entriesField = val
    63  }
    64  
    65  // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
    66  func (m *SearchLogQuery) UnmarshalJSON(raw []byte) error {
    67  	var data struct {
    68  		Entries json.RawMessage `json:"entries"`
    69  
    70  		EntryUUIDs []string `json:"entryUUIDs"`
    71  
    72  		LogIndexes []*int64 `json:"logIndexes"`
    73  	}
    74  	buf := bytes.NewBuffer(raw)
    75  	dec := json.NewDecoder(buf)
    76  	dec.UseNumber()
    77  
    78  	if err := dec.Decode(&data); err != nil {
    79  		return err
    80  	}
    81  
    82  	var propEntries []ProposedEntry
    83  	if string(data.Entries) != "null" {
    84  		entries, err := UnmarshalProposedEntrySlice(bytes.NewBuffer(data.Entries), runtime.JSONConsumer())
    85  		if err != nil && err != io.EOF {
    86  			return err
    87  		}
    88  		propEntries = entries
    89  	}
    90  
    91  	var result SearchLogQuery
    92  
    93  	// entries
    94  	result.entriesField = propEntries
    95  
    96  	// entryUUIDs
    97  	result.EntryUUIDs = data.EntryUUIDs
    98  
    99  	// logIndexes
   100  	result.LogIndexes = data.LogIndexes
   101  
   102  	*m = result
   103  
   104  	return nil
   105  }
   106  
   107  // MarshalJSON marshals this object with a polymorphic type to a JSON structure
   108  func (m SearchLogQuery) MarshalJSON() ([]byte, error) {
   109  	var b1, b2, b3 []byte
   110  	var err error
   111  	b1, err = json.Marshal(struct {
   112  		EntryUUIDs []string `json:"entryUUIDs"`
   113  
   114  		LogIndexes []*int64 `json:"logIndexes"`
   115  	}{
   116  
   117  		EntryUUIDs: m.EntryUUIDs,
   118  
   119  		LogIndexes: m.LogIndexes,
   120  	})
   121  	if err != nil {
   122  		return nil, err
   123  	}
   124  	b2, err = json.Marshal(struct {
   125  		Entries []ProposedEntry `json:"entries"`
   126  	}{
   127  
   128  		Entries: m.entriesField,
   129  	})
   130  	if err != nil {
   131  		return nil, err
   132  	}
   133  
   134  	return swag.ConcatJSON(b1, b2, b3), nil
   135  }
   136  
   137  // Validate validates this search log query
   138  func (m *SearchLogQuery) Validate(formats strfmt.Registry) error {
   139  	var res []error
   140  
   141  	if err := m.validateEntries(formats); err != nil {
   142  		res = append(res, err)
   143  	}
   144  
   145  	if err := m.validateEntryUUIDs(formats); err != nil {
   146  		res = append(res, err)
   147  	}
   148  
   149  	if err := m.validateLogIndexes(formats); err != nil {
   150  		res = append(res, err)
   151  	}
   152  
   153  	if len(res) > 0 {
   154  		return errors.CompositeValidationError(res...)
   155  	}
   156  	return nil
   157  }
   158  
   159  func (m *SearchLogQuery) validateEntries(formats strfmt.Registry) error {
   160  	if swag.IsZero(m.Entries()) { // not required
   161  		return nil
   162  	}
   163  
   164  	iEntriesSize := int64(len(m.Entries()))
   165  
   166  	if err := validate.MinItems("entries", "body", iEntriesSize, 1); err != nil {
   167  		return err
   168  	}
   169  
   170  	if err := validate.MaxItems("entries", "body", iEntriesSize, 10); err != nil {
   171  		return err
   172  	}
   173  
   174  	for i := 0; i < len(m.Entries()); i++ {
   175  
   176  		if err := m.entriesField[i].Validate(formats); err != nil {
   177  			if ve, ok := err.(*errors.Validation); ok {
   178  				return ve.ValidateName("entries" + "." + strconv.Itoa(i))
   179  			} else if ce, ok := err.(*errors.CompositeError); ok {
   180  				return ce.ValidateName("entries" + "." + strconv.Itoa(i))
   181  			}
   182  			return err
   183  		}
   184  
   185  	}
   186  
   187  	return nil
   188  }
   189  
   190  func (m *SearchLogQuery) validateEntryUUIDs(formats strfmt.Registry) error {
   191  	if swag.IsZero(m.EntryUUIDs) { // not required
   192  		return nil
   193  	}
   194  
   195  	iEntryUUIDsSize := int64(len(m.EntryUUIDs))
   196  
   197  	if err := validate.MinItems("entryUUIDs", "body", iEntryUUIDsSize, 1); err != nil {
   198  		return err
   199  	}
   200  
   201  	if err := validate.MaxItems("entryUUIDs", "body", iEntryUUIDsSize, 10); err != nil {
   202  		return err
   203  	}
   204  
   205  	for i := 0; i < len(m.EntryUUIDs); i++ {
   206  
   207  		if err := validate.Pattern("entryUUIDs"+"."+strconv.Itoa(i), "body", m.EntryUUIDs[i], `^([0-9a-fA-F]{64}|[0-9a-fA-F]{80})$`); err != nil {
   208  			return err
   209  		}
   210  
   211  	}
   212  
   213  	return nil
   214  }
   215  
   216  func (m *SearchLogQuery) validateLogIndexes(formats strfmt.Registry) error {
   217  	if swag.IsZero(m.LogIndexes) { // not required
   218  		return nil
   219  	}
   220  
   221  	iLogIndexesSize := int64(len(m.LogIndexes))
   222  
   223  	if err := validate.MinItems("logIndexes", "body", iLogIndexesSize, 1); err != nil {
   224  		return err
   225  	}
   226  
   227  	if err := validate.MaxItems("logIndexes", "body", iLogIndexesSize, 10); err != nil {
   228  		return err
   229  	}
   230  
   231  	for i := 0; i < len(m.LogIndexes); i++ {
   232  		if swag.IsZero(m.LogIndexes[i]) { // not required
   233  			continue
   234  		}
   235  
   236  		if err := validate.MinimumInt("logIndexes"+"."+strconv.Itoa(i), "body", *m.LogIndexes[i], 0, false); err != nil {
   237  			return err
   238  		}
   239  
   240  	}
   241  
   242  	return nil
   243  }
   244  
   245  // ContextValidate validate this search log query based on the context it is used
   246  func (m *SearchLogQuery) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   247  	var res []error
   248  
   249  	if err := m.contextValidateEntries(ctx, formats); err != nil {
   250  		res = append(res, err)
   251  	}
   252  
   253  	if len(res) > 0 {
   254  		return errors.CompositeValidationError(res...)
   255  	}
   256  	return nil
   257  }
   258  
   259  func (m *SearchLogQuery) contextValidateEntries(ctx context.Context, formats strfmt.Registry) error {
   260  
   261  	for i := 0; i < len(m.Entries()); i++ {
   262  
   263  		if swag.IsZero(m.entriesField[i]) { // not required
   264  			return nil
   265  		}
   266  
   267  		if err := m.entriesField[i].ContextValidate(ctx, formats); err != nil {
   268  			if ve, ok := err.(*errors.Validation); ok {
   269  				return ve.ValidateName("entries" + "." + strconv.Itoa(i))
   270  			} else if ce, ok := err.(*errors.CompositeError); ok {
   271  				return ce.ValidateName("entries" + "." + strconv.Itoa(i))
   272  			}
   273  			return err
   274  		}
   275  
   276  	}
   277  
   278  	return nil
   279  }
   280  
   281  // MarshalBinary interface implementation
   282  func (m *SearchLogQuery) MarshalBinary() ([]byte, error) {
   283  	if m == nil {
   284  		return nil, nil
   285  	}
   286  	return swag.WriteJSON(m)
   287  }
   288  
   289  // UnmarshalBinary interface implementation
   290  func (m *SearchLogQuery) UnmarshalBinary(b []byte) error {
   291  	var res SearchLogQuery
   292  	if err := swag.ReadJSON(b, &res); err != nil {
   293  		return err
   294  	}
   295  	*m = res
   296  	return nil
   297  }
   298  

View as plain text