github.com/hashicorp/hcp-sdk-go@v0.94.0/clients/cloud-vault-secrets/stable/2023-06-13/models/api_http_body.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  )
    16  
    17  // APIHTTPBody Message that represents an arbitrary HTTP body. It should only be used for
    18  // payload formats that can't be represented as JSON, such as raw binary or
    19  // an HTML page.
    20  //
    21  // This message can be used both in streaming and non-streaming API methods in
    22  // the request as well as the response.
    23  //
    24  // It can be used as a top-level request field, which is convenient if one
    25  // wants to extract parameters from either the URL or HTTP template into the
    26  // request fields and also want access to the raw HTTP body.
    27  //
    28  // Example:
    29  //
    30  //	message GetResourceRequest {
    31  //	  // A unique request id.
    32  //	  string request_id = 1;
    33  //
    34  //	  // The raw HTTP body is bound to this field.
    35  //	  google.api.HttpBody http_body = 2;
    36  //
    37  //	}
    38  //
    39  //	service ResourceService {
    40  //	  rpc GetResource(GetResourceRequest)
    41  //	    returns (google.api.HttpBody);
    42  //	  rpc UpdateResource(google.api.HttpBody)
    43  //	    returns (google.protobuf.Empty);
    44  //
    45  //	}
    46  //
    47  // Example with streaming methods:
    48  //
    49  //	service CaldavService {
    50  //	  rpc GetCalendar(stream google.api.HttpBody)
    51  //	    returns (stream google.api.HttpBody);
    52  //	  rpc UpdateCalendar(stream google.api.HttpBody)
    53  //	    returns (stream google.api.HttpBody);
    54  //
    55  //	}
    56  //
    57  // Use of this type only changes how the request and response bodies are
    58  // handled, all other features will continue to work unchanged.
    59  //
    60  // swagger:model apiHttpBody
    61  type APIHTTPBody struct {
    62  
    63  	// The HTTP Content-Type header value specifying the content type of the body.
    64  	ContentType string `json:"content_type,omitempty"`
    65  
    66  	// The HTTP request/response body as raw binary.
    67  	// Format: byte
    68  	Data strfmt.Base64 `json:"data,omitempty"`
    69  
    70  	// Application specific response metadata. Must be set in the first response
    71  	// for streaming APIs.
    72  	Extensions []*ProtobufAny `json:"extensions"`
    73  }
    74  
    75  // Validate validates this api Http body
    76  func (m *APIHTTPBody) Validate(formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.validateExtensions(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if len(res) > 0 {
    84  		return errors.CompositeValidationError(res...)
    85  	}
    86  	return nil
    87  }
    88  
    89  func (m *APIHTTPBody) validateExtensions(formats strfmt.Registry) error {
    90  	if swag.IsZero(m.Extensions) { // not required
    91  		return nil
    92  	}
    93  
    94  	for i := 0; i < len(m.Extensions); i++ {
    95  		if swag.IsZero(m.Extensions[i]) { // not required
    96  			continue
    97  		}
    98  
    99  		if m.Extensions[i] != nil {
   100  			if err := m.Extensions[i].Validate(formats); err != nil {
   101  				if ve, ok := err.(*errors.Validation); ok {
   102  					return ve.ValidateName("extensions" + "." + strconv.Itoa(i))
   103  				} else if ce, ok := err.(*errors.CompositeError); ok {
   104  					return ce.ValidateName("extensions" + "." + strconv.Itoa(i))
   105  				}
   106  				return err
   107  			}
   108  		}
   109  
   110  	}
   111  
   112  	return nil
   113  }
   114  
   115  // ContextValidate validate this api Http body based on the context it is used
   116  func (m *APIHTTPBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   117  	var res []error
   118  
   119  	if err := m.contextValidateExtensions(ctx, formats); err != nil {
   120  		res = append(res, err)
   121  	}
   122  
   123  	if len(res) > 0 {
   124  		return errors.CompositeValidationError(res...)
   125  	}
   126  	return nil
   127  }
   128  
   129  func (m *APIHTTPBody) contextValidateExtensions(ctx context.Context, formats strfmt.Registry) error {
   130  
   131  	for i := 0; i < len(m.Extensions); i++ {
   132  
   133  		if m.Extensions[i] != nil {
   134  
   135  			if swag.IsZero(m.Extensions[i]) { // not required
   136  				return nil
   137  			}
   138  
   139  			if err := m.Extensions[i].ContextValidate(ctx, formats); err != nil {
   140  				if ve, ok := err.(*errors.Validation); ok {
   141  					return ve.ValidateName("extensions" + "." + strconv.Itoa(i))
   142  				} else if ce, ok := err.(*errors.CompositeError); ok {
   143  					return ce.ValidateName("extensions" + "." + strconv.Itoa(i))
   144  				}
   145  				return err
   146  			}
   147  		}
   148  
   149  	}
   150  
   151  	return nil
   152  }
   153  
   154  // MarshalBinary interface implementation
   155  func (m *APIHTTPBody) MarshalBinary() ([]byte, error) {
   156  	if m == nil {
   157  		return nil, nil
   158  	}
   159  	return swag.WriteJSON(m)
   160  }
   161  
   162  // UnmarshalBinary interface implementation
   163  func (m *APIHTTPBody) UnmarshalBinary(b []byte) error {
   164  	var res APIHTTPBody
   165  	if err := swag.ReadJSON(b, &res); err != nil {
   166  		return err
   167  	}
   168  	*m = res
   169  	return nil
   170  }