Switch to using a third-party library for JSON conversion

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5350/head
Ian Howell 7 years ago
parent 8e050bb4b0
commit fe80e65628

@ -17,7 +17,6 @@ limitations under the License.
package chartutil package chartutil
import ( import (
"encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -158,8 +157,14 @@ func ReadSchemaFile(filename string) (Schema, error) {
// ValidateAgainstSchema checks that values does not violate the structure laid out in schema // ValidateAgainstSchema checks that values does not violate the structure laid out in schema
func ValidateAgainstSchema(values Values, schema Schema) error { func ValidateAgainstSchema(values Values, schema Schema) error {
valuesJSON := convertToJSON(values) valuesJSON, err := convertYAMLToJSON(values)
schemaJSON := convertToJSON(schema) if err != nil {
return err
}
schemaJSON, err := convertYAMLToJSON(schema)
if err != nil {
return err
}
schemaLoader := gojsonschema.NewStringLoader(string(schemaJSON)) schemaLoader := gojsonschema.NewStringLoader(string(schemaJSON))
valuesLoader := gojsonschema.NewStringLoader(string(valuesJSON)) valuesLoader := gojsonschema.NewStringLoader(string(valuesJSON))
@ -461,13 +466,13 @@ func istable(v interface{}) bool {
return ok return ok
} }
// convertToJSON takes YAML and returns a []byte representation of the same object as JSON // convertToJSON takes YAML data and returns a []byte representation of the same object as JSON
func convertToJSON(data interface{}) []byte { func convertYAMLToJSON(data interface{}) ([]byte, error) {
js, err := json.Marshal(data) yamlData, err := yaml.Marshal(data)
if err != nil { if err != nil {
panic(err.Error()) return nil, err
} }
return js return yaml.YAMLToJSON(yamlData)
} }
// PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. // PathValue takes a path that traverses a YAML structure and returns the value at the end of that path.

Loading…
Cancel
Save