github.com/openshift/installer@v1.4.17/pkg/explain/fields_lookup.go (about)

     1  package explain
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  	apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
     6  )
     7  
     8  func lookup(schema *apiextv1.JSONSchemaProps, path []string) (*apiextv1.JSONSchemaProps, error) {
     9  	if len(path) == 0 {
    10  		return schema, nil
    11  	}
    12  
    13  	properties := map[string]apiextv1.JSONSchemaProps{}
    14  	if schema.Items != nil && schema.Items.Schema != nil {
    15  		properties = schema.Items.Schema.Properties
    16  	}
    17  	if len(schema.Properties) > 0 {
    18  		properties = schema.Properties
    19  	}
    20  
    21  	property, ok := properties[path[0]]
    22  	if !ok {
    23  		return nil, errors.Errorf("invalid field %s, no such property found", path[0])
    24  	}
    25  	return lookup(&property, path[1:])
    26  }