Skip to content

Fix #213 - Review DataInputSchema unmarshal function; review k8s annotations for Object type #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 20 additions & 43 deletions config/crd/bases/serverlessworkflow.io_serverlessworkflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
failOnValidationErrors:
type: boolean
schema:
type: object
x-kubernetes-preserve-unknown-fields: true
required:
- failOnValidationErrors
- schema
Expand Down Expand Up @@ -357,17 +357,15 @@ spec:
event definitions.
properties:
contextAttributes:
additionalProperties:
type: object
description: Add additional extension context attributes
to the produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
data:
description: |-
If string type, an expression which selects parts of the states data output to become the data (payload)
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
of the event referenced by triggerEventRef.
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should be
Expand Down Expand Up @@ -397,11 +395,9 @@ spec:
description: References a reusable function definition.
properties:
arguments:
additionalProperties:
type: object
description: Arguments (inputs) to be passed to
the referenced function
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should be
Expand Down Expand Up @@ -630,17 +626,15 @@ spec:
reusable event definitions.
properties:
contextAttributes:
additionalProperties:
type: object
description: Add additional extension context
attributes to the produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
data:
description: |-
If string type, an expression which selects parts of the states data output to become the data (payload)
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
of the event referenced by triggerEventRef.
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -671,11 +665,9 @@ spec:
definition.
properties:
arguments:
additionalProperties:
type: object
description: Arguments (inputs) to be passed
to the referenced function
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -875,17 +867,15 @@ spec:
event definitions.
properties:
contextAttributes:
additionalProperties:
type: object
description: Add additional extension context
attributes to the produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
data:
description: |-
If string type, an expression which selects parts of the states data output to become the data (payload)
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
of the event referenced by triggerEventRef.
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -915,11 +905,9 @@ spec:
description: References a reusable function definition.
properties:
arguments:
additionalProperties:
type: object
description: Arguments (inputs) to be passed to
the referenced function
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -1074,12 +1062,9 @@ spec:
data input.
properties:
data:
additionalProperties:
type: object
description: JSON object which can be set as state's data
input and can be manipulated via filter
minProperties: 1
type: object
x-kubernetes-preserve-unknown-fields: true
timeouts:
description: State specific timeouts
properties:
Expand Down Expand Up @@ -1189,17 +1174,15 @@ spec:
event definitions.
properties:
contextAttributes:
additionalProperties:
type: object
description: Add additional extension context
attributes to the produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
data:
description: |-
If string type, an expression which selects parts of the states data output to become the data (payload)
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
of the event referenced by triggerEventRef.
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -1229,11 +1212,9 @@ spec:
description: References a reusable function definition.
properties:
arguments:
additionalProperties:
type: object
description: Arguments (inputs) to be passed to
the referenced function
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -1401,17 +1382,15 @@ spec:
reusable event definitions.
properties:
contextAttributes:
additionalProperties:
type: object
description: Add additional extension context
attributes to the produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
data:
description: |-
If string type, an expression which selects parts of the states data output to become the data (payload)
of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
of the event referenced by triggerEventRef.
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -1442,11 +1421,9 @@ spec:
definition.
properties:
arguments:
additionalProperties:
type: object
description: Arguments (inputs) to be passed
to the referenced function
type: object
x-kubernetes-preserve-unknown-fields: true
invoke:
default: sync
description: Specifies if the function should
Expand Down Expand Up @@ -1675,7 +1652,7 @@ spec:
description: |-
If string type, an expression which selects parts of the states data output to become the workflow data input of
continued execution. If object type, a custom object to become the workflow data input of the continued execution
type: object
x-kubernetes-preserve-unknown-fields: true
version:
description: Version of the workflow to continue
execution as.
Expand Down Expand Up @@ -1730,7 +1707,7 @@ spec:
description: |-
If String, expression which selects parts of the states data output to become the data of the produced event.
If object a custom object to become the data of produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
eventRef:
description: Reference to a defined unique
event name in the events definition
Expand Down Expand Up @@ -1784,7 +1761,7 @@ spec:
description: |-
If String, expression which selects parts of the states data output to become the data of the produced event.
If object a custom object to become the data of produced event.
type: object
x-kubernetes-preserve-unknown-fields: true
eventRef:
description: Reference to a defined unique
event name in the events definition
Expand Down
2 changes: 2 additions & 0 deletions model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type FunctionRef struct {
RefName string `json:"refName" validate:"required"`
// Arguments (inputs) to be passed to the referenced function
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// TODO: validate it as required if function type is graphql
Arguments map[string]Object `json:"arguments,omitempty"`
// Used if function type is graphql. String containing a valid GraphQL selection set.
Expand Down
2 changes: 2 additions & 0 deletions model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ type Common struct {
}

// Metadata information
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
type Metadata map[string]Object
4 changes: 4 additions & 0 deletions model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ type EventRef struct {
// of the event referenced by triggerEventRef. If object type, a custom object to become the data (payload)
// of the event referenced by triggerEventRef.
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Data *Object `json:"data,omitempty"`
// Add additional extension context attributes to the produced event.
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
ContextAttributes map[string]Object `json:"contextAttributes,omitempty"`
// Specifies if the function should be invoked sync or async. Default is sync.
// +kubebuilder:validation:Enum=async;sync
Expand Down
3 changes: 2 additions & 1 deletion model/inject_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
// InjectState used to inject static data into state data input.
type InjectState struct {
// JSON object which can be set as state's data input and can be manipulated via filter
// +kubebuilder:validation:MinProperties=1
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Data map[string]Object `json:"data" validate:"required,min=1"`
// State specific timeouts
// +optional
Expand Down
17 changes: 9 additions & 8 deletions model/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ const (
// - Integer - holds int32 values, JSON marshal any number to float64 by default, during the marshaling process it is
// parsed to int32
//
// +kubebuilder:validation:Type=object
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
type Object struct {
Type Type `json:"type,inline"`
StringValue string `json:"strVal,inline"`
IntValue int32 `json:"intVal,inline"`
FloatValue float64
MapValue map[string]Object
SliceValue []Object
BoolValue bool `json:"boolValue,inline"`
Type Type `json:"type,inline"`
StringValue string `json:"strVal,inline"`
IntValue int32 `json:"intVal,inline"`
FloatValue float64 `json:"floatVal,inline"`
MapValue map[string]Object `json:"mapVal,inline"`
SliceValue []Object `json:"sliceVal,inline"`
BoolValue bool `json:"boolValue,inline"`
}

// UnmarshalJSON implements json.Unmarshaler
Expand Down
10 changes: 8 additions & 2 deletions model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ type BaseWorkflow struct {
// +optional
KeepActive bool `json:"keepActive,omitempty"`
// Metadata custom information shared with the runtime.
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Metadata Metadata `json:"metadata,omitempty"`
// AutoRetries If set to true, actions should automatically be retried on unchecked errors. Default is false
// +optional
Expand Down Expand Up @@ -471,6 +471,8 @@ type ContinueAs struct {
// If string type, an expression which selects parts of the states data output to become the workflow data input of
// continued execution. If object type, a custom object to become the workflow data input of the continued execution
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Data Object `json:"data,omitempty"`
// WorkflowExecTimeout Workflow execution timeout to be used by the workflow continuing execution.
// Overwrites any specific settings set by that workflow
Expand All @@ -495,6 +497,8 @@ type ProduceEvent struct {
// If String, expression which selects parts of the states data output to become the data of the produced event.
// If object a custom object to become the data of produced event.
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Data Object `json:"data,omitempty"`
// Add additional event extension context attributes.
// +optional
Expand All @@ -513,6 +517,8 @@ type StateDataFilter struct {
// +builder-gen:new-call=ApplyDefault
type DataInputSchema struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
Schema *Object `json:"schema" validate:"required"`
// +kubebuilder:validation:Required
FailOnValidationErrors bool `json:"failOnValidationErrors"`
Expand Down Expand Up @@ -557,7 +563,7 @@ func (d *DataInputSchema) UnmarshalJSON(data []byte) error {
}

d.Schema = new(Object)
return util.UnmarshalObjectOrFile("schema", data, &d.Schema)
return util.UnmarshalObject("schema", data, &d.Schema)
}

// ApplyDefault set the default values for Data Input Schema
Expand Down
11 changes: 0 additions & 11 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,6 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it better to keep it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this validation is not valid anymore since Schema is not loading the external file to the attribute.

expected := model.DataInputSchema{}
data, err := util.LoadExternalResource("file://testdata/datainputschema.json")
err1 := util.UnmarshalObject("schema", data, &expected.Schema)
assert.Nil(t, err)
assert.Nil(t, err1)
assert.Equal(t, expected.Schema, w.DataInputSchema.Schema)
assert.Equal(t, false, w.DataInputSchema.FailOnValidationErrors)
},
}, {
"./testdata/workflows/dataInputSchemaObject.json", func(t *testing.T, w *model.Workflow) {
assert.NotNil(t, w.DataInputSchema)
Expand Down
Loading
Loading