Fix referencing another schema file relative to CWD

After the switch to github.com/santhosh-tekuri/jsonschema/v6 we noticed that one of our charts was failing with the following error:

> Error: values don't meet the specifications of the schema(s) in the following chart(s):
> my-chart:
> failing loading "file://./schema/library.json": open /schema/library.json: no such file or directory

Checking against helm v3.18.4 (the last version of helm to use the old jsonschema module) everything worked as expected.

From what I can tell, the newly adopted jsonschema module automatically prefixes "file://" onto the schema path, and any references within the main values.schema.json

This commit, as best as I can test, puts back the behaviour found in v3.18.4 where executing a helm subcommand that validates against a values.schema.json file it follows references to additional schema files.

Signed-off-by: Ben Lavery-Griffiths <ben@lavery-griffiths.com>
pull/31261/head
Ben Lavery-Griffiths 2 weeks ago
parent cd78e2396b
commit 767e2be528
No known key found for this signature in database
GPG Key ID: 69930B125E633F64

@ -131,12 +131,12 @@ func ValidateAgainstSingleSchema(values common.Values, schemaJSON []byte) (reter
compiler := jsonschema.NewCompiler()
compiler.UseLoader(loader)
err = compiler.AddResource("file:///values.schema.json", schema)
err = compiler.AddResource("./values.schema.json", schema)
if err != nil {
return err
}
validator, err := compiler.Compile("file:///values.schema.json")
validator, err := compiler.Compile("./values.schema.json")
if err != nil {
return err
}
@ -165,7 +165,7 @@ func (e JSONSchemaValidationError) Error() string {
// This string prefixes all of our error details. Further up the stack of helm error message
// building more detail is provided to users. This is removed.
errStr = strings.TrimPrefix(errStr, "jsonschema validation failed with 'file:///values.schema.json#'\n")
errStr = strings.TrimPrefix(errStr, "jsonschema validation failed with './values.schema.json#'\n")
// The extra new line is needed for when there are sub-charts.
return errStr + "\n"

Loading…
Cancel
Save