Skip to content

Commit

Permalink
feat(recipe): support required attribute for variable (#901)
Browse files Browse the repository at this point in the history
Because

- we want users to explicitly define which variables are required.

This commit

- adds support for the required attribute in variables.
  • Loading branch information
donch1989 authored Dec 2, 2024
1 parent 5089397 commit da7f0e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/datamodel/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ type Variable struct {
Listen []string `json:"listen,omitempty" yaml:"listen,omitempty"`
Default any `json:"default,omitempty" yaml:"default,omitempty"`
InstillUIOrder int32 `json:"instillUiOrder,omitempty" yaml:"instill-ui-order,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
}

type Output struct {
Expand Down
8 changes: 7 additions & 1 deletion pkg/service/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,14 @@ func (s *service) preTriggerPipeline(ctx context.Context, ns resource.Namespace,
}

if v == nil {
// If the field is required but no value is provided, return an error.
if r.Variable[k].Required {
return fmt.Errorf("missing required variable: %s", k)
}

// If the field has no value and no default value is specified,
// represent it as null, we treat null as missing value
// represent it as null. A null value indicates that the field
// is missing and should be handled as such by components.
if d, ok := defaultValueMap[k]; !ok || d == nil {
variable[k] = data.NewNull()
continue
Expand Down

0 comments on commit da7f0e9

Please sign in to comment.