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