k8s.io/kube-openapi@v0.0.0-20240228011516-70dd3763d340/pkg/common/restfuladapter/param_adapter.go (about)

     1  package restfuladapter
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/emicklei/go-restful/v3"
     6  	"k8s.io/kube-openapi/pkg/common"
     7  )
     8  
     9  var _ common.Parameter = &ParamAdapter{}
    10  
    11  type ParamAdapter struct {
    12  	Param *restful.Parameter
    13  }
    14  
    15  func (r *ParamAdapter) MarshalJSON() ([]byte, error) {
    16  	return json.Marshal(r.Param)
    17  }
    18  
    19  func (r *ParamAdapter) Name() string {
    20  	return r.Param.Data().Name
    21  }
    22  
    23  func (r *ParamAdapter) Description() string {
    24  	return r.Param.Data().Description
    25  }
    26  
    27  func (r *ParamAdapter) Required() bool {
    28  	return r.Param.Data().Required
    29  }
    30  
    31  func (r *ParamAdapter) Kind() common.ParameterKind {
    32  	switch r.Param.Kind() {
    33  	case restful.PathParameterKind:
    34  		return common.PathParameterKind
    35  	case restful.QueryParameterKind:
    36  		return common.QueryParameterKind
    37  	case restful.BodyParameterKind:
    38  		return common.BodyParameterKind
    39  	case restful.HeaderParameterKind:
    40  		return common.HeaderParameterKind
    41  	case restful.FormParameterKind:
    42  		return common.FormParameterKind
    43  	default:
    44  		return common.UnknownParameterKind
    45  	}
    46  }
    47  
    48  func (r *ParamAdapter) DataType() string {
    49  	return r.Param.Data().DataType
    50  }
    51  
    52  func (r *ParamAdapter) AllowMultiple() bool {
    53  	return r.Param.Data().AllowMultiple
    54  }