Skip to content

Commit

Permalink
Removed "required" tag from failOnValidationErrors
Browse files Browse the repository at this point in the history
Signed-off-by: Venera <[email protected]>
  • Loading branch information
venera-program committed Oct 3, 2023
1 parent f50885c commit 7b24089
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
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

0 comments on commit 7b24089

Please sign in to comment.