ondc-code-generator 0.7.0 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/bin/cli-tool.d.ts +70 -0
- package/dist/bin/cli-tool.js +310 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +112 -0
- package/dist/constants/syntax.js +26 -0
- package/dist/generator/config-compiler.d.ts +3 -2
- package/dist/generator/config-compiler.js +18 -6
- package/dist/generator/generators/{golang → go}/go-ast.js +2 -2
- package/dist/generator/generators/go/go-generator.d.ts +13 -0
- package/dist/generator/generators/go/go-generator.js +322 -0
- package/dist/generator/generators/go/templates/api-tests.mustache +65 -0
- package/dist/generator/generators/go/templates/go-mod.mustache +3 -0
- package/dist/generator/generators/go/templates/index.mustache +34 -0
- package/dist/generator/generators/go/templates/json-normalizer.mustache +155 -0
- package/dist/generator/generators/go/templates/json-path-utils.mustache +63 -0
- package/dist/generator/generators/go/templates/storage-templates/api-save-utils.mustache +84 -0
- package/dist/generator/generators/go/templates/storage-templates/api-save.mustache +44 -0
- package/dist/generator/generators/go/templates/storage-templates/index.mustache +72 -0
- package/dist/generator/generators/go/templates/storage-templates/save-utils.mustache +75 -0
- package/dist/generator/generators/{golang → go}/templates/storage-templates/storage-interface.mustache +33 -22
- package/dist/generator/generators/go/templates/test-config.mustache +62 -0
- package/dist/generator/generators/go/templates/test-object.mustache +52 -0
- package/dist/generator/generators/go/templates/validation-code.mustache +66 -0
- package/dist/generator/generators/go/templates/validation-utils.mustache +321 -0
- package/dist/generator/generators/typescript/templates/index.mustache +1 -1
- package/dist/generator/generators/typescript/ts-generator.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.test.js +1 -0
- package/dist/types/build.d.ts +2 -0
- package/dist/types/compiler-types.d.ts +1 -1
- package/dist/types/compiler-types.js +1 -1
- package/dist/utils/fs-utils.d.ts +1 -0
- package/dist/utils/fs-utils.js +18 -34
- package/dist/utils/general-utils/string-utils.d.ts +1 -0
- package/dist/utils/general-utils/string-utils.js +11 -0
- package/package.json +5 -1
- package/dist/generator/generators/golang/go-generator.d.ts +0 -23
- package/dist/generator/generators/golang/go-generator.js +0 -511
- package/dist/generator/generators/golang/templates/api-test.mustache +0 -48
- package/dist/generator/generators/golang/templates/json-normalizer.mustache +0 -46
- package/dist/generator/generators/golang/templates/json-path-utils.mustache +0 -21
- package/dist/generator/generators/golang/templates/storage-templates/api-save.mustache +0 -30
- package/dist/generator/generators/golang/templates/storage-templates/index.mustache +0 -41
- package/dist/generator/generators/golang/templates/storage-templates/save-utils.mustache +0 -37
- package/dist/generator/generators/golang/templates/storage-templates/storage-helpers.mustache +0 -51
- package/dist/generator/generators/golang/templates/storage-templates/storage-types.mustache +0 -15
- package/dist/generator/generators/golang/templates/test-config.mustache +0 -39
- package/dist/generator/generators/golang/templates/test-object.mustache +0 -39
- package/dist/generator/generators/golang/templates/validation-code.mustache +0 -51
- package/dist/generator/generators/golang/templates/validation-utils.mustache +0 -246
- /package/dist/generator/generators/{golang → go}/go-ast.d.ts +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package storageutils
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"fmt"
|
|
8
|
+
"time"
|
|
9
|
+
"validationpkg/validationutils"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// saveFunction saves extracted data from payload to storage
|
|
14
|
+
func saveFunction(
|
|
15
|
+
payload interface{},
|
|
16
|
+
uniquePrefix string,
|
|
17
|
+
key string,
|
|
18
|
+
path string,
|
|
19
|
+
store validationutils.StorageInterface,
|
|
20
|
+
config StorageConfig,
|
|
21
|
+
action string,
|
|
22
|
+
) error {
|
|
23
|
+
if path == "" || key == "_SELF" {
|
|
24
|
+
return nil
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Extract value using JSONPath
|
|
28
|
+
value := validationutils.GetJsonPath(payload, path, true)
|
|
29
|
+
|
|
30
|
+
// Create data structure
|
|
31
|
+
data := map[string]interface{}{
|
|
32
|
+
"stored_from": action + "_action",
|
|
33
|
+
"key_path": path,
|
|
34
|
+
"value": value,
|
|
35
|
+
"timestamp": time.Now().UTC().Format(time.RFC3339),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Serialize to JSON
|
|
39
|
+
dataBytes, err := json.Marshal(data)
|
|
40
|
+
if err != nil {
|
|
41
|
+
return fmt.Errorf("failed to marshal data: %w", err)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Save with retry logic
|
|
45
|
+
return SaveData(uniquePrefix, key, string(dataBytes), store, config)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// loadFunction loads and parses stored data from storage
|
|
49
|
+
func loadFunction(
|
|
50
|
+
store validationutils.StorageInterface,
|
|
51
|
+
uniquePrefix string,
|
|
52
|
+
key string,
|
|
53
|
+
) ([]string, error) {
|
|
54
|
+
value, err := store.GetKey(uniquePrefix, key)
|
|
55
|
+
if err != nil {
|
|
56
|
+
// Return empty slice on error (matches TS behavior)
|
|
57
|
+
return []string{}, nil
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if value == "" {
|
|
61
|
+
return []string{}, nil
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Parse JSON
|
|
65
|
+
var data struct {
|
|
66
|
+
Value []interface{} `json:"value"`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if err := json.Unmarshal([]byte(value), &data); err != nil {
|
|
70
|
+
return []string{}, nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Convert to string slice
|
|
74
|
+
result := make([]string, 0, len(data.Value))
|
|
75
|
+
for _, v := range data.Value {
|
|
76
|
+
if v == nil {
|
|
77
|
+
result = append(result, "null")
|
|
78
|
+
} else {
|
|
79
|
+
result = append(result, fmt.Sprintf("%v", v))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result, nil
|
|
84
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package storageutils
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"validationpkg/validationutils"
|
|
7
|
+
"fmt"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// Store_{{action}} stores data from payload to storage for the {{action}} action
|
|
11
|
+
func Store_{{action}}(
|
|
12
|
+
uniquePrefix string,
|
|
13
|
+
payload interface{},
|
|
14
|
+
store validationutils.StorageInterface,
|
|
15
|
+
config StorageConfig,
|
|
16
|
+
) error {
|
|
17
|
+
{{#storeActions}}
|
|
18
|
+
if err := saveFunction(payload, uniquePrefix, "{{{key}}}", "{{{value}}}", store, config, "{{$action}}"); err != nil {
|
|
19
|
+
return fmt.Errorf("failed to save key {{{key}}}: %w", err)
|
|
20
|
+
}
|
|
21
|
+
{{/storeActions}}
|
|
22
|
+
fmt.Printf("Stored data for action {{action}} successfully\n")
|
|
23
|
+
return nil
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// LoadFor_{{action}} loads stored data for the {{action}} action
|
|
27
|
+
func LoadFor_{{action}}(
|
|
28
|
+
uniquePrefix string,
|
|
29
|
+
store validationutils.StorageInterface,
|
|
30
|
+
) (validationutils.ExternalData, error) {
|
|
31
|
+
result := validationutils.ExternalData{}
|
|
32
|
+
|
|
33
|
+
{{#loadActions}}
|
|
34
|
+
{{{key}}}_value, err := loadFunction(store, uniquePrefix, "{{{key}}}")
|
|
35
|
+
if err != nil {
|
|
36
|
+
return result, fmt.Errorf("failed to load key {{{key}}}: %w", err)
|
|
37
|
+
}
|
|
38
|
+
result.{{{key}}} = {{{key}}}_value
|
|
39
|
+
{{/loadActions}}
|
|
40
|
+
|
|
41
|
+
fmt.Printf("Loaded external data for action {{action}}: %+v\n", result)
|
|
42
|
+
return result, nil
|
|
43
|
+
}
|
|
44
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
package storageutils
|
|
3
|
+
|
|
4
|
+
import (
|
|
5
|
+
"fmt"
|
|
6
|
+
"validationpkg/validationutils"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// Perform{{functionName}}Save saves validation state data for a given action
|
|
10
|
+
//
|
|
11
|
+
// Parameters:
|
|
12
|
+
// - action: The action name
|
|
13
|
+
// - uniquePrefix: Unique namespace prefix
|
|
14
|
+
// - payload: The payload data to extract and save
|
|
15
|
+
// - store: Storage interface implementation
|
|
16
|
+
// - config: Optional storage configuration (nil uses defaults)
|
|
17
|
+
//
|
|
18
|
+
// Returns error if the action is not found or save fails
|
|
19
|
+
func Perform{{functionName}}Save(
|
|
20
|
+
action string,
|
|
21
|
+
uniquePrefix string,
|
|
22
|
+
payload interface{},
|
|
23
|
+
store validationutils.StorageInterface,
|
|
24
|
+
config *StorageConfig,
|
|
25
|
+
) error {
|
|
26
|
+
// Set default config if not provided
|
|
27
|
+
completeConfig := StorageConfig{
|
|
28
|
+
RetryAttempts: 3,
|
|
29
|
+
RetryDelayMs: 1000,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if config != nil {
|
|
33
|
+
if config.RetryAttempts > 0 {
|
|
34
|
+
completeConfig.RetryAttempts = config.RetryAttempts
|
|
35
|
+
}
|
|
36
|
+
if config.RetryDelayMs > 0 {
|
|
37
|
+
completeConfig.RetryDelayMs = config.RetryDelayMs
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
switch action {
|
|
42
|
+
{{#actions}}
|
|
43
|
+
case "{{action}}":
|
|
44
|
+
return Store_{{{action}}}(uniquePrefix, payload, store, completeConfig)
|
|
45
|
+
{{/actions}}
|
|
46
|
+
default:
|
|
47
|
+
return fmt.Errorf("action not found: %s", action)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Perform{{functionName}}Load loads validation state data for a given action
|
|
52
|
+
//
|
|
53
|
+
// Parameters:
|
|
54
|
+
// - action: The action name
|
|
55
|
+
// - uniquePrefix: Unique namespace prefix
|
|
56
|
+
// - store: Storage interface implementation
|
|
57
|
+
//
|
|
58
|
+
// Returns ExternalData with loaded values and error if action not found
|
|
59
|
+
func Perform{{functionName}}Load(
|
|
60
|
+
action string,
|
|
61
|
+
uniquePrefix string,
|
|
62
|
+
store validationutils.StorageInterface,
|
|
63
|
+
) (validationutils.ExternalData, error) {
|
|
64
|
+
switch action {
|
|
65
|
+
{{#actions}}
|
|
66
|
+
case "{{action}}":
|
|
67
|
+
return LoadFor_{{{action}}}(uniquePrefix, store)
|
|
68
|
+
{{/actions}}
|
|
69
|
+
default:
|
|
70
|
+
return validationutils.ExternalData{}, fmt.Errorf("action not found: %s", action)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package storageutils
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"fmt"
|
|
7
|
+
"time"
|
|
8
|
+
"validationpkg/validationutils"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// StorageConfig holds configuration for storage operations
|
|
12
|
+
type StorageConfig struct {
|
|
13
|
+
// RetryAttempts is the number of times to retry a failed operation
|
|
14
|
+
RetryAttempts int
|
|
15
|
+
// RetryDelayMs is the delay in milliseconds between retry attempts
|
|
16
|
+
RetryDelayMs int
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// DefaultStorageConfig returns a StorageConfig with sensible defaults
|
|
20
|
+
func DefaultStorageConfig() StorageConfig {
|
|
21
|
+
return StorageConfig{
|
|
22
|
+
RetryAttempts: 3,
|
|
23
|
+
RetryDelayMs: 100,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// SaveData saves data to storage with retry logic
|
|
28
|
+
//
|
|
29
|
+
// Parameters:
|
|
30
|
+
// - uniquePrefix: The namespace prefix for the key
|
|
31
|
+
// - key: The key to store the data under
|
|
32
|
+
// - saveData: The string data to save
|
|
33
|
+
// - store: The storage interface implementation
|
|
34
|
+
// - config: Configuration including retry settings
|
|
35
|
+
//
|
|
36
|
+
// Returns error if all retry attempts fail
|
|
37
|
+
func SaveData(
|
|
38
|
+
uniquePrefix string,
|
|
39
|
+
key string,
|
|
40
|
+
saveData string,
|
|
41
|
+
store validationutils.StorageInterface,
|
|
42
|
+
config StorageConfig,
|
|
43
|
+
) error {
|
|
44
|
+
finalKey := key
|
|
45
|
+
retryTimes := config.RetryAttempts
|
|
46
|
+
delayMs := config.RetryDelayMs
|
|
47
|
+
attempts := 0
|
|
48
|
+
|
|
49
|
+
for attempts < retryTimes {
|
|
50
|
+
err := store.SaveKey(uniquePrefix, finalKey, saveData)
|
|
51
|
+
if err == nil {
|
|
52
|
+
return nil
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
attempts++
|
|
56
|
+
if attempts >= retryTimes {
|
|
57
|
+
return fmt.Errorf("failed to save data after %d attempts: %w", retryTimes, err)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
time.Sleep(time.Duration(delayMs) * time.Millisecond)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// CreateKey creates a fully qualified storage key from prefix and key
|
|
67
|
+
//
|
|
68
|
+
// Parameters:
|
|
69
|
+
// - uniquePrefix: The namespace prefix
|
|
70
|
+
// - key: The key within the namespace
|
|
71
|
+
//
|
|
72
|
+
// Returns the combined key in format "prefix:key"
|
|
73
|
+
func CreateKey(uniquePrefix string, key string) string {
|
|
74
|
+
return fmt.Sprintf("%s:%s", uniquePrefix, key)
|
|
75
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package validationutils
|
|
2
4
|
|
|
3
5
|
// StorageInterface provides a standardized abstraction layer for storage operations
|
|
4
6
|
// that can be implemented by different storage backends (Redis, Memory, File, etc.).
|
|
5
7
|
//
|
|
6
|
-
//
|
|
7
|
-
// Keys
|
|
8
|
-
// Implementations should handle serialization/deserialization as needed
|
|
9
|
-
// Prefix-based operations allow for namespacing and bulk operations
|
|
8
|
+
// Implementation Notes:
|
|
9
|
+
// - Keys should be strings and values are stored as strings
|
|
10
|
+
// - Implementations should handle serialization/deserialization as needed
|
|
11
|
+
// - Prefix-based operations allow for namespacing and bulk operations
|
|
10
12
|
//
|
|
11
|
-
// Example
|
|
13
|
+
// Example:
|
|
12
14
|
//
|
|
13
15
|
// type RedisStorage struct {
|
|
14
16
|
// client *redis.Client
|
|
@@ -18,6 +20,10 @@ package interfaces
|
|
|
18
20
|
// fullKey := fmt.Sprintf("%s:%s", uniquePrefix, key)
|
|
19
21
|
// return r.client.Set(ctx, fullKey, value, 0).Err()
|
|
20
22
|
// }
|
|
23
|
+
//
|
|
24
|
+
// storage := &RedisStorage{client: redisClient}
|
|
25
|
+
// userData, _ := json.Marshal(user)
|
|
26
|
+
// storage.SaveKey("app1", "user:123", string(userData))
|
|
21
27
|
type StorageInterface interface {
|
|
22
28
|
// SaveKey saves a key-value pair to storage with a unique prefix for namespacing.
|
|
23
29
|
//
|
|
@@ -26,11 +32,12 @@ type StorageInterface interface {
|
|
|
26
32
|
// - key: The unique identifier for the stored value within the prefix namespace
|
|
27
33
|
// - value: The string value to store
|
|
28
34
|
//
|
|
29
|
-
// Returns
|
|
35
|
+
// Returns error if the operation fails
|
|
30
36
|
//
|
|
31
37
|
// Example:
|
|
32
|
-
//
|
|
33
|
-
SaveKey(
|
|
38
|
+
// sessionData, _ := json.Marshal(session)
|
|
39
|
+
// err := storage.SaveKey("app1", "session:abc123", string(sessionData))
|
|
40
|
+
SaveKey(uniquePrefix string, key string, value string) error
|
|
34
41
|
|
|
35
42
|
// GetKey retrieves a value by its key from storage within a specific namespace.
|
|
36
43
|
//
|
|
@@ -38,11 +45,14 @@ type StorageInterface interface {
|
|
|
38
45
|
// - uniquePrefix: The unique identifier/namespace prefix used when storing
|
|
39
46
|
// - key: The unique identifier for the value to retrieve within the prefix namespace
|
|
40
47
|
//
|
|
41
|
-
// Returns the stored value
|
|
48
|
+
// Returns the stored value and error if the key does not exist
|
|
42
49
|
//
|
|
43
50
|
// Example:
|
|
44
51
|
// sessionData, err := storage.GetKey("app1", "session:abc123")
|
|
45
|
-
|
|
52
|
+
// if err != nil {
|
|
53
|
+
// // handle key not found
|
|
54
|
+
// }
|
|
55
|
+
GetKey(uniquePrefix string, key string) (string, error)
|
|
46
56
|
|
|
47
57
|
// DeleteKey removes a key-value pair from storage within a specific namespace.
|
|
48
58
|
//
|
|
@@ -50,30 +60,31 @@ type StorageInterface interface {
|
|
|
50
60
|
// - uniquePrefix: The unique identifier/namespace prefix used when storing
|
|
51
61
|
// - key: The unique identifier for the value to delete within the prefix namespace
|
|
52
62
|
//
|
|
53
|
-
// Returns
|
|
63
|
+
// Returns error if the operation fails
|
|
54
64
|
//
|
|
55
65
|
// Example:
|
|
56
66
|
// err := storage.DeleteKey("app1", "session:abc123")
|
|
57
|
-
DeleteKey(uniquePrefix, key string) error
|
|
67
|
+
DeleteKey(uniquePrefix string, key string) error
|
|
58
68
|
|
|
59
|
-
// ListKeys
|
|
69
|
+
// ListKeys lists all keys within a specific namespace/prefix.
|
|
60
70
|
//
|
|
61
71
|
// Parameters:
|
|
62
72
|
// - uniquePrefix: The unique identifier/namespace prefix to list keys from
|
|
63
73
|
//
|
|
64
|
-
// Returns an array of keys within that namespace
|
|
74
|
+
// Returns an array of keys within that namespace
|
|
65
75
|
//
|
|
66
76
|
// Example:
|
|
67
77
|
// app1Keys, err := storage.ListKeys("app1")
|
|
68
|
-
// // Returns keys
|
|
78
|
+
// // Returns keys stored under the "app1" namespace
|
|
79
|
+
// // e.g., []string{"session:abc123", "user:456", "config:settings"}
|
|
69
80
|
ListKeys(uniquePrefix string) ([]string, error)
|
|
70
81
|
|
|
71
|
-
// ClearStorage
|
|
82
|
+
// ClearStorage clears all stored data from the storage backend.
|
|
72
83
|
//
|
|
73
84
|
// WARNING: This operation is destructive and cannot be undone.
|
|
74
85
|
// Use with caution, especially in production environments.
|
|
75
86
|
//
|
|
76
|
-
// Returns
|
|
87
|
+
// Returns error if the operation fails
|
|
77
88
|
//
|
|
78
89
|
// Example:
|
|
79
90
|
// err := storage.ClearStorage() // All data is now removed
|
|
@@ -85,12 +96,12 @@ type StorageInterface interface {
|
|
|
85
96
|
// - uniquePrefix: The unique identifier/namespace prefix to check within
|
|
86
97
|
// - key: The unique identifier to check for existence within the prefix namespace
|
|
87
98
|
//
|
|
88
|
-
// Returns true if the key exists, false otherwise
|
|
99
|
+
// Returns true if the key exists, false otherwise
|
|
89
100
|
//
|
|
90
101
|
// Example:
|
|
91
102
|
// exists, err := storage.KeyExists("app1", "user:123")
|
|
92
|
-
// if exists {
|
|
103
|
+
// if err == nil && exists {
|
|
93
104
|
// userData, _ := storage.GetKey("app1", "user:123")
|
|
94
105
|
// }
|
|
95
|
-
KeyExists(uniquePrefix, key string) (bool, error)
|
|
96
|
-
}
|
|
106
|
+
KeyExists(uniquePrefix string, key string) (bool, error)
|
|
107
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package validationutils
|
|
4
|
+
|
|
5
|
+
// ValidationConfig holds configuration options for running validation routines.
|
|
6
|
+
type ValidationConfig struct {
|
|
7
|
+
// StateFullValidations enables stateful validations that may depend on previous data
|
|
8
|
+
StateFullValidations bool
|
|
9
|
+
// UniqueKey is an optional unique key for the validation instance
|
|
10
|
+
UniqueKey *string
|
|
11
|
+
// Store is an optional implementation of StorageInterface for persisting data across validations
|
|
12
|
+
Store StorageInterface
|
|
13
|
+
// OnlyInvalid if true, only invalid results will be returned
|
|
14
|
+
OnlyInvalid bool
|
|
15
|
+
// HideParentErrors hides nested error details if set to true
|
|
16
|
+
HideParentErrors bool
|
|
17
|
+
// Debug enables debug mode for additional diagnostic information
|
|
18
|
+
Debug bool
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ValidationOutput represents the output of a validation run.
|
|
22
|
+
// Each element corresponds to a single validation test result.
|
|
23
|
+
type ValidationOutput struct {
|
|
24
|
+
// TestName is the name of the validation test
|
|
25
|
+
TestName string `json:"testName"`
|
|
26
|
+
// Valid indicates whether the test passed (true) or failed (false)
|
|
27
|
+
Valid bool `json:"valid"`
|
|
28
|
+
// Code is a numeric code representing the result or error type
|
|
29
|
+
Code int `json:"code"`
|
|
30
|
+
// Description provides additional details about the test result
|
|
31
|
+
Description string `json:"description,omitempty"`
|
|
32
|
+
// DebugInfo contains diagnostic information useful for debugging
|
|
33
|
+
DebugInfo *DebugInfo `json:"_debugInfo,omitempty"`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// DebugInfo contains diagnostic information for validation results
|
|
37
|
+
type DebugInfo struct {
|
|
38
|
+
// FedConfig is the configuration used to generate the validation
|
|
39
|
+
FedConfig interface{} `json:"fedConfig"`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ExternalData holds external data references for validation
|
|
43
|
+
type ExternalData struct {
|
|
44
|
+
Self interface{} `json:"_SELF,omitempty"`
|
|
45
|
+
{{#externalData}}
|
|
46
|
+
{{name}} []string `json:"{{name}},omitempty"`
|
|
47
|
+
{{/externalData}}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ValidationInput represents the input data for validation functions
|
|
51
|
+
type ValidationInput struct {
|
|
52
|
+
Payload interface{}
|
|
53
|
+
ExternalData ExternalData
|
|
54
|
+
Config ValidationConfig
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// TestFunction is a function type that takes ValidationInput and returns a slice of ValidationOutput
|
|
58
|
+
type TestFunction func(input ValidationInput) ([]ValidationOutput, error)
|
|
59
|
+
|
|
60
|
+
// TestFunctionArray is a slice of test functions
|
|
61
|
+
type TestFunctionArray []TestFunction
|
|
62
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var {{name}} = func (input validationutils.ValidationInput) ([]validationutils.ValidationOutput, error) {
|
|
2
|
+
scope := validationutils.GetJsonPath(input.Payload,"{{{scopePath}}}",true)
|
|
3
|
+
|
|
4
|
+
subResults := make([]validationutils.ValidationOutput, 0)
|
|
5
|
+
valid := true
|
|
6
|
+
configureDebugInfo := ""
|
|
7
|
+
for _, testObj := range scope {
|
|
8
|
+
testObjMap, ok := validationutils.DeepCloneJSON(testObj).(map[string]interface{})
|
|
9
|
+
if !ok {
|
|
10
|
+
return nil, fmt.Errorf("Invalid object structure in scope for test {{name}}")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
testObjMap["_EXTERNAL"] = validationutils.DeepCloneJSON(input.ExternalData)
|
|
14
|
+
|
|
15
|
+
{{#variables}}
|
|
16
|
+
{{name}} := {{{value}}}
|
|
17
|
+
validationutils.UnusedFunction({{name}})
|
|
18
|
+
{{/variables}}
|
|
19
|
+
|
|
20
|
+
{{#hasContinue}}
|
|
21
|
+
skipCheck := {{{skipCheckStatement}}}
|
|
22
|
+
if( skipCheck ) {
|
|
23
|
+
continue
|
|
24
|
+
}
|
|
25
|
+
{{/hasContinue}}
|
|
26
|
+
|
|
27
|
+
{{{validationCode}}}
|
|
28
|
+
|
|
29
|
+
delete(testObjMap, "_EXTERNAL")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
result := validationutils.ValidationOutput{
|
|
33
|
+
TestName: "{{name}}",
|
|
34
|
+
Valid: valid,
|
|
35
|
+
Code: 0,
|
|
36
|
+
DebugInfo: &validationutils.DebugInfo{
|
|
37
|
+
FedConfig: configureDebugInfo,
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if valid {
|
|
42
|
+
result.Code = {{successCode}}
|
|
43
|
+
} else {
|
|
44
|
+
result.Code = {{errorCode}}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
results := make([]validationutils.ValidationOutput, 0, len(subResults)+1)
|
|
48
|
+
results = append(results, result)
|
|
49
|
+
results = append(results, subResults...)
|
|
50
|
+
|
|
51
|
+
return results,nil
|
|
52
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
{{#isNested}}
|
|
4
|
+
|
|
5
|
+
{{{nestedFunctions}}}
|
|
6
|
+
|
|
7
|
+
var testFunctions = validationutils.TestFunctionArray{
|
|
8
|
+
{{#names}}
|
|
9
|
+
{{name}},
|
|
10
|
+
{{/names}}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
allResults := make([]validationutils.ValidationOutput, 0)
|
|
14
|
+
|
|
15
|
+
for _, testFunc := range testFunctions {
|
|
16
|
+
results, err := testFunc(input)
|
|
17
|
+
if err != nil {
|
|
18
|
+
return nil, err
|
|
19
|
+
}
|
|
20
|
+
allResults = append(allResults, results...)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
subResults = allResults
|
|
24
|
+
// if all subResults are valid, then valid is true
|
|
25
|
+
valid = true
|
|
26
|
+
for _, res := range subResults {
|
|
27
|
+
if !res.Valid {
|
|
28
|
+
valid = false
|
|
29
|
+
break
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
configureDebugInfo = `NESTED_TEST_OBJECT`
|
|
34
|
+
|
|
35
|
+
{{/isNested}}
|
|
36
|
+
|
|
37
|
+
{{^isNested}}
|
|
38
|
+
|
|
39
|
+
{{#isStateFull}}
|
|
40
|
+
validate := true
|
|
41
|
+
if( input.Config.StateFullValidations == false ) {
|
|
42
|
+
validate = {{{returnStatement}}}
|
|
43
|
+
}
|
|
44
|
+
{{/isStateFull}}
|
|
45
|
+
|
|
46
|
+
{{^isStateFull}}
|
|
47
|
+
validate := {{{returnStatement}}}
|
|
48
|
+
{{/isStateFull}}
|
|
49
|
+
|
|
50
|
+
configureDebugInfo = `{{{TEST_OBJECT}}}`
|
|
51
|
+
|
|
52
|
+
if(!validate){
|
|
53
|
+
result := validationutils.ValidationOutput{
|
|
54
|
+
TestName: "{{testName}}",
|
|
55
|
+
Valid: false,
|
|
56
|
+
Code: {{errorCode}},
|
|
57
|
+
Description: `{{{errorDescription}}}`,
|
|
58
|
+
DebugInfo: &validationutils.DebugInfo{
|
|
59
|
+
FedConfig: configureDebugInfo,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
delete(testObjMap, "_EXTERNAL")
|
|
63
|
+
return []validationutils.ValidationOutput{result},nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
{{/isNested}}
|