Skip to content

Commit 0b585d7

Browse files
Fix #213 - Review DataInputSchema unmarshal function; review k8s annotations for Object type (#214)
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
1 parent 44c3948 commit 0b585d7

File tree

9 files changed

+100
-65
lines changed

9 files changed

+100
-65
lines changed

config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
failOnValidationErrors:
9191
type: boolean
9292
schema:
93-
type: object
93+
x-kubernetes-preserve-unknown-fields: true
9494
required:
9595
- failOnValidationErrors
9696
- schema
@@ -357,17 +357,15 @@ spec:
357357
event definitions.
358358
properties:
359359
contextAttributes:
360-
additionalProperties:
361-
type: object
362360
description: Add additional extension context attributes
363361
to the produced event.
364-
type: object
362+
x-kubernetes-preserve-unknown-fields: true
365363
data:
366364
description: |-
367365
If string type, an expression which selects parts of the states data output to become the data (payload)
368366
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
369367
of the event referenced by triggerEventRef.
370-
type: object
368+
x-kubernetes-preserve-unknown-fields: true
371369
invoke:
372370
default: sync
373371
description: Specifies if the function should be
@@ -397,11 +395,9 @@ spec:
397395
description: References a reusable function definition.
398396
properties:
399397
arguments:
400-
additionalProperties:
401-
type: object
402398
description: Arguments (inputs) to be passed to
403399
the referenced function
404-
type: object
400+
x-kubernetes-preserve-unknown-fields: true
405401
invoke:
406402
default: sync
407403
description: Specifies if the function should be
@@ -630,17 +626,15 @@ spec:
630626
reusable event definitions.
631627
properties:
632628
contextAttributes:
633-
additionalProperties:
634-
type: object
635629
description: Add additional extension context
636630
attributes to the produced event.
637-
type: object
631+
x-kubernetes-preserve-unknown-fields: true
638632
data:
639633
description: |-
640634
If string type, an expression which selects parts of the states data output to become the data (payload)
641635
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
642636
of the event referenced by triggerEventRef.
643-
type: object
637+
x-kubernetes-preserve-unknown-fields: true
644638
invoke:
645639
default: sync
646640
description: Specifies if the function should
@@ -671,11 +665,9 @@ spec:
671665
definition.
672666
properties:
673667
arguments:
674-
additionalProperties:
675-
type: object
676668
description: Arguments (inputs) to be passed
677669
to the referenced function
678-
type: object
670+
x-kubernetes-preserve-unknown-fields: true
679671
invoke:
680672
default: sync
681673
description: Specifies if the function should
@@ -875,17 +867,15 @@ spec:
875867
event definitions.
876868
properties:
877869
contextAttributes:
878-
additionalProperties:
879-
type: object
880870
description: Add additional extension context
881871
attributes to the produced event.
882-
type: object
872+
x-kubernetes-preserve-unknown-fields: true
883873
data:
884874
description: |-
885875
If string type, an expression which selects parts of the states data output to become the data (payload)
886876
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
887877
of the event referenced by triggerEventRef.
888-
type: object
878+
x-kubernetes-preserve-unknown-fields: true
889879
invoke:
890880
default: sync
891881
description: Specifies if the function should
@@ -915,11 +905,9 @@ spec:
915905
description: References a reusable function definition.
916906
properties:
917907
arguments:
918-
additionalProperties:
919-
type: object
920908
description: Arguments (inputs) to be passed to
921909
the referenced function
922-
type: object
910+
x-kubernetes-preserve-unknown-fields: true
923911
invoke:
924912
default: sync
925913
description: Specifies if the function should
@@ -1074,12 +1062,9 @@ spec:
10741062
data input.
10751063
properties:
10761064
data:
1077-
additionalProperties:
1078-
type: object
10791065
description: JSON object which can be set as state's data
10801066
input and can be manipulated via filter
1081-
minProperties: 1
1082-
type: object
1067+
x-kubernetes-preserve-unknown-fields: true
10831068
timeouts:
10841069
description: State specific timeouts
10851070
properties:
@@ -1189,17 +1174,15 @@ spec:
11891174
event definitions.
11901175
properties:
11911176
contextAttributes:
1192-
additionalProperties:
1193-
type: object
11941177
description: Add additional extension context
11951178
attributes to the produced event.
1196-
type: object
1179+
x-kubernetes-preserve-unknown-fields: true
11971180
data:
11981181
description: |-
11991182
If string type, an expression which selects parts of the states data output to become the data (payload)
12001183
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
12011184
of the event referenced by triggerEventRef.
1202-
type: object
1185+
x-kubernetes-preserve-unknown-fields: true
12031186
invoke:
12041187
default: sync
12051188
description: Specifies if the function should
@@ -1229,11 +1212,9 @@ spec:
12291212
description: References a reusable function definition.
12301213
properties:
12311214
arguments:
1232-
additionalProperties:
1233-
type: object
12341215
description: Arguments (inputs) to be passed to
12351216
the referenced function
1236-
type: object
1217+
x-kubernetes-preserve-unknown-fields: true
12371218
invoke:
12381219
default: sync
12391220
description: Specifies if the function should
@@ -1401,17 +1382,15 @@ spec:
14011382
reusable event definitions.
14021383
properties:
14031384
contextAttributes:
1404-
additionalProperties:
1405-
type: object
14061385
description: Add additional extension context
14071386
attributes to the produced event.
1408-
type: object
1387+
x-kubernetes-preserve-unknown-fields: true
14091388
data:
14101389
description: |-
14111390
If string type, an expression which selects parts of the states data output to become the data (payload)
14121391
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
14131392
of the event referenced by triggerEventRef.
1414-
type: object
1393+
x-kubernetes-preserve-unknown-fields: true
14151394
invoke:
14161395
default: sync
14171396
description: Specifies if the function should
@@ -1442,11 +1421,9 @@ spec:
14421421
definition.
14431422
properties:
14441423
arguments:
1445-
additionalProperties:
1446-
type: object
14471424
description: Arguments (inputs) to be passed
14481425
to the referenced function
1449-
type: object
1426+
x-kubernetes-preserve-unknown-fields: true
14501427
invoke:
14511428
default: sync
14521429
description: Specifies if the function should
@@ -1675,7 +1652,7 @@ spec:
16751652
description: |-
16761653
If string type, an expression which selects parts of the states data output to become the workflow data input of
16771654
continued execution. If object type, a custom object to become the workflow data input of the continued execution
1678-
type: object
1655+
x-kubernetes-preserve-unknown-fields: true
16791656
version:
16801657
description: Version of the workflow to continue
16811658
execution as.
@@ -1730,7 +1707,7 @@ spec:
17301707
description: |-
17311708
If String, expression which selects parts of the states data output to become the data of the produced event.
17321709
If object a custom object to become the data of produced event.
1733-
type: object
1710+
x-kubernetes-preserve-unknown-fields: true
17341711
eventRef:
17351712
description: Reference to a defined unique
17361713
event name in the events definition
@@ -1784,7 +1761,7 @@ spec:
17841761
description: |-
17851762
If String, expression which selects parts of the states data output to become the data of the produced event.
17861763
If object a custom object to become the data of produced event.
1787-
type: object
1764+
x-kubernetes-preserve-unknown-fields: true
17881765
eventRef:
17891766
description: Reference to a defined unique
17901767
event name in the events definition

