From 7bdff25775423595e0b730fbaf6c60898542bd6e Mon Sep 17 00:00:00 2001 From: monalisa Date: Wed, 8 Nov 2023 16:25:26 +0100 Subject: [PATCH] Do not allow empty descriptions for bundle template inputs --- libs/template/config.go | 7 +++++++ libs/template/config_test.go | 5 +++++ .../testdata/config-test-schema/invalid-test-schema.json | 8 ++++++++ .../template/testdata/config-test-schema/test-schema.json | 8 ++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 libs/template/testdata/config-test-schema/invalid-test-schema.json diff --git a/libs/template/config.go b/libs/template/config.go index 58b671fbfd..51283e035f 100644 --- a/libs/template/config.go +++ b/libs/template/config.go @@ -25,6 +25,13 @@ func newConfig(ctx context.Context, schemaPath string) (*config, error) { return nil, err } + // Validate that all properties have a description + for name, p := range schema.Properties { + if p.Description == "" { + return nil, fmt.Errorf("template property %s is missing a description", name) + } + } + // Do not allow template input variables that are not defined in the schema. schema.AdditionalProperties = false diff --git a/libs/template/config_test.go b/libs/template/config_test.go index 9a0a9931ff..69e7054fec 100644 --- a/libs/template/config_test.go +++ b/libs/template/config_test.go @@ -189,3 +189,8 @@ func TestAssignDefaultValuesWithTemplatedDefaults(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "my_file", c.values["string_val"]) } + +func TestTemplateSchemaErrorsWithEmptyDescription(t *testing.T) { + _, err := newConfig(context.Background(), "./testdata/config-test-schema/invalid-test-schema.json") + assert.EqualError(t, err, "template property property-without-description is missing a description") +} diff --git a/libs/template/testdata/config-test-schema/invalid-test-schema.json b/libs/template/testdata/config-test-schema/invalid-test-schema.json new file mode 100644 index 0000000000..53514057fa --- /dev/null +++ b/libs/template/testdata/config-test-schema/invalid-test-schema.json @@ -0,0 +1,8 @@ +{ + "properties": { + "property-without-description": { + "type": "integer", + "default": 123 + } + } +} diff --git a/libs/template/testdata/config-test-schema/test-schema.json b/libs/template/testdata/config-test-schema/test-schema.json index 6daf495951..10f8652f4c 100644 --- a/libs/template/testdata/config-test-schema/test-schema.json +++ b/libs/template/testdata/config-test-schema/test-schema.json @@ -2,16 +2,20 @@ "properties": { "int_val": { "type": "integer", + "description": "This is an integer value", "default": 123 }, "float_val": { - "type": "number" + "type": "number", + "description": "This is a float value" }, "bool_val": { - "type": "boolean" + "type": "boolean", + "description": "This is a boolean value" }, "string_val": { "type": "string", + "description": "This is a string value", "default": "{{template \"file_name\"}}" } }