mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Fix up parameter handling. Also handle type mapping between Go and JSON
This commit is contained in:
parent
d70d2d20cd
commit
ee0d71aac6
@ -230,7 +230,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||
namer := scopeNaming{scope, a.group.Linker, gpath.Join(a.prefix, itemPath), false}
|
||||
|
||||
actions = appendIf(actions, action{"LIST", resourcePath, namespaceParams, namer}, isLister)
|
||||
actions = appendIf(actions, action{"POST", resourcePath, namespaceParams, namer}, isCreater)
|
||||
// Some paths ("/pods/{name}/binding", I'm looking at you) contain an embedded '{name}')
|
||||
if strings.Contains(resourcePath, "{name}") {
|
||||
actions = appendIf(actions, action{"POST", resourcePath, nameParams, namer}, isCreater)
|
||||
} else {
|
||||
actions = appendIf(actions, action{"POST", resourcePath, namespaceParams, namer}, isCreater)
|
||||
}
|
||||
actions = appendIf(actions, action{"WATCHLIST", "watch/" + resourcePath, namespaceParams, namer}, allowWatchList)
|
||||
|
||||
actions = appendIf(actions, action{"GET", itemPath, nameParams, namer}, isGetter)
|
||||
@ -706,13 +711,32 @@ func addObjectParams(ws *restful.WebService, route *restful.RouteBuilder, obj ru
|
||||
continue
|
||||
}
|
||||
desc := sf.Tag.Get("description")
|
||||
route.Param(ws.QueryParameter(jsonName, desc).DataType(sf.Type.Name()))
|
||||
route.Param(ws.QueryParameter(jsonName, desc).DataType(typeToJSON(sf.Type.Name())))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: this is incomplete, expand as needed.
|
||||
// Convert the name of a golang type to the name of a JSON type
|
||||
func typeToJSON(typeName string) string {
|
||||
switch typeName {
|
||||
case "bool":
|
||||
return "boolean"
|
||||
case "uint8", "int", "int32", "int64", "uint32", "uint64":
|
||||
return "integer"
|
||||
case "byte":
|
||||
return "string"
|
||||
case "float64", "float32":
|
||||
return "number"
|
||||
case "time/Time":
|
||||
return "string"
|
||||
default:
|
||||
return typeName
|
||||
}
|
||||
}
|
||||
|
||||
// defaultStorageMetadata provides default answers to rest.StorageMetadata.
|
||||
type defaultStorageMetadata struct{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user