github.com/circl-dev/go-swagger@v0.31.0/examples/external-types/models/zzz.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"context"
    10  	"strconv"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/strfmt"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/circl-dev/go-swagger/examples/external-types/fred"
    16  	custom "github.com/circl-dev/go-swagger/examples/external-types/fred"
    17  	"github.com/circl-dev/validate"
    18  )
    19  
    20  // Zzz This demonstrates variations in generated code, depending on how properties are declared.
    21  //
    22  // Some properties are directly based on some external type and some other define collections (slices, maps)
    23  // of these external types.
    24  //
    25  // Notice the use of pointers for required properties, but not for slices or maps.
    26  //
    27  // In addition, it demonstrates how pointer generation may be controlled with the nullable hint or the x-nullable extension.
    28  //
    29  // type Zzz struct {
    30  // 	Beta []MyOtherType `json:"beta"`
    31  // 	Delta MyInteger `json:"delta,omitempty"`
    32  // 	Epsilon []custom.MyAlternateType `json:"epsilon"`
    33  // 	Gamma fred.MyAlternateInteger `json:"gamma,omitempty"`
    34  // 	Meta MyType `json:"meta,omitempty"`
    35  //
    36  // 	NullableBeta []*MyOtherType `json:"nullableBeta"`
    37  // 	NullableDelta *MyInteger `json:"nullableDelta,omitempty"`
    38  // 	NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`
    39  // 	NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`
    40  // 	NullableMeta MyType `json:"nullableMeta,omitempty"`
    41  //
    42  // 	ReqBeta []MyOtherType `json:"reqBeta"`
    43  // 	ReqDelta *MyInteger `json:"reqDelta"`
    44  // 	ReqEpsilon []custom.MyAlternateType `json:"reqEpsilon"`
    45  // 	ReqGamma *fred.MyAlternateInteger `json:"reqGamma"`
    46  // 	ReqMeta *MyType `json:"reqMeta"`
    47  // }
    48  //
    49  //
    50  // swagger:model Zzz
    51  type Zzz struct {
    52  
    53  	// This property defines an array of external types (in the same package).
    54  	//
    55  	// []MyOtherType
    56  	//
    57  	// The maxItems validation is generated and the external validation is called for every item.
    58  	//
    59  	// Max Items: 15
    60  	Beta []MyOtherType `json:"beta"`
    61  
    62  	// A type is provided (integer), and the implementation is an external type in the same package.
    63  	//
    64  	// The maximum validation remains documentary and is ignored by the generated code.
    65  	//
    66  	// Maximum: 15
    67  	Delta MyInteger `json:"delta,omitempty"`
    68  
    69  	// epsilon
    70  	Epsilon []custom.MyAlternateType `json:"epsilon"`
    71  
    72  	// Property defined as an external type from package "fred"
    73  	//
    74  	Gamma fred.MyAlternateInteger `json:"gamma,omitempty"`
    75  
    76  	// meta
    77  	Meta MyType `json:"meta,omitempty"`
    78  
    79  	// This property defines an array of external types (in the same package).
    80  	//
    81  	// []MyOtherType
    82  	//
    83  	// The maxItems validation is generated and the external validation is called for every item.
    84  	//
    85  	// Max Items: 15
    86  	NullableBeta []*MyOtherType `json:"nullableBeta"`
    87  
    88  	// A type is provided (integer), and the implementation is an external type in the same package.
    89  	//
    90  	// The maximum validation remains documentary and is ignored by the generated code.
    91  	//
    92  	// NullableDelta *MyInteger
    93  	//
    94  	// Maximum: 15
    95  	NullableDelta *MyInteger `json:"nullableDelta,omitempty"`
    96  
    97  	// In this example, items are made nullable.
    98  	//
    99  	// NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`
   100  	//
   101  	NullableEpsilon []*custom.MyAlternateType `json:"nullableEpsilon"`
   102  
   103  	// Property defined as an external type from package "fred", with a nullable hint for the
   104  	// external type.
   105  	//
   106  	// NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`
   107  	//
   108  	NullableGamma *fred.MyAlternateInteger `json:"nullableGamma,omitempty"`
   109  
   110  	// nullable meta
   111  	NullableMeta MyType `json:"nullableMeta,omitempty"`
   112  
   113  	// req beta
   114  	// Required: true
   115  	ReqBeta []MyOtherType `json:"reqBeta"`
   116  
   117  	// req delta
   118  	// Required: true
   119  	ReqDelta *MyInteger `json:"reqDelta"`
   120  
   121  	// req epsilon
   122  	// Required: true
   123  	ReqEpsilon []custom.MyAlternateType `json:"reqEpsilon"`
   124  
   125  	// req gamma
   126  	// Required: true
   127  	ReqGamma *fred.MyAlternateInteger `json:"reqGamma"`
   128  
   129  	// req meta
   130  	// Required: true
   131  	ReqMeta *MyType `json:"reqMeta"`
   132  }
   133  
   134  // Validate validates this zzz
   135  func (m *Zzz) Validate(formats strfmt.Registry) error {
   136  	var res []error
   137  
   138  	if err := m.validateBeta(formats); err != nil {
   139  		res = append(res, err)
   140  	}
   141  
   142  	if err := m.validateDelta(formats); err != nil {
   143  		res = append(res, err)
   144  	}
   145  
   146  	if err := m.validateEpsilon(formats); err != nil {
   147  		res = append(res, err)
   148  	}
   149  
   150  	if err := m.validateGamma(formats); err != nil {
   151  		res = append(res, err)
   152  	}
   153  
   154  	if err := m.validateMeta(formats); err != nil {
   155  		res = append(res, err)
   156  	}
   157  
   158  	if err := m.validateNullableBeta(formats); err != nil {
   159  		res = append(res, err)
   160  	}
   161  
   162  	if err := m.validateNullableDelta(formats); err != nil {
   163  		res = append(res, err)
   164  	}
   165  
   166  	if err := m.validateNullableEpsilon(formats); err != nil {
   167  		res = append(res, err)
   168  	}
   169  
   170  	if err := m.validateNullableGamma(formats); err != nil {
   171  		res = append(res, err)
   172  	}
   173  
   174  	if err := m.validateNullableMeta(formats); err != nil {
   175  		res = append(res, err)
   176  	}
   177  
   178  	if err := m.validateReqBeta(formats); err != nil {
   179  		res = append(res, err)
   180  	}
   181  
   182  	if err := m.validateReqDelta(formats); err != nil {
   183  		res = append(res, err)
   184  	}
   185  
   186  	if err := m.validateReqEpsilon(formats); err != nil {
   187  		res = append(res, err)
   188  	}
   189  
   190  	if err := m.validateReqGamma(formats); err != nil {
   191  		res = append(res, err)
   192  	}
   193  
   194  	if err := m.validateReqMeta(formats); err != nil {
   195  		res = append(res, err)
   196  	}
   197  
   198  	if len(res) > 0 {
   199  		return errors.CompositeValidationError(res...)
   200  	}
   201  	return nil
   202  }
   203  
   204  func (m *Zzz) validateBeta(formats strfmt.Registry) error {
   205  	if swag.IsZero(m.Beta) { // not required
   206  		return nil
   207  	}
   208  
   209  	iBetaSize := int64(len(m.Beta))
   210  
   211  	if err := validate.MaxItems("beta", "body", iBetaSize, 15); err != nil {
   212  		return err
   213  	}
   214  
   215  	for i := 0; i < len(m.Beta); i++ {
   216  
   217  		if err := m.Beta[i].Validate(formats); err != nil {
   218  			if ve, ok := err.(*errors.Validation); ok {
   219  				return ve.ValidateName("beta" + "." + strconv.Itoa(i))
   220  			} else if ce, ok := err.(*errors.CompositeError); ok {
   221  				return ce.ValidateName("beta" + "." + strconv.Itoa(i))
   222  			}
   223  			return err
   224  		}
   225  
   226  	}
   227  
   228  	return nil
   229  }
   230  
   231  func (m *Zzz) validateDelta(formats strfmt.Registry) error {
   232  	if swag.IsZero(m.Delta) { // not required
   233  		return nil
   234  	}
   235  
   236  	if err := m.Delta.Validate(formats); err != nil {
   237  		if ve, ok := err.(*errors.Validation); ok {
   238  			return ve.ValidateName("delta")
   239  		} else if ce, ok := err.(*errors.CompositeError); ok {
   240  			return ce.ValidateName("delta")
   241  		}
   242  		return err
   243  	}
   244  
   245  	return nil
   246  }
   247  
   248  func (m *Zzz) validateEpsilon(formats strfmt.Registry) error {
   249  	if swag.IsZero(m.Epsilon) { // not required
   250  		return nil
   251  	}
   252  
   253  	for i := 0; i < len(m.Epsilon); i++ {
   254  
   255  		if err := m.Epsilon[i].Validate(formats); err != nil {
   256  			if ve, ok := err.(*errors.Validation); ok {
   257  				return ve.ValidateName("epsilon" + "." + strconv.Itoa(i))
   258  			} else if ce, ok := err.(*errors.CompositeError); ok {
   259  				return ce.ValidateName("epsilon" + "." + strconv.Itoa(i))
   260  			}
   261  			return err
   262  		}
   263  
   264  	}
   265  
   266  	return nil
   267  }
   268  
   269  func (m *Zzz) validateGamma(formats strfmt.Registry) error {
   270  	if swag.IsZero(m.Gamma) { // not required
   271  		return nil
   272  	}
   273  
   274  	if err := m.Gamma.Validate(formats); err != nil {
   275  		if ve, ok := err.(*errors.Validation); ok {
   276  			return ve.ValidateName("gamma")
   277  		} else if ce, ok := err.(*errors.CompositeError); ok {
   278  			return ce.ValidateName("gamma")
   279  		}
   280  		return err
   281  	}
   282  
   283  	return nil
   284  }
   285  
   286  func (m *Zzz) validateMeta(formats strfmt.Registry) error {
   287  	if swag.IsZero(m.Meta) { // not required
   288  		return nil
   289  	}
   290  
   291  	if err := m.Meta.Validate(formats); err != nil {
   292  		if ve, ok := err.(*errors.Validation); ok {
   293  			return ve.ValidateName("meta")
   294  		} else if ce, ok := err.(*errors.CompositeError); ok {
   295  			return ce.ValidateName("meta")
   296  		}
   297  		return err
   298  	}
   299  
   300  	return nil
   301  }
   302  
   303  func (m *Zzz) validateNullableBeta(formats strfmt.Registry) error {
   304  	if swag.IsZero(m.NullableBeta) { // not required
   305  		return nil
   306  	}
   307  
   308  	iNullableBetaSize := int64(len(m.NullableBeta))
   309  
   310  	if err := validate.MaxItems("nullableBeta", "body", iNullableBetaSize, 15); err != nil {
   311  		return err
   312  	}
   313  
   314  	for i := 0; i < len(m.NullableBeta); i++ {
   315  		if swag.IsZero(m.NullableBeta[i]) { // not required
   316  			continue
   317  		}
   318  
   319  		if m.NullableBeta[i] != nil {
   320  			if err := m.NullableBeta[i].Validate(formats); err != nil {
   321  				if ve, ok := err.(*errors.Validation); ok {
   322  					return ve.ValidateName("nullableBeta" + "." + strconv.Itoa(i))
   323  				} else if ce, ok := err.(*errors.CompositeError); ok {
   324  					return ce.ValidateName("nullableBeta" + "." + strconv.Itoa(i))
   325  				}
   326  				return err
   327  			}
   328  		}
   329  
   330  	}
   331  
   332  	return nil
   333  }
   334  
   335  func (m *Zzz) validateNullableDelta(formats strfmt.Registry) error {
   336  	if swag.IsZero(m.NullableDelta) { // not required
   337  		return nil
   338  	}
   339  
   340  	if m.NullableDelta != nil {
   341  		if err := m.NullableDelta.Validate(formats); err != nil {
   342  			if ve, ok := err.(*errors.Validation); ok {
   343  				return ve.ValidateName("nullableDelta")
   344  			} else if ce, ok := err.(*errors.CompositeError); ok {
   345  				return ce.ValidateName("nullableDelta")
   346  			}
   347  			return err
   348  		}
   349  	}
   350  
   351  	return nil
   352  }
   353  
   354  func (m *Zzz) validateNullableEpsilon(formats strfmt.Registry) error {
   355  	if swag.IsZero(m.NullableEpsilon) { // not required
   356  		return nil
   357  	}
   358  
   359  	for i := 0; i < len(m.NullableEpsilon); i++ {
   360  		if swag.IsZero(m.NullableEpsilon[i]) { // not required
   361  			continue
   362  		}
   363  
   364  		if m.NullableEpsilon[i] != nil {
   365  			if err := m.NullableEpsilon[i].Validate(formats); err != nil {
   366  				if ve, ok := err.(*errors.Validation); ok {
   367  					return ve.ValidateName("nullableEpsilon" + "." + strconv.Itoa(i))
   368  				} else if ce, ok := err.(*errors.CompositeError); ok {
   369  					return ce.ValidateName("nullableEpsilon" + "." + strconv.Itoa(i))
   370  				}
   371  				return err
   372  			}
   373  		}
   374  
   375  	}
   376  
   377  	return nil
   378  }
   379  
   380  func (m *Zzz) validateNullableGamma(formats strfmt.Registry) error {
   381  	if swag.IsZero(m.NullableGamma) { // not required
   382  		return nil
   383  	}
   384  
   385  	if m.NullableGamma != nil {
   386  		if err := m.NullableGamma.Validate(formats); err != nil {
   387  			if ve, ok := err.(*errors.Validation); ok {
   388  				return ve.ValidateName("nullableGamma")
   389  			} else if ce, ok := err.(*errors.CompositeError); ok {
   390  				return ce.ValidateName("nullableGamma")
   391  			}
   392  			return err
   393  		}
   394  	}
   395  
   396  	return nil
   397  }
   398  
   399  func (m *Zzz) validateNullableMeta(formats strfmt.Registry) error {
   400  	if swag.IsZero(m.NullableMeta) { // not required
   401  		return nil
   402  	}
   403  
   404  	if err := m.NullableMeta.Validate(formats); err != nil {
   405  		if ve, ok := err.(*errors.Validation); ok {
   406  			return ve.ValidateName("nullableMeta")
   407  		} else if ce, ok := err.(*errors.CompositeError); ok {
   408  			return ce.ValidateName("nullableMeta")
   409  		}
   410  		return err
   411  	}
   412  
   413  	return nil
   414  }
   415  
   416  func (m *Zzz) validateReqBeta(formats strfmt.Registry) error {
   417  
   418  	if err := validate.Required("reqBeta", "body", m.ReqBeta); err != nil {
   419  		return err
   420  	}
   421  
   422  	for i := 0; i < len(m.ReqBeta); i++ {
   423  
   424  		if err := m.ReqBeta[i].Validate(formats); err != nil {
   425  			if ve, ok := err.(*errors.Validation); ok {
   426  				return ve.ValidateName("reqBeta" + "." + strconv.Itoa(i))
   427  			} else if ce, ok := err.(*errors.CompositeError); ok {
   428  				return ce.ValidateName("reqBeta" + "." + strconv.Itoa(i))
   429  			}
   430  			return err
   431  		}
   432  
   433  	}
   434  
   435  	return nil
   436  }
   437  
   438  func (m *Zzz) validateReqDelta(formats strfmt.Registry) error {
   439  
   440  	if err := validate.Required("reqDelta", "body", m.ReqDelta); err != nil {
   441  		return err
   442  	}
   443  
   444  	if err := validate.Required("reqDelta", "body", m.ReqDelta); err != nil {
   445  		return err
   446  	}
   447  
   448  	if m.ReqDelta != nil {
   449  		if err := m.ReqDelta.Validate(formats); err != nil {
   450  			if ve, ok := err.(*errors.Validation); ok {
   451  				return ve.ValidateName("reqDelta")
   452  			} else if ce, ok := err.(*errors.CompositeError); ok {
   453  				return ce.ValidateName("reqDelta")
   454  			}
   455  			return err
   456  		}
   457  	}
   458  
   459  	return nil
   460  }
   461  
   462  func (m *Zzz) validateReqEpsilon(formats strfmt.Registry) error {
   463  
   464  	if err := validate.Required("reqEpsilon", "body", m.ReqEpsilon); err != nil {
   465  		return err
   466  	}
   467  
   468  	for i := 0; i < len(m.ReqEpsilon); i++ {
   469  
   470  		if err := m.ReqEpsilon[i].Validate(formats); err != nil {
   471  			if ve, ok := err.(*errors.Validation); ok {
   472  				return ve.ValidateName("reqEpsilon" + "." + strconv.Itoa(i))
   473  			} else if ce, ok := err.(*errors.CompositeError); ok {
   474  				return ce.ValidateName("reqEpsilon" + "." + strconv.Itoa(i))
   475  			}
   476  			return err
   477  		}
   478  
   479  	}
   480  
   481  	return nil
   482  }
   483  
   484  func (m *Zzz) validateReqGamma(formats strfmt.Registry) error {
   485  
   486  	if err := validate.Required("reqGamma", "body", m.ReqGamma); err != nil {
   487  		return err
   488  	}
   489  
   490  	if m.ReqGamma != nil {
   491  		if err := m.ReqGamma.Validate(formats); err != nil {
   492  			if ve, ok := err.(*errors.Validation); ok {
   493  				return ve.ValidateName("reqGamma")
   494  			} else if ce, ok := err.(*errors.CompositeError); ok {
   495  				return ce.ValidateName("reqGamma")
   496  			}
   497  			return err
   498  		}
   499  	}
   500  
   501  	return nil
   502  }
   503  
   504  func (m *Zzz) validateReqMeta(formats strfmt.Registry) error {
   505  
   506  	if err := validate.Required("reqMeta", "body", m.ReqMeta); err != nil {
   507  		return err
   508  	}
   509  
   510  	if m.ReqMeta != nil {
   511  		if err := m.ReqMeta.Validate(formats); err != nil {
   512  			if ve, ok := err.(*errors.Validation); ok {
   513  				return ve.ValidateName("reqMeta")
   514  			} else if ce, ok := err.(*errors.CompositeError); ok {
   515  				return ce.ValidateName("reqMeta")
   516  			}
   517  			return err
   518  		}
   519  	}
   520  
   521  	return nil
   522  }
   523  
   524  // ContextValidate validate this zzz based on the context it is used
   525  func (m *Zzz) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   526  	var res []error
   527  
   528  	if err := m.contextValidateMeta(ctx, formats); err != nil {
   529  		res = append(res, err)
   530  	}
   531  
   532  	if err := m.contextValidateNullableMeta(ctx, formats); err != nil {
   533  		res = append(res, err)
   534  	}
   535  
   536  	if err := m.contextValidateReqMeta(ctx, formats); err != nil {
   537  		res = append(res, err)
   538  	}
   539  
   540  	if len(res) > 0 {
   541  		return errors.CompositeValidationError(res...)
   542  	}
   543  	return nil
   544  }
   545  
   546  func (m *Zzz) contextValidateMeta(ctx context.Context, formats strfmt.Registry) error {
   547  
   548  	if err := m.Meta.ContextValidate(ctx, formats); err != nil {
   549  		if ve, ok := err.(*errors.Validation); ok {
   550  			return ve.ValidateName("meta")
   551  		} else if ce, ok := err.(*errors.CompositeError); ok {
   552  			return ce.ValidateName("meta")
   553  		}
   554  		return err
   555  	}
   556  
   557  	return nil
   558  }
   559  
   560  func (m *Zzz) contextValidateNullableMeta(ctx context.Context, formats strfmt.Registry) error {
   561  
   562  	if err := m.NullableMeta.ContextValidate(ctx, formats); err != nil {
   563  		if ve, ok := err.(*errors.Validation); ok {
   564  			return ve.ValidateName("nullableMeta")
   565  		} else if ce, ok := err.(*errors.CompositeError); ok {
   566  			return ce.ValidateName("nullableMeta")
   567  		}
   568  		return err
   569  	}
   570  
   571  	return nil
   572  }
   573  
   574  func (m *Zzz) contextValidateReqMeta(ctx context.Context, formats strfmt.Registry) error {
   575  
   576  	if m.ReqMeta != nil {
   577  		if err := m.ReqMeta.ContextValidate(ctx, formats); err != nil {
   578  			if ve, ok := err.(*errors.Validation); ok {
   579  				return ve.ValidateName("reqMeta")
   580  			} else if ce, ok := err.(*errors.CompositeError); ok {
   581  				return ce.ValidateName("reqMeta")
   582  			}
   583  			return err
   584  		}
   585  	}
   586  
   587  	return nil
   588  }
   589  
   590  // MarshalBinary interface implementation
   591  func (m *Zzz) MarshalBinary() ([]byte, error) {
   592  	if m == nil {
   593  		return nil, nil
   594  	}
   595  	return swag.WriteJSON(m)
   596  }
   597  
   598  // UnmarshalBinary interface implementation
   599  func (m *Zzz) UnmarshalBinary(b []byte) error {
   600  	var res Zzz
   601  	if err := swag.ReadJSON(b, &res); err != nil {
   602  		return err
   603  	}
   604  	*m = res
   605  	return nil
   606  }