File: route_adapter.go

package info (click to toggle)
golang-k8s-kube-openapi 0.0~git20241212.2c72e55-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,396 kB
  • sloc: sh: 50; makefile: 5
file content (68 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package restfuladapter

import (
	"github.com/emicklei/go-restful/v3"
	"k8s.io/kube-openapi/pkg/common"
)

var _ common.Route = &RouteAdapter{}

// RouteAdapter adapts a restful.Route to common.Route.
type RouteAdapter struct {
	Route *restful.Route
}

func (r *RouteAdapter) StatusCodeResponses() []common.StatusCodeResponse {
	// go-restful uses the ResponseErrors field to contain both error and regular responses.
	var responses []common.StatusCodeResponse
	for _, res := range r.Route.ResponseErrors {
		localRes := res
		responses = append(responses, &ResponseErrorAdapter{&localRes})
	}

	return responses
}

func (r *RouteAdapter) OperationName() string {
	return r.Route.Operation
}

func (r *RouteAdapter) Method() string {
	return r.Route.Method
}

func (r *RouteAdapter) Path() string {
	return r.Route.Path
}

func (r *RouteAdapter) Parameters() []common.Parameter {
	var params []common.Parameter
	for _, rParam := range r.Route.ParameterDocs {
		params = append(params, &ParamAdapter{rParam})
	}
	return params
}

func (r *RouteAdapter) Description() string {
	return r.Route.Doc
}

func (r *RouteAdapter) Consumes() []string {
	return r.Route.Consumes
}

func (r *RouteAdapter) Produces() []string {
	return r.Route.Produces
}

func (r *RouteAdapter) Metadata() map[string]interface{} {
	return r.Route.Metadata
}

func (r *RouteAdapter) RequestPayloadSample() interface{} {
	return r.Route.ReadSample
}

func (r *RouteAdapter) ResponsePayloadSample() interface{} {
	return r.Route.WriteSample
}