Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(recipe): support required attribute for variable #901

Merged
merged 1 commit into from
Dec 2, 2024
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
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 @@
}

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)
}

Check warning on line 922 in pkg/service/pipeline.go

View check run for this annotation

Codecov / codecov/patch

pkg/service/pipeline.go#L919-L922

Added lines #L919 - L922 were not covered by tests

// 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
Loading