| 1 |
package restfuladapter |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/emicklei/go-restful/v3" |
| 5 |
"k8s.io/kube-openapi/pkg/common" |
| 6 |
) |
| 7 |
|
| 8 |
var _ common.Route = &RouteAdapter{} |
| 9 |
|
| 10 |
// RouteAdapter adapts a restful.Route to common.Route. |
| 11 |
type RouteAdapter struct { |
| 12 |
Route *restful.Route |
| 13 |
} |
| 14 |
|
| 15 |
func (r *RouteAdapter) StatusCodeResponses() []common.StatusCodeResponse { |
| 16 |
// go-restful uses the ResponseErrors field to contain both error and regular responses. |
| 17 |
var responses []common.StatusCodeResponse |
| 18 |
for _, res := range r.Route.ResponseErrors { |
| 19 |
localRes := res |
| 20 |
responses = append(responses, &ResponseErrorAdapter{&localRes}) |
| 21 |
} |
| 22 |
|
| 23 |
return responses |
| 24 |
} |
| 25 |
|
| 26 |
func (r *RouteAdapter) OperationName() string { |
| 27 |
return r.Route.Operation |
| 28 |
} |
| 29 |
|
| 30 |
func (r *RouteAdapter) Method() string { |
| 31 |
return r.Route.Method |
| 32 |
} |
| 33 |
|
| 34 |
func (r *RouteAdapter) Path() string { |
| 35 |
return r.Route.Path |
| 36 |
} |
| 37 |
|
| 38 |
func (r *RouteAdapter) Parameters() []common.Parameter { |
| 39 |
var params []common.Parameter |
| 40 |
for _, rParam := range r.Route.ParameterDocs { |
| 41 |
params = append(params, &ParamAdapter{rParam}) |
| 42 |
} |
| 43 |
return params |
| 44 |
} |
| 45 |
|
| 46 |
func (r *RouteAdapter) Description() string { |
| 47 |
return r.Route.Doc |
| 48 |
} |
| 49 |
|
| 50 |
func (r *RouteAdapter) Consumes() []string { |
| 51 |
return r.Route.Consumes |
| 52 |
} |
| 53 |
|
| 54 |
func (r *RouteAdapter) Produces() []string { |
| 55 |
return r.Route.Produces |
| 56 |
} |
| 57 |
|
| 58 |
func (r *RouteAdapter) Metadata() map[string]interface{} { |
| 59 |
return r.Route.Metadata |
| 60 |
} |
| 61 |
|
| 62 |
func (r *RouteAdapter) RequestPayloadSample() interface{} { |
| 63 |
return r.Route.ReadSample |
| 64 |
} |
| 65 |
|
| 66 |
func (r *RouteAdapter) ResponsePayloadSample() interface{} { |
| 67 |
return r.Route.WriteSample |
| 68 |
} |