@@ -24,9 +24,14 @@ import (
2424type ValidationMode string
2525
2626const (
27- // ValidationModeDefault is used for creating a workspace. It validates the
28- // final value used for a parameter.
29- ValidationModeDefault ValidationMode = ""
27+ // ValidationModeDefault is used for creating a workspace. It validates the final
28+ // value used for a parameter. Some allowances for invalid options are tolerated,
29+ // as unused options do not affect the final parameter value. The default value
30+ // is also ignored, assuming a value is provided.
31+ ValidationModeDefault ValidationMode = ""
32+ // ValidationModeTemplateImport tolerates empty values, as the value might not be
33+ // available at import. It does not tolerate an invalid default or invalid option
34+ // values.
3035 ValidationModeTemplateImport ValidationMode = "template-import"
3136)
3237
@@ -413,6 +418,14 @@ func (v *Parameter) Valid(input *string, mode ValidationMode) (string, diag.Diag
413418 value = v .Default
414419 }
415420
421+ // TODO: When empty values want to be rejected, uncomment this.
422+ // coder/coder should update to use template import mode first,
423+ // before this is uncommented.
424+ //if value == nil && mode == ValidationModeDefault {
425+ // var empty string
426+ // value = &empty
427+ //}
428+
416429 // optionType might differ from parameter.Type. This is ok, and parameter.Type
417430 // should be used for the value type, and optionType for options.
418431 optionType , v .FormType , err = ValidateFormType (v .Type , len (v .Option ), v .FormType )
0 commit comments