Skip to content

Commit 6894631

Browse files
committed
use dataInputSchema.schema as pointer
Signed-off-by: Spolti <[email protected]>
1 parent 0ba22a1 commit 6894631

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

model/workflow.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ type StateDataFilter struct {
507507
// DataInputSchema Used to validate the workflow data input against a defined JSON Schema
508508
type DataInputSchema struct {
509509
// +kubebuilder:validation:Required
510-
Schema Object `json:"schema" validate:"required"`
510+
Schema *Object `json:"schema" validate:"required"`
511511
// +kubebuilder:validation:Required
512512
FailOnValidationErrors bool `json:"failOnValidationErrors"`
513513
}
@@ -519,7 +519,8 @@ func (d *DataInputSchema) UnmarshalJSON(data []byte) error {
519519
d.ApplyDefault()
520520
if data[0] == '"' && len(data) > 0 {
521521
replaced := bytes.Replace(data, []byte(`"`), []byte(``), -1)
522-
d.Schema = FromString(string(replaced))
522+
repp := FromString(string(replaced))
523+
d.Schema = &repp
523524
} else {
524525
return util.UnmarshalObject("dataInputSchema", data, (*dataInputSchemaUnmarshal)(d))
525526
}

model/workflow_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ func TestTransitionUnmarshalJSON(t *testing.T) {
496496
}
497497

498498
func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
499+
500+
schemaName := FromString("schema name")
501+
499502
type testCase struct {
500503
desp string
501504
data string
@@ -508,7 +511,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
508511
desp: "string success",
509512
data: `"schema name"`,
510513
expect: DataInputSchema{
511-
Schema: FromString("schema name"),
514+
Schema: &schemaName,
512515
FailOnValidationErrors: true,
513516
},
514517
err: ``,
@@ -517,7 +520,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
517520
desp: `object success`,
518521
data: `{"schema": "schema name"}`,
519522
expect: DataInputSchema{
520-
Schema: FromString("schema name"),
523+
Schema: &schemaName,
521524
FailOnValidationErrors: true,
522525
},
523526
err: ``,
@@ -526,7 +529,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
526529
desp: `object fail`,
527530
data: `{"schema": "schema name}`,
528531
expect: DataInputSchema{
529-
Schema: FromString("schema name"),
532+
Schema: &schemaName,
530533
FailOnValidationErrors: true,
531534
},
532535
err: `unexpected end of JSON input`,

model/workflow_validator_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,26 +425,28 @@ func TestDataInputSchemaStructLevelValidation(t *testing.T) {
425425
action1 := buildActionByOperationState(operationState, "action 1")
426426
buildFunctionRef(baseWorkflow, action1, "function 1")
427427

428+
sampleSchema := FromString("sample schema")
429+
428430
testCases := []ValidationCase{
429431
// TODO Empty DataInoputSchema will have this instead nil:
430432
// &{Schema:{Type:0 StringValue: IntValue:0 FloatValue:0 MapValue:map[] SliceValue:[] BoolValue:false}
431433
// We can, make Schema pointer, or, find a way to make all fields from Object as pointer.
432434
// Using Schema: FromNull does have the same effect than just not set it.
433-
//{
434-
// Desp: "empty DataInputSchema",
435-
// Model: func() Workflow {
436-
// model := baseWorkflow.DeepCopy()
437-
// model.DataInputSchema = &DataInputSchema{}
438-
// return *model
439-
// },
440-
// Err: `workflow.dataInputSchema.schema is required`,
441-
//},
435+
{
436+
Desp: "empty DataInputSchema",
437+
Model: func() Workflow {
438+
model := baseWorkflow.DeepCopy()
439+
model.DataInputSchema = &DataInputSchema{}
440+
return *model
441+
},
442+
Err: `workflow.dataInputSchema.schema is required`,
443+
},
442444
{
443445
Desp: "filled Schema, default failOnValidationErrors",
444446
Model: func() Workflow {
445447
model := baseWorkflow.DeepCopy()
446448
model.DataInputSchema = &DataInputSchema{
447-
Schema: FromString("sample schema"),
449+
Schema: &sampleSchema,
448450
}
449451
return *model
450452
},

model/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/parser_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ func TestFromFile(t *testing.T) {
583583
}, {
584584
"./testdata/workflows/dataInputSchemaValidation.yaml", func(t *testing.T, w *model.Workflow) {
585585
assert.NotNil(t, w.DataInputSchema)
586-
587-
assert.Equal(t, model.FromString("sample schema"), w.DataInputSchema.Schema)
586+
expected := model.FromString("sample schema")
587+
assert.Equal(t, &expected, w.DataInputSchema.Schema)
588588
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
589589
},
590590
}, {
@@ -597,7 +597,7 @@ func TestFromFile(t *testing.T) {
597597
&expected)
598598
fmt.Printf("err: %s\n", err)
599599
fmt.Printf("schema: %+v\n", expected)
600-
assert.Equal(t, expected, w.DataInputSchema.Schema)
600+
assert.Equal(t, &expected, w.DataInputSchema.Schema)
601601
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
602602
},
603603
},

0 commit comments

Comments
 (0)