github.com/kaisawind/go-swagger@v0.19.0/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  	strfmt "github.com/go-openapi/strfmt"
    10  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/swag"
    13  )
    14  
    15  // ValidationError validation error
    16  // swagger:model ValidationError
    17  type ValidationError struct {
    18  	Error
    19  
    20  	// an optional field name to which this validation error applies
    21  	Field string `json:"field,omitempty"`
    22  }
    23  
    24  // UnmarshalJSON unmarshals this object from a JSON structure
    25  func (m *ValidationError) UnmarshalJSON(raw []byte) error {
    26  	// AO0
    27  	var aO0 Error
    28  	if err := swag.ReadJSON(raw, &aO0); err != nil {
    29  		return err
    30  	}
    31  	m.Error = aO0
    32  
    33  	// AO1
    34  	var dataAO1 struct {
    35  		Field string `json:"field,omitempty"`
    36  	}
    37  	if err := swag.ReadJSON(raw, &dataAO1); err != nil {
    38  		return err
    39  	}
    40  
    41  	m.Field = dataAO1.Field
    42  
    43  	return nil
    44  }
    45  
    46  // MarshalJSON marshals this object to a JSON structure
    47  func (m ValidationError) MarshalJSON() ([]byte, error) {
    48  	_parts := make([][]byte, 0, 2)
    49  
    50  	aO0, err := swag.WriteJSON(m.Error)
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  	_parts = append(_parts, aO0)
    55  
    56  	var dataAO1 struct {
    57  		Field string `json:"field,omitempty"`
    58  	}
    59  
    60  	dataAO1.Field = m.Field
    61  
    62  	jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
    63  	if errAO1 != nil {
    64  		return nil, errAO1
    65  	}
    66  	_parts = append(_parts, jsonDataAO1)
    67  
    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  // MarshalBinary interface implementation
    87  func (m *ValidationError) MarshalBinary() ([]byte, error) {
    88  	if m == nil {
    89  		return nil, nil
    90  	}
    91  	return swag.WriteJSON(m)
    92  }
    93  
    94  // UnmarshalBinary interface implementation
    95  func (m *ValidationError) UnmarshalBinary(b []byte) error {
    96  	var res ValidationError
    97  	if err := swag.ReadJSON(b, &res); err != nil {
    98  		return err
    99  	}
   100  	*m = res
   101  	return nil
   102  }