Update vendor dir and Godeps.json with new Godep

This commit is contained in:
mbohlool 2016-06-28 02:01:10 -07:00
parent e0b1336ef4
commit 809199ce38
10 changed files with 54 additions and 45 deletions

14
Godeps/Godeps.json generated
View File

@ -1,7 +1,7 @@
{ {
"ImportPath": "k8s.io/kubernetes", "ImportPath": "k8s.io/kubernetes",
"GoVersion": "go1.6", "GoVersion": "go1.6",
"GodepVersion": "v74", "GodepVersion": "v67",
"Packages": [ "Packages": [
"github.com/ugorji/go/codec/codecgen", "github.com/ugorji/go/codec/codecgen",
"github.com/onsi/ginkgo/ginkgo", "github.com/onsi/ginkgo/ginkgo",
@ -744,18 +744,18 @@
}, },
{ {
"ImportPath": "github.com/emicklei/go-restful", "ImportPath": "github.com/emicklei/go-restful",
"Comment": "v1.2-54-g7c47e25", "Comment": "v1.2-66-gc4afa8e",
"Rev": "7c47e2558a0bbbaba9ecab06bc6681e73028a28a" "Rev": "c4afa8e5421428d584b32d36d7b35f2c9ae5f823"
}, },
{ {
"ImportPath": "github.com/emicklei/go-restful/log", "ImportPath": "github.com/emicklei/go-restful/log",
"Comment": "v1.2-54-g7c47e25", "Comment": "v1.2-66-gc4afa8e",
"Rev": "7c47e2558a0bbbaba9ecab06bc6681e73028a28a" "Rev": "c4afa8e5421428d584b32d36d7b35f2c9ae5f823"
}, },
{ {
"ImportPath": "github.com/emicklei/go-restful/swagger", "ImportPath": "github.com/emicklei/go-restful/swagger",
"Comment": "v1.2-54-g7c47e25", "Comment": "v1.2-66-gc4afa8e",
"Rev": "7c47e2558a0bbbaba9ecab06bc6681e73028a28a" "Rev": "c4afa8e5421428d584b32d36d7b35f2c9ae5f823"
}, },
{ {
"ImportPath": "github.com/evanphx/json-patch", "ImportPath": "github.com/evanphx/json-patch",

View File

@ -40,7 +40,7 @@ func (u UserResource) findUser(request *restful.Request, response *restful.Respo
- Routes for request → function mapping with path parameter (e.g. {id}) support - Routes for request → function mapping with path parameter (e.g. {id}) support
- Configurable router: - Configurable router:
- Routing algorithm after [JSR311](http://jsr311.java.net/nonav/releases/1.1/spec/spec.html) that is implemented using (but doest **not** accept) regular expressions (See RouterJSR311 which is used by default) - Routing algorithm after [JSR311](http://jsr311.java.net/nonav/releases/1.1/spec/spec.html) that is implemented using (but does **not** accept) regular expressions (See RouterJSR311 which is used by default)
- Fast routing algorithm that allows static elements, regular expressions and dynamic parameters in the URL path (e.g. /meetings/{id} or /static/{subpath:*}, See CurlyRouter) - Fast routing algorithm that allows static elements, regular expressions and dynamic parameters in the URL path (e.g. /meetings/{id} or /static/{subpath:*}, See CurlyRouter)
- Request API for reading structs from JSON/XML and accesing parameters (path,query,header) - Request API for reading structs from JSON/XML and accesing parameters (path,query,header)
- Response API for writing structs to JSON/XML and setting headers - Response API for writing structs to JSON/XML and setting headers

View File

@ -44,16 +44,16 @@ func (c CurlyRouter) SelectRoute(
} }
// selectRoutes return a collection of Route from a WebService that matches the path tokens from the request. // selectRoutes return a collection of Route from a WebService that matches the path tokens from the request.
func (c CurlyRouter) selectRoutes(ws *WebService, requestTokens []string) []Route { func (c CurlyRouter) selectRoutes(ws *WebService, requestTokens []string) sortableCurlyRoutes {
candidates := &sortableCurlyRoutes{[]*curlyRoute{}} candidates := sortableCurlyRoutes{}
for _, each := range ws.routes { for _, each := range ws.routes {
matches, paramCount, staticCount := c.matchesRouteByPathTokens(each.pathParts, requestTokens) matches, paramCount, staticCount := c.matchesRouteByPathTokens(each.pathParts, requestTokens)
if matches { if matches {
candidates.add(&curlyRoute{each, paramCount, staticCount}) // TODO make sure Routes() return pointers? candidates.add(curlyRoute{each, paramCount, staticCount}) // TODO make sure Routes() return pointers?
} }
} }
sort.Sort(sort.Reverse(candidates)) sort.Sort(sort.Reverse(candidates))
return candidates.routes() return candidates
} }
// matchesRouteByPathTokens computes whether it matches, howmany parameters do match and what the number of static path elements are. // matchesRouteByPathTokens computes whether it matches, howmany parameters do match and what the number of static path elements are.
@ -110,9 +110,9 @@ func (c CurlyRouter) regularMatchesPathToken(routeToken string, colon int, reque
// detectRoute selectes from a list of Route the first match by inspecting both the Accept and Content-Type // detectRoute selectes from a list of Route the first match by inspecting both the Accept and Content-Type
// headers of the Request. See also RouterJSR311 in jsr311.go // headers of the Request. See also RouterJSR311 in jsr311.go
func (c CurlyRouter) detectRoute(candidateRoutes []Route, httpRequest *http.Request) (*Route, error) { func (c CurlyRouter) detectRoute(candidateRoutes sortableCurlyRoutes, httpRequest *http.Request) (*Route, error) {
// tracing is done inside detectRoute // tracing is done inside detectRoute
return RouterJSR311{}.detectRoute(candidateRoutes, httpRequest) return RouterJSR311{}.detectRoute(candidateRoutes.routes(), httpRequest)
} }
// detectWebService returns the best matching webService given the list of path tokens. // detectWebService returns the best matching webService given the list of path tokens.

View File

@ -11,30 +11,28 @@ type curlyRoute struct {
staticCount int staticCount int
} }
type sortableCurlyRoutes struct { type sortableCurlyRoutes []curlyRoute
candidates []*curlyRoute
func (s *sortableCurlyRoutes) add(route curlyRoute) {
*s = append(*s, route)
} }
func (s *sortableCurlyRoutes) add(route *curlyRoute) { func (s sortableCurlyRoutes) routes() (routes []Route) {
s.candidates = append(s.candidates, route) for _, each := range s {
}
func (s *sortableCurlyRoutes) routes() (routes []Route) {
for _, each := range s.candidates {
routes = append(routes, each.route) // TODO change return type routes = append(routes, each.route) // TODO change return type
} }
return routes return routes
} }
func (s *sortableCurlyRoutes) Len() int { func (s sortableCurlyRoutes) Len() int {
return len(s.candidates) return len(s)
} }
func (s *sortableCurlyRoutes) Swap(i, j int) { func (s sortableCurlyRoutes) Swap(i, j int) {
s.candidates[i], s.candidates[j] = s.candidates[j], s.candidates[i] s[i], s[j] = s[j], s[i]
} }
func (s *sortableCurlyRoutes) Less(i, j int) bool { func (s sortableCurlyRoutes) Less(i, j int) bool {
ci := s.candidates[i] ci := s[i]
cj := s.candidates[j] cj := s[j]
// primary key // primary key
if ci.staticCount < cj.staticCount { if ci.staticCount < cj.staticCount {

View File

@ -74,7 +74,7 @@ func (r RouterJSR311) detectRoute(routes []Route, httpRequest *http.Request) (*R
// accept // accept
outputMediaOk := []Route{} outputMediaOk := []Route{}
accept := httpRequest.Header.Get(HEADER_Accept) accept := httpRequest.Header.Get(HEADER_Accept)
if accept == "" { if len(accept) == 0 {
accept = "*/*" accept = "*/*"
} }
for _, each := range inputMediaOk { for _, each := range inputMediaOk {
@ -88,7 +88,8 @@ func (r RouterJSR311) detectRoute(routes []Route, httpRequest *http.Request) (*R
} }
return nil, NewError(http.StatusNotAcceptable, "406: Not Acceptable") return nil, NewError(http.StatusNotAcceptable, "406: Not Acceptable")
} }
return r.bestMatchByMedia(outputMediaOk, contentType, accept), nil // return r.bestMatchByMedia(outputMediaOk, contentType, accept), nil
return &outputMediaOk[0], nil
} }
// http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2 // http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2

View File

@ -130,25 +130,25 @@ func (r *Response) WriteHeaderAndEntity(status int, value interface{}) error {
} }
// WriteAsXml is a convenience method for writing a value in xml (requires Xml tags on the value) // WriteAsXml is a convenience method for writing a value in xml (requires Xml tags on the value)
// It uses the standard encoding/xml package for marshalling the valuel ; not using a registered EntityReaderWriter. // It uses the standard encoding/xml package for marshalling the value ; not using a registered EntityReaderWriter.
func (r *Response) WriteAsXml(value interface{}) error { func (r *Response) WriteAsXml(value interface{}) error {
return writeXML(r, http.StatusOK, MIME_XML, value) return writeXML(r, http.StatusOK, MIME_XML, value)
} }
// WriteHeaderAndXml is a convenience method for writing a status and value in xml (requires Xml tags on the value) // WriteHeaderAndXml is a convenience method for writing a status and value in xml (requires Xml tags on the value)
// It uses the standard encoding/xml package for marshalling the valuel ; not using a registered EntityReaderWriter. // It uses the standard encoding/xml package for marshalling the value ; not using a registered EntityReaderWriter.
func (r *Response) WriteHeaderAndXml(status int, value interface{}) error { func (r *Response) WriteHeaderAndXml(status int, value interface{}) error {
return writeXML(r, status, MIME_XML, value) return writeXML(r, status, MIME_XML, value)
} }
// WriteAsJson is a convenience method for writing a value in json. // WriteAsJson is a convenience method for writing a value in json.
// It uses the standard encoding/json package for marshalling the valuel ; not using a registered EntityReaderWriter. // It uses the standard encoding/json package for marshalling the value ; not using a registered EntityReaderWriter.
func (r *Response) WriteAsJson(value interface{}) error { func (r *Response) WriteAsJson(value interface{}) error {
return writeJSON(r, http.StatusOK, MIME_JSON, value) return writeJSON(r, http.StatusOK, MIME_JSON, value)
} }
// WriteJson is a convenience method for writing a value in Json with a given Content-Type. // WriteJson is a convenience method for writing a value in Json with a given Content-Type.
// It uses the standard encoding/json package for marshalling the valuel ; not using a registered EntityReaderWriter. // It uses the standard encoding/json package for marshalling the value ; not using a registered EntityReaderWriter.
func (r *Response) WriteJson(value interface{}, contentType string) error { func (r *Response) WriteJson(value interface{}, contentType string) error {
return writeJSON(r, http.StatusOK, contentType, value) return writeJSON(r, http.StatusOK, contentType, value)
} }

View File

@ -128,7 +128,7 @@ func (b *RouteBuilder) Param(parameter *Parameter) *RouteBuilder {
return b return b
} }
// Operation allows you to document what the acutal method/function call is of the Route. // Operation allows you to document what the actual method/function call is of the Route.
// Unless called, the operation name is derived from the RouteFunction set using To(..). // Unless called, the operation name is derived from the RouteFunction set using To(..).
func (b *RouteBuilder) Operation(name string) *RouteBuilder { func (b *RouteBuilder) Operation(name string) *RouteBuilder {
b.operation = name b.operation = name

View File

@ -9,6 +9,8 @@ import (
// PostBuildDeclarationMapFunc can be used to modify the api declaration map. // PostBuildDeclarationMapFunc can be used to modify the api declaration map.
type PostBuildDeclarationMapFunc func(apiDeclarationMap *ApiDeclarationList) type PostBuildDeclarationMapFunc func(apiDeclarationMap *ApiDeclarationList)
type MapSchemaFormatFunc func(typeName string) string
type Config struct { type Config struct {
// url where the services are available, e.g. http://localhost:8080 // url where the services are available, e.g. http://localhost:8080
// if left empty then the basePath of Swagger is taken from the actual request // if left empty then the basePath of Swagger is taken from the actual request
@ -31,4 +33,6 @@ type Config struct {
PostBuildHandler PostBuildDeclarationMapFunc PostBuildHandler PostBuildDeclarationMapFunc
// Swagger global info struct // Swagger global info struct
Info Info Info Info
// [optional] If set, model builder should call this handler to get addition typename-to-swagger-format-field convertion.
SchemaFormatHandler MapSchemaFormatFunc
} }

View File

@ -14,6 +14,7 @@ type ModelBuildable interface {
type modelBuilder struct { type modelBuilder struct {
Models *ModelList Models *ModelList
Config *Config
} }
type documentable interface { type documentable interface {
@ -231,7 +232,7 @@ func (b modelBuilder) buildStructTypeProperty(field reflect.StructField, jsonNam
if field.Name == fieldType.Name() && field.Anonymous && !hasNamedJSONTag(field) { if field.Name == fieldType.Name() && field.Anonymous && !hasNamedJSONTag(field) {
// embedded struct // embedded struct
sub := modelBuilder{new(ModelList)} sub := modelBuilder{new(ModelList), b.Config}
sub.addModel(fieldType, "") sub.addModel(fieldType, "")
subKey := sub.keyFrom(fieldType) subKey := sub.keyFrom(fieldType)
// merge properties from sub // merge properties from sub
@ -410,6 +411,11 @@ func (b modelBuilder) jsonSchemaType(modelName string) string {
} }
func (b modelBuilder) jsonSchemaFormat(modelName string) string { func (b modelBuilder) jsonSchemaFormat(modelName string) string {
if b.Config != nil && b.Config.SchemaFormatHandler != nil {
if mapped := b.Config.SchemaFormatHandler(modelName); mapped != "" {
return mapped
}
}
schemaMap := map[string]string{ schemaMap := map[string]string{
"int": "int32", "int": "int32",
"int32": "int32", "int32": "int32",

View File

@ -241,7 +241,7 @@ func (sws SwaggerService) composeDeclaration(ws *restful.WebService, pathPrefix
DataTypeFields: DataTypeFields{Type: &voidString}, DataTypeFields: DataTypeFields{Type: &voidString},
Parameters: []Parameter{}, Parameters: []Parameter{},
Nickname: route.Operation, Nickname: route.Operation,
ResponseMessages: composeResponseMessages(route, &decl)} ResponseMessages: composeResponseMessages(route, &decl, &sws.config)}
operation.Consumes = route.Consumes operation.Consumes = route.Consumes
operation.Produces = route.Produces operation.Produces = route.Produces
@ -271,7 +271,7 @@ func withoutWildcard(path string) string {
} }
// composeResponseMessages takes the ResponseErrors (if any) and creates ResponseMessages from them. // composeResponseMessages takes the ResponseErrors (if any) and creates ResponseMessages from them.
func composeResponseMessages(route restful.Route, decl *ApiDeclaration) (messages []ResponseMessage) { func composeResponseMessages(route restful.Route, decl *ApiDeclaration, config *Config) (messages []ResponseMessage) {
if route.ResponseErrors == nil { if route.ResponseErrors == nil {
return messages return messages
} }
@ -294,7 +294,7 @@ func composeResponseMessages(route restful.Route, decl *ApiDeclaration) (message
if isCollection { if isCollection {
modelName = "array[" + modelName + "]" modelName = "array[" + modelName + "]"
} }
modelBuilder{&decl.Models}.addModel(st, "") modelBuilder{Models: &decl.Models, Config: config}.addModel(st, "")
// reference the model // reference the model
message.ResponseModel = modelName message.ResponseModel = modelName
} }
@ -332,11 +332,11 @@ func detectCollectionType(st reflect.Type) (bool, reflect.Type) {
// addModelFromSample creates and adds (or overwrites) a Model from a sample resource // addModelFromSample creates and adds (or overwrites) a Model from a sample resource
func (sws SwaggerService) addModelFromSampleTo(operation *Operation, isResponse bool, sample interface{}, models *ModelList) { func (sws SwaggerService) addModelFromSampleTo(operation *Operation, isResponse bool, sample interface{}, models *ModelList) {
if isResponse { if isResponse {
type_, items := asDataType(sample) type_, items := asDataType(sample, &sws.config)
operation.Type = type_ operation.Type = type_
operation.Items = items operation.Items = items
} }
modelBuilder{models}.addModelFrom(sample) modelBuilder{Models: models, Config: &sws.config}.addModelFrom(sample)
} }
func asSwaggerParameter(param restful.ParameterData) Parameter { func asSwaggerParameter(param restful.ParameterData) Parameter {
@ -411,7 +411,7 @@ func asParamType(kind int) string {
return "" return ""
} }
func asDataType(any interface{}) (*string, *Item) { func asDataType(any interface{}, config *Config) (*string, *Item) {
// If it's not a collection, return the suggested model name // If it's not a collection, return the suggested model name
st := reflect.TypeOf(any) st := reflect.TypeOf(any)
isCollection, st := detectCollectionType(st) isCollection, st := detectCollectionType(st)
@ -424,7 +424,7 @@ func asDataType(any interface{}) (*string, *Item) {
// XXX: This is not very elegant // XXX: This is not very elegant
// We create an Item object referring to the given model // We create an Item object referring to the given model
models := ModelList{} models := ModelList{}
mb := modelBuilder{&models} mb := modelBuilder{Models: &models, Config: config}
mb.addModelFrom(any) mb.addModelFrom(any)
elemTypeName := mb.getElementTypeName(modelName, "", st) elemTypeName := mb.getElementTypeName(modelName, "", st)