Skip to content

Commit 78b1c06

Browse files
Removed "required" tag from failOnValidationErrors (#192)
Signed-off-by: Venera <31911811+venera-program@users.noreply.github.com>
1 parent f50885c commit 78b1c06

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

model/workflow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ type DataInputSchema struct {
507507
// +kubebuilder:validation:Required
508508
Schema string `json:"schema" validate:"required"`
509509
// +kubebuilder:validation:Required
510-
FailOnValidationErrors bool `json:"failOnValidationErrors" validate:"required"`
510+
FailOnValidationErrors bool `json:"failOnValidationErrors"`
511+
// FailOnValidationErrors bool `json:"failOnValidationErrors" validate:"required"`
511512
}
512513

513514
type dataInputSchemaUnmarshal DataInputSchema

model/workflow_validator_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,39 @@ Key: 'Workflow.States[3].BaseState.Transition.NextState' Error:Field validation
417417
StructLevelValidationCtx(t, testCases)
418418
}
419419

420+
func TestDataInputSchemaStructLevelValidation(t *testing.T) {
421+
baseWorkflow := buildWorkflow()
422+
423+
operationState := buildOperationState(baseWorkflow, "start state")
424+
buildEndByState(operationState, true, false)
425+
action1 := buildActionByOperationState(operationState, "action 1")
426+
buildFunctionRef(baseWorkflow, action1, "function 1")
427+
428+
testCases := []ValidationCase{
429+
{
430+
Desp: "empty DataInputSchema",
431+
Model: func() Workflow {
432+
model := baseWorkflow.DeepCopy()
433+
model.DataInputSchema = &DataInputSchema{}
434+
return *model
435+
},
436+
Err: `workflow.dataInputSchema.schema is required`,
437+
},
438+
{
439+
Desp: "filled Schema, default failOnValidationErrors",
440+
Model: func() Workflow {
441+
model := baseWorkflow.DeepCopy()
442+
model.DataInputSchema = &DataInputSchema{
443+
Schema: "sample schema",
444+
}
445+
return *model
446+
},
447+
},
448+
}
449+
450+
StructLevelValidationCtx(t, testCases)
451+
}
452+
420453
func TestSecretsStructLevelValidation(t *testing.T) {
421454
baseWorkflow := buildWorkflow()
422455

parser/parser_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ func TestFromFile(t *testing.T) {
579579
assert.Equal(t, "SendTextForHighPriority", w.States[10].SwitchState.DefaultCondition.Transition.NextState)
580580
assert.Equal(t, true, w.States[10].End.Terminate)
581581
},
582+
}, {
583+
"./testdata/workflows/dataInputSchemaValidation.yaml", func(t *testing.T, w *model.Workflow) {
584+
assert.NotNil(t, w.DataInputSchema)
585+
586+
assert.Equal(t, "sample schema", w.DataInputSchema.Schema)
587+
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
588+
},
582589
},
583590
}
584591
for _, file := range files {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2023 The Serverless Workflow Specification Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
id: Valid DataInputSchema
16+
version: '1.0'
17+
specVersion: '0.8'
18+
start: Start
19+
dataInputSchema:
20+
failOnValidationErrors: false
21+
schema: "sample schema"
22+
states:
23+
- name: Start
24+
type: inject
25+
data:
26+
done: true
27+
end:
28+
terminate: true

0 commit comments

Comments
 (0)