mirror of
https://github.com/rancher/norman.git
synced 2025-09-17 07:40:10 +00:00
Random fixes
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
var (
|
||||
resourceType = reflect.TypeOf(Resource{})
|
||||
typeType = reflect.TypeOf(metav1.TypeMeta{})
|
||||
metaType = reflect.TypeOf(metav1.ObjectMeta{})
|
||||
blacklistNames = map[string]bool{
|
||||
"links": true,
|
||||
@@ -114,6 +115,9 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
|
||||
schema.ResourceMethods = []string{"GET", "PUT", "DELETE"}
|
||||
}
|
||||
|
||||
hasType := false
|
||||
hasMeta := false
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
|
||||
@@ -128,6 +132,14 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if field.Anonymous && jsonName == "" && field.Type == typeType {
|
||||
hasType = true
|
||||
}
|
||||
|
||||
if field.Anonymous && jsonName == "metadata" && field.Type == metaType {
|
||||
hasMeta = true
|
||||
}
|
||||
|
||||
if field.Anonymous && jsonName == "" {
|
||||
t := field.Type
|
||||
if t.Kind() == reflect.Ptr {
|
||||
@@ -177,15 +189,15 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
|
||||
schemaField.Type = inferedType
|
||||
}
|
||||
|
||||
if field.Type == metaType {
|
||||
schema.CollectionMethods = []string{"GET", "POST"}
|
||||
schema.ResourceMethods = []string{"GET", "PUT", "DELETE"}
|
||||
}
|
||||
|
||||
logrus.Debugf("Setting field %s.%s: %#v", schema.ID, fieldName, schemaField)
|
||||
schema.ResourceFields[fieldName] = schemaField
|
||||
}
|
||||
|
||||
if hasType && hasMeta {
|
||||
schema.CollectionMethods = []string{"GET", "POST"}
|
||||
schema.ResourceMethods = []string{"GET", "PUT", "DELETE"}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user