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

Removed "required" tag from failOnValidationErrors #192

Merged
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
3 changes: 2 additions & 1 deletion model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ type DataInputSchema struct {
// +kubebuilder:validation:Required
Schema string `json:"schema" validate:"required"`
// +kubebuilder:validation:Required
FailOnValidationErrors bool `json:"failOnValidationErrors" validate:"required"`
FailOnValidationErrors bool `json:"failOnValidationErrors"`
// FailOnValidationErrors bool `json:"failOnValidationErrors" validate:"required"`
}

type dataInputSchemaUnmarshal DataInputSchema
Expand Down
33 changes: 33 additions & 0 deletions model/workflow_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,39 @@ Key: 'Workflow.States[3].BaseState.Transition.NextState' Error:Field validation
StructLevelValidationCtx(t, testCases)
}

func TestDataInputSchemaStructLevelValidation(t *testing.T) {
baseWorkflow := buildWorkflow()

operationState := buildOperationState(baseWorkflow, "start state")
buildEndByState(operationState, true, false)
action1 := buildActionByOperationState(operationState, "action 1")
buildFunctionRef(baseWorkflow, action1, "function 1")

testCases := []ValidationCase{
{
Desp: "empty DataInputSchema",
Model: func() Workflow {
model := baseWorkflow.DeepCopy()
model.DataInputSchema = &DataInputSchema{}
return *model
},
Err: `workflow.dataInputSchema.schema is required`,
},
{
Desp: "filled Schema, default failOnValidationErrors",
Model: func() Workflow {
model := baseWorkflow.DeepCopy()
model.DataInputSchema = &DataInputSchema{
Schema: "sample schema",
}
return *model
},
},
}

StructLevelValidationCtx(t, testCases)
}

func TestSecretsStructLevelValidation(t *testing.T) {
baseWorkflow := buildWorkflow()

Expand Down
7 changes: 7 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,13 @@ func TestFromFile(t *testing.T) {
assert.Equal(t, "SendTextForHighPriority", w.States[10].SwitchState.DefaultCondition.Transition.NextState)
assert.Equal(t, true, w.States[10].End.Terminate)
},
}, {
"./testdata/workflows/dataInputSchemaValidation.yaml", func(t *testing.T, w *model.Workflow) {
assert.NotNil(t, w.DataInputSchema)

assert.Equal(t, "sample schema", w.DataInputSchema.Schema)
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
},
},
}
for _, file := range files {
Expand Down
28 changes: 28 additions & 0 deletions parser/testdata/workflows/dataInputSchemaValidation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 The Serverless Workflow Specification Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

id: Valid DataInputSchema
version: '1.0'
specVersion: '0.8'
start: Start
dataInputSchema:
failOnValidationErrors: false
schema: "sample schema"
states:
- name: Start
type: inject
data:
done: true
end:
terminate: true