-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add validator with context to validate the refs (functions, events, retries, etc) exists Signed-off-by: André R. de Miranda <[email protected]> * Valid errors exist and change unique_struct to unique Signed-off-by: André R. de Miranda <[email protected]> * Fix lint Signed-off-by: André R. de Miranda <[email protected]> * Add transition and compensation validations. Refactor state exists Signed-off-by: André R. de Miranda <[email protected]> * Json ignore field Signed-off-by: André R. de Miranda <[email protected]> * Fix tests Signed-off-by: André R. de Miranda <[email protected]> * Add validations: OnEvent.EventRefs, EventCondition.EventRef, and FunctionType Signed-off-by: André R. de Miranda <[email protected]> * Fix tests Signed-off-by: André R. de Miranda <[email protected]> * Replace oneof to oneofkind, and improve the error message Signed-off-by: André R. de Miranda <[email protected]> * Validation refactoring for each struct to have its test case. Revision suggestions Signed-off-by: André R. de Miranda <[email protected]> * Add validation oneofkind validation auth struct Signed-off-by: André R. de Miranda <[email protected]> * Add new tests and improve error description Signed-off-by: André R. de Miranda <[email protected]> * Add new unit tests, refactor intstr validator, and add new validation description Signed-off-by: André R. de Miranda <[email protected]> * Remove reflection from validation Signed-off-by: André R. de Miranda <[email protected]> * Remove commented code Signed-off-by: André R. de Miranda <[email protected]> --------- Signed-off-by: André R. de Miranda <[email protected]>
- Loading branch information
1 parent
5110906
commit 4afc5f3
Showing
70 changed files
with
3,645 additions
and
1,625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2022 The Serverless Workflow Specification Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package model | ||
|
||
import "testing" | ||
|
||
func TestActionDataFilterStructLevelValidation(t *testing.T) { | ||
testCases := []ValidationCase{} | ||
StructLevelValidationCtx(t, testCases) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2022 The Serverless Workflow Specification Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package model | ||
|
||
import ( | ||
validator "github.com/go-playground/validator/v10" | ||
|
||
val "github.com/serverlessworkflow/sdk-go/v2/validator" | ||
) | ||
|
||
func init() { | ||
val.GetValidator().RegisterStructValidationCtx(ValidationWrap(actionStructLevelValidationCtx), Action{}) | ||
val.GetValidator().RegisterStructValidationCtx(ValidationWrap(functionRefStructLevelValidation), FunctionRef{}) | ||
} | ||
|
||
func actionStructLevelValidationCtx(ctx ValidatorContext, structLevel validator.StructLevel) { | ||
action := structLevel.Current().Interface().(Action) | ||
|
||
if action.FunctionRef == nil && action.EventRef == nil && action.SubFlowRef == nil { | ||
structLevel.ReportError(action.FunctionRef, "FunctionRef", "FunctionRef", "required_without", "") | ||
return | ||
} | ||
|
||
values := []bool{ | ||
action.FunctionRef != nil, | ||
action.EventRef != nil, | ||
action.SubFlowRef != nil, | ||
} | ||
|
||
if validationNotExclusiveParamters(values) { | ||
structLevel.ReportError(action.FunctionRef, "FunctionRef", "FunctionRef", val.TagExclusive, "") | ||
structLevel.ReportError(action.EventRef, "EventRef", "EventRef", val.TagExclusive, "") | ||
structLevel.ReportError(action.SubFlowRef, "SubFlowRef", "SubFlowRef", val.TagExclusive, "") | ||
} | ||
|
||
if action.RetryRef != "" && !ctx.ExistRetry(action.RetryRef) { | ||
structLevel.ReportError(action.RetryRef, "RetryRef", "RetryRef", val.TagExists, "") | ||
} | ||
} | ||
|
||
func functionRefStructLevelValidation(ctx ValidatorContext, structLevel validator.StructLevel) { | ||
functionRef := structLevel.Current().Interface().(FunctionRef) | ||
if !ctx.ExistFunction(functionRef.RefName) { | ||
structLevel.ReportError(functionRef.RefName, "RefName", "RefName", val.TagExists, functionRef.RefName) | ||
} | ||
} |
Oops, something went wrong.