Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/template/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions libs/template/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"properties": {
"property-without-description": {
"type": "integer",
"default": 123
}
}
}
8 changes: 6 additions & 2 deletions libs/template/testdata/config-test-schema/test-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}}"
}
}
Expand Down