model/action.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type FunctionRef struct {
8080
RefName string `json:"refName" validate:"required"`
8181
// Arguments (inputs) to be passed to the referenced function
8282
// +optional
83+
// +kubebuilder:validation:Schemaless
84+
// +kubebuilder:pruning:PreserveUnknownFields
8385
// TODO: validate it as required if function type is graphql
8486
Arguments map[string]Object `json:"arguments,omitempty"`
8587
// Used if function type is graphql. String containing a valid GraphQL selection set.

model/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ type Common struct {
2424
}
2525

2626
// Metadata information
27+
// +kubebuilder:pruning:PreserveUnknownFields
28+
// +kubebuilder:validation:Schemaless
2729
type Metadata map[string]Object

model/event.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ type EventRef struct {
106106
// of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
107107
// of the event referenced by triggerEventRef.
108108
// +optional
109+
// +kubebuilder:validation:Schemaless
110+
// +kubebuilder:pruning:PreserveUnknownFields
109111
Data *Object `json:"data,omitempty"`
110112
// Add additional extension context attributes to the produced event.
111113
// +optional
114+
// +kubebuilder:validation:Schemaless
115+
// +kubebuilder:pruning:PreserveUnknownFields
112116
ContextAttributes map[string]Object `json:"contextAttributes,omitempty"`
113117
// Specifies if the function should be invoked sync or async. Default is sync.
114118
// +kubebuilder:validation:Enum=async;sync

model/inject_state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
// InjectState used to inject static data into state data input.
2222
type InjectState struct {
2323
// JSON object which can be set as state's data input and can be manipulated via filter
24-
// +kubebuilder:validation:MinProperties=1
24+
// +kubebuilder:validation:Schemaless
25+
// +kubebuilder:pruning:PreserveUnknownFields
2526
Data map[string]Object `json:"data" validate:"required,min=1"`
2627
// State specific timeouts
2728
// +optional

model/object.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ const (
4444
// - Integer - holds int32 values, JSON marshal any number to float64 by default, during the marshaling process it is
4545
// parsed to int32
4646
//
47-
// +kubebuilder:validation:Type=object
47+
// +kubebuilder:pruning:PreserveUnknownFields
48+
// +kubebuilder:validation:Schemaless
4849
type Object struct {
49-
Type Type `json:"type,inline"`
50-
StringValue string `json:"strVal,inline"`
51-
IntValue int32 `json:"intVal,inline"`
52-
FloatValue float64
53-
MapValue map[string]Object
54-
SliceValue []Object
55-
BoolValue bool `json:"boolValue,inline"`
50+
Type Type `json:"type,inline"`
51+
StringValue string `json:"strVal,inline"`
52+
IntValue int32 `json:"intVal,inline"`
53+
FloatValue float64 `json:"floatVal,inline"`
54+
MapValue map[string]Object `json:"mapVal,inline"`
55+
SliceValue []Object `json:"sliceVal,inline"`
56+
BoolValue bool `json:"boolValue,inline"`
5657
}
5758

5859
// UnmarshalJSON implements json.Unmarshaler

model/workflow.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ type BaseWorkflow struct {
154154
// +optional
155155
KeepActive bool `json:"keepActive,omitempty"`
156156
// Metadata custom information shared with the runtime.
157+
// +optional
157158
// +kubebuilder:validation:Schemaless
158159
// +kubebuilder:pruning:PreserveUnknownFields
159-
// +optional
160160
Metadata Metadata `json:"metadata,omitempty"`
161161
// AutoRetries If set to true, actions should automatically be retried on unchecked errors. Default is false
162162
// +optional
@@ -471,6 +471,8 @@ type ContinueAs struct {
471471
// If string type, an expression which selects parts of the states data output to become the workflow data input of
472472
// continued execution. If object type, a custom object to become the workflow data input of the continued execution
473473
// +optional
474+
// +kubebuilder:validation:Schemaless
475+
// +kubebuilder:pruning:PreserveUnknownFields
474476
Data Object `json:"data,omitempty"`
475477
// WorkflowExecTimeout Workflow execution timeout to be used by the workflow continuing execution.
476478
// Overwrites any specific settings set by that workflow
@@ -495,6 +497,8 @@ type ProduceEvent struct {
495497
// If String, expression which selects parts of the states data output to become the data of the produced event.
496498
// If object a custom object to become the data of produced event.
497499
// +optional
500+
// +kubebuilder:validation:Schemaless
501+
// +kubebuilder:pruning:PreserveUnknownFields
498502
Data Object `json:"data,omitempty"`
499503
// Add additional event extension context attributes.
500504
// +optional
@@ -513,6 +517,8 @@ type StateDataFilter struct {
513517
// +builder-gen:new-call=ApplyDefault
514518
type DataInputSchema struct {
515519
// +kubebuilder:validation:Required
520+
// +kubebuilder:validation:Schemaless
521+
// +kubebuilder:pruning:PreserveUnknownFields
516522
Schema *Object `json:"schema" validate:"required"`
517523
// +kubebuilder:validation:Required
518524
FailOnValidationErrors bool `json:"failOnValidationErrors"`
@@ -557,7 +563,7 @@ func (d *DataInputSchema) UnmarshalJSON(data []byte) error {
557563
}
558564

559565
d.Schema = new(Object)
560-
return util.UnmarshalObjectOrFile("schema", data, &d.Schema)
566+
return util.UnmarshalObject("schema", data, &d.Schema)
561567
}
562568

563569
// ApplyDefault set the default values for Data Input Schema

parser/parser_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,6 @@ func TestFromFile(t *testing.T) {
581581
assert.Equal(t, "SendTextForHighPriority", w.States[10].SwitchState.DefaultCondition.Transition.NextState)
582582
assert.Equal(t, true, w.States[10].End.Terminate)
583583
},
584-
}, {
585-
"./testdata/workflows/dataInputSchemaValidation.yaml", func(t *testing.T, w *model.Workflow) {
586-
assert.NotNil(t, w.DataInputSchema)
587-
expected := model.DataInputSchema{}
588-
data, err := util.LoadExternalResource("file://testdata/datainputschema.json")
589-
err1 := util.UnmarshalObject("schema", data, &expected.Schema)
590-
assert.Nil(t, err)
591-
assert.Nil(t, err1)
592-
assert.Equal(t, expected.Schema, w.DataInputSchema.Schema)
593-
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
594-
},
595584
}, {
596585
"./testdata/workflows/dataInputSchemaObject.json", func(t *testing.T, w *model.Workflow) {
597586
assert.NotNil(t, w.DataInputSchema)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy