github.com/weaviate/weaviate@v1.24.6/entities/models/nested_property.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  // Code generated by go-swagger; DO NOT EDIT.
    13  
    14  package models
    15  
    16  // This file was generated by the swagger tool.
    17  // Editing this file might prove futile when you re-run the swagger generate command
    18  
    19  import (
    20  	"context"
    21  	"encoding/json"
    22  	"strconv"
    23  
    24  	"github.com/go-openapi/errors"
    25  	"github.com/go-openapi/strfmt"
    26  	"github.com/go-openapi/swag"
    27  	"github.com/go-openapi/validate"
    28  )
    29  
    30  // NestedProperty nested property
    31  //
    32  // swagger:model NestedProperty
    33  type NestedProperty struct {
    34  
    35  	// data type
    36  	DataType []string `json:"dataType"`
    37  
    38  	// description
    39  	Description string `json:"description,omitempty"`
    40  
    41  	// index filterable
    42  	IndexFilterable *bool `json:"indexFilterable,omitempty"`
    43  
    44  	// index searchable
    45  	IndexSearchable *bool `json:"indexSearchable,omitempty"`
    46  
    47  	// name
    48  	Name string `json:"name,omitempty"`
    49  
    50  	// nested properties
    51  	NestedProperties []*NestedProperty `json:"nestedProperties,omitempty"`
    52  
    53  	// tokenization
    54  	// Enum: [word lowercase whitespace field]
    55  	Tokenization string `json:"tokenization,omitempty"`
    56  }
    57  
    58  // Validate validates this nested property
    59  func (m *NestedProperty) Validate(formats strfmt.Registry) error {
    60  	var res []error
    61  
    62  	if err := m.validateNestedProperties(formats); err != nil {
    63  		res = append(res, err)
    64  	}
    65  
    66  	if err := m.validateTokenization(formats); err != nil {
    67  		res = append(res, err)
    68  	}
    69  
    70  	if len(res) > 0 {
    71  		return errors.CompositeValidationError(res...)
    72  	}
    73  	return nil
    74  }
    75  
    76  func (m *NestedProperty) validateNestedProperties(formats strfmt.Registry) error {
    77  	if swag.IsZero(m.NestedProperties) { // not required
    78  		return nil
    79  	}
    80  
    81  	for i := 0; i < len(m.NestedProperties); i++ {
    82  		if swag.IsZero(m.NestedProperties[i]) { // not required
    83  			continue
    84  		}
    85  
    86  		if m.NestedProperties[i] != nil {
    87  			if err := m.NestedProperties[i].Validate(formats); err != nil {
    88  				if ve, ok := err.(*errors.Validation); ok {
    89  					return ve.ValidateName("nestedProperties" + "." + strconv.Itoa(i))
    90  				} else if ce, ok := err.(*errors.CompositeError); ok {
    91  					return ce.ValidateName("nestedProperties" + "." + strconv.Itoa(i))
    92  				}
    93  				return err
    94  			}
    95  		}
    96  
    97  	}
    98  
    99  	return nil
   100  }
   101  
   102  var nestedPropertyTypeTokenizationPropEnum []interface{}
   103  
   104  func init() {
   105  	var res []string
   106  	if err := json.Unmarshal([]byte(`["word","lowercase","whitespace","field"]`), &res); err != nil {
   107  		panic(err)
   108  	}
   109  	for _, v := range res {
   110  		nestedPropertyTypeTokenizationPropEnum = append(nestedPropertyTypeTokenizationPropEnum, v)
   111  	}
   112  }
   113  
   114  const (
   115  
   116  	// NestedPropertyTokenizationWord captures enum value "word"
   117  	NestedPropertyTokenizationWord string = "word"
   118  
   119  	// NestedPropertyTokenizationLowercase captures enum value "lowercase"
   120  	NestedPropertyTokenizationLowercase string = "lowercase"
   121  
   122  	// NestedPropertyTokenizationWhitespace captures enum value "whitespace"
   123  	NestedPropertyTokenizationWhitespace string = "whitespace"
   124  
   125  	// NestedPropertyTokenizationField captures enum value "field"
   126  	NestedPropertyTokenizationField string = "field"
   127  )
   128  
   129  // prop value enum
   130  func (m *NestedProperty) validateTokenizationEnum(path, location string, value string) error {
   131  	if err := validate.EnumCase(path, location, value, nestedPropertyTypeTokenizationPropEnum, true); err != nil {
   132  		return err
   133  	}
   134  	return nil
   135  }
   136  
   137  func (m *NestedProperty) validateTokenization(formats strfmt.Registry) error {
   138  	if swag.IsZero(m.Tokenization) { // not required
   139  		return nil
   140  	}
   141  
   142  	// value enum
   143  	if err := m.validateTokenizationEnum("tokenization", "body", m.Tokenization); err != nil {
   144  		return err
   145  	}
   146  
   147  	return nil
   148  }
   149  
   150  // ContextValidate validate this nested property based on the context it is used
   151  func (m *NestedProperty) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   152  	var res []error
   153  
   154  	if err := m.contextValidateNestedProperties(ctx, formats); err != nil {
   155  		res = append(res, err)
   156  	}
   157  
   158  	if len(res) > 0 {
   159  		return errors.CompositeValidationError(res...)
   160  	}
   161  	return nil
   162  }
   163  
   164  func (m *NestedProperty) contextValidateNestedProperties(ctx context.Context, formats strfmt.Registry) error {
   165  
   166  	for i := 0; i < len(m.NestedProperties); i++ {
   167  
   168  		if m.NestedProperties[i] != nil {
   169  			if err := m.NestedProperties[i].ContextValidate(ctx, formats); err != nil {
   170  				if ve, ok := err.(*errors.Validation); ok {
   171  					return ve.ValidateName("nestedProperties" + "." + strconv.Itoa(i))
   172  				} else if ce, ok := err.(*errors.CompositeError); ok {
   173  					return ce.ValidateName("nestedProperties" + "." + strconv.Itoa(i))
   174  				}
   175  				return err
   176  			}
   177  		}
   178  
   179  	}
   180  
   181  	return nil
   182  }
   183  
   184  // MarshalBinary interface implementation
   185  func (m *NestedProperty) MarshalBinary() ([]byte, error) {
   186  	if m == nil {
   187  		return nil, nil
   188  	}
   189  	return swag.WriteJSON(m)
   190  }
   191  
   192  // UnmarshalBinary interface implementation
   193  func (m *NestedProperty) UnmarshalBinary(b []byte) error {
   194  	var res NestedProperty
   195  	if err := swag.ReadJSON(b, &res); err != nil {
   196  		return err
   197  	}
   198  	*m = res
   199  	return nil
   200  }