From 1b942581ee7f9c765d5817ee11f9d4b24815554f Mon Sep 17 00:00:00 2001 From: "Chang, Hui-Tang" Date: Mon, 2 Dec 2024 21:38:57 +0800 Subject: [PATCH] feat(recipe): support `required` attribute for variable --- pkg/datamodel/datamodel.go | 1 + pkg/service/pipeline.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/datamodel/datamodel.go b/pkg/datamodel/datamodel.go index 83556efee..eb912d883 100644 --- a/pkg/datamodel/datamodel.go +++ b/pkg/datamodel/datamodel.go @@ -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 { diff --git a/pkg/service/pipeline.go b/pkg/service/pipeline.go index f75bd8372..f2882a24d 100644 --- a/pkg/service/pipeline.go +++ b/pkg/service/pipeline.go @@ -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