func (c yamlCodec) Decode(data []byte) (Object, error) { out, err := yaml.ToJSON(data) if err != nil { return nil, err } data = out return c.Codec.Decode(data) }
func (c yamlCodec) DecodeInto(data []byte, obj Object) error { out, err := yaml.ToJSON(data) if err != nil { return err } data = out return c.Codec.DecodeInto(data, obj) }
// AddObjectsFromPath loads the JSON or YAML file containing Kubernetes API resources // and adds them to the provided ObjectRetriever. func AddObjectsFromPath(path string, o ObjectRetriever, decoder runtime.Decoder) error { data, err := ioutil.ReadFile(path) if err != nil { return err } data, err = yaml.ToJSON(data) if err != nil { return err } obj, err := runtime.Decode(decoder, data) if err != nil { return err } if err := o.Add(obj); err != nil { return err } return nil }
func (s *SwaggerSchema) ValidateBytes(data []byte) error { var obj interface{} out, err := yaml.ToJSON(data) if err != nil { return err } data = out if err := json.Unmarshal(data, &obj); err != nil { return err } fields, ok := obj.(map[string]interface{}) if !ok { return fmt.Errorf("error in unmarshaling data %s", string(data)) } groupVersion := fields["apiVersion"] if groupVersion == nil { return fmt.Errorf("apiVersion not set") } if _, ok := groupVersion.(string); !ok { return fmt.Errorf("apiVersion isn't string type") } kind := fields["kind"] if kind == nil { return fmt.Errorf("kind not set") } if _, ok := kind.(string); !ok { return fmt.Errorf("kind isn't string type") } if strings.HasSuffix(kind.(string), "List") { return utilerrors.NewAggregate(s.validateList(fields)) } version := apiutil.GetVersion(groupVersion.(string)) allErrs := s.ValidateObject(obj, "", version+"."+kind.(string)) if len(allErrs) == 1 { return allErrs[0] } return utilerrors.NewAggregate(allErrs) }