Skip to content

Commit d4d4b74

Browse files
Do not allow empty descriptions for bundle template inputs (#967)
## Changes We rely on the descriptions to render the prompts to a user. Thus we should not allow empty descriptions here. Note, both mlops stacks and the default-python template have descriptions for all their properties so this should not be an issue. ## Tests Unit test
1 parent b72f2a9 commit d4d4b74

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

libs/template/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func newConfig(ctx context.Context, schemaPath string) (*config, error) {
2525
return nil, err
2626
}
2727

28+
// Validate that all properties have a description
29+
for name, p := range schema.Properties {
30+
if p.Description == "" {
31+
return nil, fmt.Errorf("template property %s is missing a description", name)
32+
}
33+
}
34+
2835
// Do not allow template input variables that are not defined in the schema.
2936
schema.AdditionalProperties = false
3037

libs/template/config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,8 @@ func TestAssignDefaultValuesWithTemplatedDefaults(t *testing.T) {
189189
assert.NoError(t, err)
190190
assert.Equal(t, "my_file", c.values["string_val"])
191191
}
192+
193+
func TestTemplateSchemaErrorsWithEmptyDescription(t *testing.T) {
194+
_, err := newConfig(context.Background(), "./testdata/config-test-schema/invalid-test-schema.json")
195+
assert.EqualError(t, err, "template property property-without-description is missing a description")
196+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"properties": {
3+
"property-without-description": {
4+
"type": "integer",
5+
"default": 123
6+
}
7+
}
8+
}

libs/template/testdata/config-test-schema/test-schema.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
"properties": {
33
"int_val": {
44
"type": "integer",
5+
"description": "This is an integer value",
56
"default": 123
67
},
78
"float_val": {
8-
"type": "number"
9+
"type": "number",
10+
"description": "This is a float value"
911
},
1012
"bool_val": {
11-
"type": "boolean"
13+
"type": "boolean",
14+
"description": "This is a boolean value"
1215
},
1316
"string_val": {
1417
"type": "string",
18+
"description": "This is a string value",
1519
"default": "{{template \"file_name\"}}"
1620
}
1721
}

0 commit comments

Comments
 (0)