github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/examples/auto-configure/models/item.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  	"github.com/go-openapi/validate"
    15  )
    16  
    17  // Item item
    18  //
    19  // swagger:model item
    20  type Item struct {
    21  
    22  	// completed
    23  	Completed bool `json:"completed,omitempty"`
    24  
    25  	// description
    26  	// Required: true
    27  	// Min Length: 1
    28  	Description *string `json:"description"`
    29  
    30  	// id
    31  	// Read Only: true
    32  	ID int64 `json:"id,omitempty"`
    33  }
    34  
    35  // Validate validates this item
    36  func (m *Item) Validate(formats strfmt.Registry) error {
    37  	var res []error
    38  
    39  	if err := m.validateDescription(formats); err != nil {
    40  		res = append(res, err)
    41  	}
    42  
    43  	if len(res) > 0 {
    44  		return errors.CompositeValidationError(res...)
    45  	}
    46  	return nil
    47  }
    48  
    49  func (m *Item) validateDescription(formats strfmt.Registry) error {
    50  
    51  	if err := validate.Required("description", "body", m.Description); err != nil {
    52  		return err
    53  	}
    54  
    55  	if err := validate.MinLength("description", "body", *m.Description, 1); err != nil {
    56  		return err
    57  	}
    58  
    59  	return nil
    60  }
    61  
    62  // ContextValidate validate this item based on the context it is used
    63  func (m *Item) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    64  	var res []error
    65  
    66  	if err := m.contextValidateID(ctx, 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 *Item) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
    77  
    78  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
    79  		return err
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  // MarshalBinary interface implementation
    86  func (m *Item) MarshalBinary() ([]byte, error) {
    87  	if m == nil {
    88  		return nil, nil
    89  	}
    90  	return swag.WriteJSON(m)
    91  }
    92  
    93  // UnmarshalBinary interface implementation
    94  func (m *Item) UnmarshalBinary(b []byte) error {
    95  	var res Item
    96  	if err := swag.ReadJSON(b, &res); err != nil {
    97  		return err
    98  	}
    99  	*m = res
   100  	return nil
   101  }