github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/examples/task-tracker/models/validation_error.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  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/go-openapi/swag"
    14  )
    15  
    16  // ValidationError validation error
    17  //
    18  // swagger:model ValidationError
    19  type ValidationError struct {
    20  	Error
    21  
    22  	// an optional field name to which this validation error applies
    23  	Field string `json:"field,omitempty"`
    24  }
    25  
    26  // UnmarshalJSON unmarshals this object from a JSON structure
    27  func (m *ValidationError) UnmarshalJSON(raw []byte) error {
    28  	// AO0
    29  	var aO0 Error
    30  	if err := swag.ReadJSON(raw, &aO0); err != nil {
    31  		return err
    32  	}
    33  	m.Error = aO0
    34  
    35  	// AO1
    36  	var dataAO1 struct {
    37  		Field string `json:"field,omitempty"`
    38  	}
    39  	if err := swag.ReadJSON(raw, &dataAO1); err != nil {
    40  		return err
    41  	}
    42  
    43  	m.Field = dataAO1.Field
    44  
    45  	return nil
    46  }
    47  
    48  // MarshalJSON marshals this object to a JSON structure
    49  func (m ValidationError) MarshalJSON() ([]byte, error) {
    50  	_parts := make([][]byte, 0, 2)
    51  
    52  	aO0, err := swag.WriteJSON(m.Error)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	_parts = append(_parts, aO0)
    57  	var dataAO1 struct {
    58  		Field string `json:"field,omitempty"`
    59  	}
    60  
    61  	dataAO1.Field = m.Field
    62  
    63  	jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
    64  	if errAO1 != nil {
    65  		return nil, errAO1
    66  	}
    67  	_parts = append(_parts, jsonDataAO1)
    68  	return swag.ConcatJSON(_parts...), nil
    69  }
    70  
    71  // Validate validates this validation error
    72  func (m *ValidationError) Validate(formats strfmt.Registry) error {
    73  	var res []error
    74  
    75  	// validation for a type composition with Error
    76  	if err := m.Error.Validate(formats); err != nil {
    77  		res = append(res, err)
    78  	}
    79  
    80  	if len(res) > 0 {
    81  		return errors.CompositeValidationError(res...)
    82  	}
    83  	return nil
    84  }
    85  
    86  // ContextValidate validate this validation error based on the context it is used
    87  func (m *ValidationError) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    88  	var res []error
    89  
    90  	// validation for a type composition with Error
    91  	if err := m.Error.ContextValidate(ctx, formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if len(res) > 0 {
    96  		return errors.CompositeValidationError(res...)
    97  	}
    98  	return nil
    99  }
   100  
   101  // MarshalBinary interface implementation
   102  func (m *ValidationError) MarshalBinary() ([]byte, error) {
   103  	if m == nil {
   104  		return nil, nil
   105  	}
   106  	return swag.WriteJSON(m)
   107  }
   108  
   109  // UnmarshalBinary interface implementation
   110  func (m *ValidationError) UnmarshalBinary(b []byte) error {
   111  	var res ValidationError
   112  	if err := swag.ReadJSON(b, &res); err != nil {
   113  		return err
   114  	}
   115  	*m = res
   116  	return nil
   117  }