mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
33 lines
780 B
Go
33 lines
780 B
Go
package restfulspec
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
restful "github.com/emicklei/go-restful"
|
|
"github.com/go-openapi/spec"
|
|
)
|
|
|
|
func buildDefinitions(ws *restful.WebService, cfg Config) (definitions spec.Definitions) {
|
|
definitions = spec.Definitions{}
|
|
for _, each := range ws.Routes() {
|
|
addDefinitionsFromRouteTo(each, cfg, definitions)
|
|
}
|
|
return
|
|
}
|
|
|
|
func addDefinitionsFromRouteTo(r restful.Route, cfg Config, d spec.Definitions) {
|
|
builder := definitionBuilder{Definitions: d, Config: cfg}
|
|
if r.ReadSample != nil {
|
|
builder.addModel(reflect.TypeOf(r.ReadSample), "")
|
|
}
|
|
if r.WriteSample != nil {
|
|
builder.addModel(reflect.TypeOf(r.WriteSample), "")
|
|
}
|
|
for _, v := range r.ResponseErrors {
|
|
if v.Model == nil {
|
|
continue
|
|
}
|
|
builder.addModel(reflect.TypeOf(v.Model), "")
|
|
}
|
|
}
|