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