payload.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Code generated by go-swagger; DO NOT EDIT.
  2. package models
  3. // This file was generated by the swagger tool.
  4. // Editing this file might prove futile when you re-run the swagger generate command
  5. import (
  6. "context"
  7. "strconv"
  8. "github.com/go-openapi/errors"
  9. "github.com/go-openapi/strfmt"
  10. "github.com/go-openapi/swag"
  11. "github.com/go-openapi/validate"
  12. )
  13. // Payload payload
  14. //
  15. // swagger:model payload
  16. type Payload struct {
  17. // fuels
  18. // Required: true
  19. Fuels interface{} `json:"fuels"`
  20. // load
  21. // Required: true
  22. Load *float64 `json:"load"`
  23. // powerplants
  24. // Required: true
  25. Powerplants []*Powerplant `json:"powerplants"`
  26. }
  27. // Validate validates this payload
  28. func (m *Payload) Validate(formats strfmt.Registry) error {
  29. var res []error
  30. if err := m.validateFuels(formats); err != nil {
  31. res = append(res, err)
  32. }
  33. if err := m.validateLoad(formats); err != nil {
  34. res = append(res, err)
  35. }
  36. if err := m.validatePowerplants(formats); err != nil {
  37. res = append(res, err)
  38. }
  39. if len(res) > 0 {
  40. return errors.CompositeValidationError(res...)
  41. }
  42. return nil
  43. }
  44. func (m *Payload) validateFuels(formats strfmt.Registry) error {
  45. if m.Fuels == nil {
  46. return errors.Required("fuels", "body", nil)
  47. }
  48. return nil
  49. }
  50. func (m *Payload) validateLoad(formats strfmt.Registry) error {
  51. if err := validate.Required("load", "body", m.Load); err != nil {
  52. return err
  53. }
  54. return nil
  55. }
  56. func (m *Payload) validatePowerplants(formats strfmt.Registry) error {
  57. if err := validate.Required("powerplants", "body", m.Powerplants); err != nil {
  58. return err
  59. }
  60. for i := 0; i < len(m.Powerplants); i++ {
  61. if swag.IsZero(m.Powerplants[i]) { // not required
  62. continue
  63. }
  64. if m.Powerplants[i] != nil {
  65. if err := m.Powerplants[i].Validate(formats); err != nil {
  66. if ve, ok := err.(*errors.Validation); ok {
  67. return ve.ValidateName("powerplants" + "." + strconv.Itoa(i))
  68. }
  69. return err
  70. }
  71. }
  72. }
  73. return nil
  74. }
  75. // ContextValidate validate this payload based on the context it is used
  76. func (m *Payload) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
  77. var res []error
  78. if err := m.contextValidatePowerplants(ctx, formats); err != nil {
  79. res = append(res, err)
  80. }
  81. if len(res) > 0 {
  82. return errors.CompositeValidationError(res...)
  83. }
  84. return nil
  85. }
  86. func (m *Payload) contextValidatePowerplants(ctx context.Context, formats strfmt.Registry) error {
  87. for i := 0; i < len(m.Powerplants); i++ {
  88. if m.Powerplants[i] != nil {
  89. if err := m.Powerplants[i].ContextValidate(ctx, formats); err != nil {
  90. if ve, ok := err.(*errors.Validation); ok {
  91. return ve.ValidateName("powerplants" + "." + strconv.Itoa(i))
  92. }
  93. return err
  94. }
  95. }
  96. }
  97. return nil
  98. }
  99. // MarshalBinary interface implementation
  100. func (m *Payload) MarshalBinary() ([]byte, error) {
  101. if m == nil {
  102. return nil, nil
  103. }
  104. return swag.WriteJSON(m)
  105. }
  106. // UnmarshalBinary interface implementation
  107. func (m *Payload) UnmarshalBinary(b []byte) error {
  108. var res Payload
  109. if err := swag.ReadJSON(b, &res); err != nil {
  110. return err
  111. }
  112. *m = res
  113. return nil
  114. }