Skip to content

Commit 4bfd879

Browse files
committed
use dataInputSchema.schema as pointer
Signed-off-by: Spolti <filippespolti@gmail.com>
1 parent 45ad34a commit 4bfd879

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
@@ -512,7 +512,7 @@ type StateDataFilter struct {
512512
// +builder-gen:new-call=ApplyDefault
513513
type DataInputSchema struct {
514514
// +kubebuilder:validation:Required
515-
Schema Object `json:"schema" validate:"required"`
515+
Schema *Object `json:"schema" validate:"required"`
516516
// +kubebuilder:validation:Required
517517
FailOnValidationErrors bool `json:"failOnValidationErrors"`
518518
}
@@ -524,7 +524,8 @@ func (d *DataInputSchema) UnmarshalJSON(data []byte) error {
524524
d.ApplyDefault()
525525
if data[0] == '"' && len(data) > 0 {
526526
replaced := bytes.Replace(data, []byte(`"`), []byte(``), -1)
527-
d.Schema = FromString(string(replaced))
527+
repp := FromString(string(replaced))
528+
d.Schema = &repp
528529
} else {
529530
return util.UnmarshalObject("dataInputSchema", data, (*dataInputSchemaUnmarshal)(d))
530531
}

model/workflow_test.go

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

500500
func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
501+
502+
schemaName := FromString("schema name")
503+
501504
type testCase struct {
502505
desp string
503506
data string
@@ -510,7 +513,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
510513
desp: "string success",
511514
data: `"schema name"`,
512515
expect: DataInputSchema{
513-
Schema: FromString("schema name"),
516+
Schema: &schemaName,
514517
FailOnValidationErrors: true,
515518
},
516519
err: ``,
@@ -519,7 +522,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
519522
desp: `object success`,
520523
data: `{"schema": "schema name"}`,
521524
expect: DataInputSchema{
522-
Schema: FromString("schema name"),
525+
Schema: &schemaName,
523526
FailOnValidationErrors: true,
524527
},
525528
err: ``,
@@ -528,7 +531,7 @@ func TestDataInputSchemaUnmarshalJSON(t *testing.T) {
528531
desp: `object fail`,
529532
data: `{"schema": "schema name}`,
530533
expect: DataInputSchema{
531-
Schema: FromString("schema name"),
534+
Schema: &schemaName,
532535
FailOnValidationErrors: true,
533536
},
534537
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)