ondc-code-generator 0.8.7 → 0.8.9
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 +1 -1
- package/alpha/docs/page/index.html +6137 -0
- package/alpha/docs/page/style.css +204 -0
- package/alpha/docs/readme.md +5939 -0
- package/alpha/docs/validPaths.json +14351 -0
- package/alpha/page/index.html +6137 -0
- package/alpha/page/style.css +204 -0
- package/alpha/readme.md +5939 -0
- package/alpha/validPaths.json +11393 -34240
- package/alpha/validationpkg/examples/search.json +143 -0
- package/alpha/validationpkg/examples_output/search/case-001/output.json +12 -0
- package/alpha/validationpkg/go.mod +8 -0
- package/alpha/validationpkg/go.sum +4 -0
- package/alpha/validationpkg/jsonvalidations/cancel.go +1289 -0
- package/alpha/validationpkg/jsonvalidations/confirm.go +9121 -0
- package/alpha/validationpkg/jsonvalidations/init.go +4864 -0
- package/alpha/validationpkg/jsonvalidations/issue.go +4868 -0
- package/alpha/validationpkg/jsonvalidations/on_cancel.go +7111 -0
- package/alpha/validationpkg/jsonvalidations/on_confirm.go +8903 -0
- package/alpha/validationpkg/jsonvalidations/on_init.go +4445 -0
- package/alpha/validationpkg/jsonvalidations/on_issue.go +2828 -0
- package/alpha/validationpkg/jsonvalidations/on_issue_status.go +1938 -0
- package/alpha/validationpkg/jsonvalidations/on_search.go +3356 -0
- package/alpha/validationpkg/jsonvalidations/on_status.go +8129 -0
- package/alpha/validationpkg/jsonvalidations/on_track.go +1415 -0
- package/alpha/validationpkg/jsonvalidations/on_update.go +8700 -0
- package/alpha/validationpkg/jsonvalidations/search.go +3585 -0
- package/alpha/validationpkg/jsonvalidations/status.go +1073 -0
- package/alpha/validationpkg/jsonvalidations/track.go +1073 -0
- package/alpha/validationpkg/jsonvalidations/update.go +3012 -0
- package/alpha/validationpkg/main-validator.go +196 -0
- package/alpha/validationpkg/main-validator_test.go +165 -0
- package/alpha/validationpkg/storageutils/api_save_utils.go +83 -0
- package/alpha/validationpkg/storageutils/cancel.go +30 -0
- package/alpha/validationpkg/storageutils/confirm.go +30 -0
- package/alpha/validationpkg/storageutils/index.go +132 -0
- package/alpha/validationpkg/storageutils/init.go +30 -0
- package/alpha/validationpkg/storageutils/issue.go +30 -0
- package/alpha/validationpkg/storageutils/on_cancel.go +30 -0
- package/alpha/validationpkg/storageutils/on_confirm.go +30 -0
- package/alpha/validationpkg/storageutils/on_init.go +30 -0
- package/alpha/validationpkg/storageutils/on_issue.go +30 -0
- package/alpha/validationpkg/storageutils/on_issue_status.go +30 -0
- package/alpha/validationpkg/storageutils/on_search.go +30 -0
- package/alpha/validationpkg/storageutils/on_status.go +30 -0
- package/alpha/validationpkg/storageutils/on_track.go +30 -0
- package/alpha/validationpkg/storageutils/on_update.go +30 -0
- package/alpha/validationpkg/storageutils/save_utils.go +75 -0
- package/alpha/validationpkg/storageutils/search.go +30 -0
- package/alpha/validationpkg/storageutils/status.go +30 -0
- package/alpha/validationpkg/storageutils/track.go +30 -0
- package/alpha/validationpkg/storageutils/update.go +30 -0
- package/alpha/validationpkg/validationutils/json_normalizer.go +152 -0
- package/alpha/validationpkg/validationutils/json_path_utils.go +173 -0
- package/alpha/validationpkg/validationutils/storage-interface.go +107 -0
- package/alpha/validationpkg/validationutils/test-config.go +69 -0
- package/alpha/validationpkg/validationutils/validation_utils.go +429 -0
- package/dist/bin/cli.js +6 -2
- package/dist/generator/config-compiler.d.ts +2 -2
- package/dist/generator/config-compiler.js +10 -4
- package/dist/generator/generators/classes/abstract-generator.d.ts +1 -0
- package/dist/generator/generators/go/go-generator.js +34 -17
- package/dist/generator/generators/go/templates/api-tests.mustache +1 -1
- package/dist/generator/generators/go/templates/go-mod.mustache +1 -1
- package/dist/generator/generators/go/templates/index.mustache +1 -1
- package/dist/generator/generators/go/templates/storage-templates/api-save-utils.mustache +1 -1
- package/dist/generator/generators/go/templates/storage-templates/api-save.mustache +1 -1
- package/dist/generator/generators/go/templates/storage-templates/index.mustache +1 -1
- package/dist/generator/generators/go/templates/storage-templates/save-utils.mustache +1 -1
- package/dist/generator/generators/go/templates/test-templates/validator-test.mustache +6 -6
- package/dist/types/compiler-types.d.ts +2 -1
- package/dist/types/compiler-types.js +1 -0
- package/docs/jval-dsl.md +913 -0
- package/package.json +1 -1
- package/alpha/possible-json-paths.json +0 -248
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package validationutils
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"fmt"
|
|
7
|
+
"strings"
|
|
8
|
+
"sync"
|
|
9
|
+
|
|
10
|
+
"github.com/AsaiYusuke/jsonpath"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
// Global cache for parsed JSONPath functions
|
|
14
|
+
var (
|
|
15
|
+
pathParserCache = make(map[string]func(interface{}) ([]interface{}, error))
|
|
16
|
+
parserCacheMu sync.RWMutex
|
|
17
|
+
cacheHits uint64
|
|
18
|
+
cacheMisses uint64
|
|
19
|
+
statsMu sync.Mutex
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
// getOrParseJSONPath retrieves a cached parser or parses and caches a new one
|
|
23
|
+
func getOrParseJSONPath(path string) (func(interface{}) ([]interface{}, error), error) {
|
|
24
|
+
// Try to get from cache first (read lock for fast concurrent reads)
|
|
25
|
+
parserCacheMu.RLock()
|
|
26
|
+
parser, exists := pathParserCache[path]
|
|
27
|
+
parserCacheMu.RUnlock()
|
|
28
|
+
|
|
29
|
+
if exists {
|
|
30
|
+
// Cache hit - use existing parser
|
|
31
|
+
statsMu.Lock()
|
|
32
|
+
cacheHits++
|
|
33
|
+
statsMu.Unlock()
|
|
34
|
+
return parser, nil
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Cache miss - need to parse
|
|
38
|
+
statsMu.Lock()
|
|
39
|
+
cacheMisses++
|
|
40
|
+
statsMu.Unlock()
|
|
41
|
+
|
|
42
|
+
// Acquire write lock to add to cache
|
|
43
|
+
parserCacheMu.Lock()
|
|
44
|
+
defer parserCacheMu.Unlock()
|
|
45
|
+
|
|
46
|
+
// Double-check after acquiring write lock (another goroutine might have added it)
|
|
47
|
+
if parser, exists := pathParserCache[path]; exists {
|
|
48
|
+
return parser, nil
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Parse the JSONPath expression
|
|
52
|
+
parser, err := jsonpath.Parse(path)
|
|
53
|
+
if err != nil {
|
|
54
|
+
return nil, fmt.Errorf("failed to parse JSONPath %s: %w", path, err)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Cache it for future use
|
|
58
|
+
pathParserCache[path] = parser
|
|
59
|
+
return parser, nil
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// GetParserCacheStats returns cache statistics
|
|
63
|
+
func GetParserCacheStats() (hits, misses uint64, size int) {
|
|
64
|
+
statsMu.Lock()
|
|
65
|
+
h, m := cacheHits, cacheMisses
|
|
66
|
+
statsMu.Unlock()
|
|
67
|
+
|
|
68
|
+
parserCacheMu.RLock()
|
|
69
|
+
s := len(pathParserCache)
|
|
70
|
+
parserCacheMu.RUnlock()
|
|
71
|
+
|
|
72
|
+
return h, m, s
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ClearParserCache clears the cache (useful for testing)
|
|
76
|
+
func ClearParserCache() {
|
|
77
|
+
parserCacheMu.Lock()
|
|
78
|
+
pathParserCache = make(map[string]func(interface{}) ([]interface{}, error))
|
|
79
|
+
parserCacheMu.Unlock()
|
|
80
|
+
|
|
81
|
+
statsMu.Lock()
|
|
82
|
+
cacheHits = 0
|
|
83
|
+
cacheMisses = 0
|
|
84
|
+
statsMu.Unlock()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// isListOfStringsOrNull checks if the variable is a slice containing only strings or nil values
|
|
88
|
+
func isListOfStringsOrNull(variable interface{}) bool {
|
|
89
|
+
slice, ok := variable.([]interface{})
|
|
90
|
+
if !ok {
|
|
91
|
+
return false
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for _, item := range slice {
|
|
95
|
+
if item == nil {
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
if _, isString := item.(string); !isString {
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// GetJsonPath queries a payload using JSONPath and returns the results
|
|
106
|
+
func GetJsonPath(payload interface{}, path string, flattenResult bool) []interface{} {
|
|
107
|
+
resolvedPath, resolvedData, err := resolveJSONPathData(path, payload)
|
|
108
|
+
if err != nil {
|
|
109
|
+
// fmt.Printf("Error resolving JSONPath %s: %v\n", path, err)
|
|
110
|
+
return []interface{}{}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get or parse the JSONPath - uses cache if available
|
|
114
|
+
parser, err := getOrParseJSONPath(resolvedPath)
|
|
115
|
+
if err != nil {
|
|
116
|
+
// fmt.Printf("Error parsing JSONPath %s: %v\n", resolvedPath, err)
|
|
117
|
+
return []interface{}{}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Execute the parsed JSONPath function
|
|
121
|
+
result, err := parser(resolvedData)
|
|
122
|
+
if err != nil {
|
|
123
|
+
// fmt.Printf("Error retrieving JSONPath %s: %v\n", resolvedPath, err)
|
|
124
|
+
return []interface{}{}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Result is already []interface{}
|
|
128
|
+
output := result
|
|
129
|
+
|
|
130
|
+
if len(output) == 0 {
|
|
131
|
+
return []interface{}{}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if isListOfStringsOrNull(output) {
|
|
135
|
+
for i, item := range output {
|
|
136
|
+
if item == nil {
|
|
137
|
+
output[i] = "null"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if flattenResult {
|
|
143
|
+
output = flattenSlice(output)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return output
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// flattenSlice recursively flattens nested slices
|
|
150
|
+
func flattenSlice(slice []interface{}) []interface{} {
|
|
151
|
+
result := make([]interface{}, 0)
|
|
152
|
+
for _, item := range slice {
|
|
153
|
+
if nestedSlice, ok := item.([]interface{}); ok {
|
|
154
|
+
result = append(result, flattenSlice(nestedSlice)...)
|
|
155
|
+
} else {
|
|
156
|
+
result = append(result, item)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func resolveJSONPathData(path string, data interface{}) (string, interface{}, error) {
|
|
163
|
+
if input, ok := data.(ValidationInput); ok {
|
|
164
|
+
if strings.HasPrefix(path, "$._EXTERNAL._SELF") {
|
|
165
|
+
resolvedPath := strings.Replace(path, "$._EXTERNAL._SELF", "$", 1)
|
|
166
|
+
return resolvedPath, input.ExternalData["_SELF"], nil
|
|
167
|
+
} else if strings.HasPrefix(path, "$._EXTERNAL") {
|
|
168
|
+
resolvedPath := strings.Replace(path, "$._EXTERNAL", "$", 1)
|
|
169
|
+
return resolvedPath, input.ExternalData, nil
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return path, data, nil
|
|
173
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
package validationutils
|
|
4
|
+
|
|
5
|
+
// StorageInterface provides a standardized abstraction layer for storage operations
|
|
6
|
+
// that can be implemented by different storage backends (Redis, Memory, File, etc.).
|
|
7
|
+
//
|
|
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
|
|
12
|
+
//
|
|
13
|
+
// Example:
|
|
14
|
+
//
|
|
15
|
+
// type RedisStorage struct {
|
|
16
|
+
// client *redis.Client
|
|
17
|
+
// }
|
|
18
|
+
//
|
|
19
|
+
// func (r *RedisStorage) SaveKey(uniquePrefix, key, value string) error {
|
|
20
|
+
// fullKey := fmt.Sprintf("%s:%s", uniquePrefix, key)
|
|
21
|
+
// return r.client.Set(ctx, fullKey, value, 0).Err()
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// storage := &RedisStorage{client: redisClient}
|
|
25
|
+
// userData, _ := json.Marshal(user)
|
|
26
|
+
// storage.SaveKey("app1", "user:123", string(userData))
|
|
27
|
+
type StorageInterface interface {
|
|
28
|
+
// SaveKey saves a key-value pair to storage with a unique prefix for namespacing.
|
|
29
|
+
//
|
|
30
|
+
// Parameters:
|
|
31
|
+
// - uniquePrefix: A unique identifier/namespace prefix to prevent key collisions
|
|
32
|
+
// - key: The unique identifier for the stored value within the prefix namespace
|
|
33
|
+
// - value: The string value to store
|
|
34
|
+
//
|
|
35
|
+
// Returns error if the operation fails
|
|
36
|
+
//
|
|
37
|
+
// Example:
|
|
38
|
+
// sessionData, _ := json.Marshal(session)
|
|
39
|
+
// err := storage.SaveKey("app1", "session:abc123", string(sessionData))
|
|
40
|
+
SaveKey(uniquePrefix string, key string, value string) error
|
|
41
|
+
|
|
42
|
+
// GetKey retrieves a value by its key from storage within a specific namespace.
|
|
43
|
+
//
|
|
44
|
+
// Parameters:
|
|
45
|
+
// - uniquePrefix: The unique identifier/namespace prefix used when storing
|
|
46
|
+
// - key: The unique identifier for the value to retrieve within the prefix namespace
|
|
47
|
+
//
|
|
48
|
+
// Returns the stored value and error if the key does not exist
|
|
49
|
+
//
|
|
50
|
+
// Example:
|
|
51
|
+
// sessionData, err := storage.GetKey("app1", "session:abc123")
|
|
52
|
+
// if err != nil {
|
|
53
|
+
// // handle key not found
|
|
54
|
+
// }
|
|
55
|
+
GetKey(uniquePrefix string, key string) (string, error)
|
|
56
|
+
|
|
57
|
+
// DeleteKey removes a key-value pair from storage within a specific namespace.
|
|
58
|
+
//
|
|
59
|
+
// Parameters:
|
|
60
|
+
// - uniquePrefix: The unique identifier/namespace prefix used when storing
|
|
61
|
+
// - key: The unique identifier for the value to delete within the prefix namespace
|
|
62
|
+
//
|
|
63
|
+
// Returns error if the operation fails
|
|
64
|
+
//
|
|
65
|
+
// Example:
|
|
66
|
+
// err := storage.DeleteKey("app1", "session:abc123")
|
|
67
|
+
DeleteKey(uniquePrefix string, key string) error
|
|
68
|
+
|
|
69
|
+
// ListKeys lists all keys within a specific namespace/prefix.
|
|
70
|
+
//
|
|
71
|
+
// Parameters:
|
|
72
|
+
// - uniquePrefix: The unique identifier/namespace prefix to list keys from
|
|
73
|
+
//
|
|
74
|
+
// Returns an array of keys within that namespace
|
|
75
|
+
//
|
|
76
|
+
// Example:
|
|
77
|
+
// app1Keys, err := storage.ListKeys("app1")
|
|
78
|
+
// // Returns keys stored under the "app1" namespace
|
|
79
|
+
// // e.g., []string{"session:abc123", "user:456", "config:settings"}
|
|
80
|
+
ListKeys(uniquePrefix string) ([]string, error)
|
|
81
|
+
|
|
82
|
+
// ClearStorage clears all stored data from the storage backend.
|
|
83
|
+
//
|
|
84
|
+
// WARNING: This operation is destructive and cannot be undone.
|
|
85
|
+
// Use with caution, especially in production environments.
|
|
86
|
+
//
|
|
87
|
+
// Returns error if the operation fails
|
|
88
|
+
//
|
|
89
|
+
// Example:
|
|
90
|
+
// err := storage.ClearStorage() // All data is now removed
|
|
91
|
+
ClearStorage() error
|
|
92
|
+
|
|
93
|
+
// KeyExists checks if a key exists in storage within a specific namespace.
|
|
94
|
+
//
|
|
95
|
+
// Parameters:
|
|
96
|
+
// - uniquePrefix: The unique identifier/namespace prefix to check within
|
|
97
|
+
// - key: The unique identifier to check for existence within the prefix namespace
|
|
98
|
+
//
|
|
99
|
+
// Returns true if the key exists, false otherwise
|
|
100
|
+
//
|
|
101
|
+
// Example:
|
|
102
|
+
// exists, err := storage.KeyExists("app1", "user:123")
|
|
103
|
+
// if err == nil && exists {
|
|
104
|
+
// userData, _ := storage.GetKey("app1", "user:123")
|
|
105
|
+
// }
|
|
106
|
+
KeyExists(uniquePrefix string, key string) (bool, error)
|
|
107
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
// SkipTests is a list of test names to be skipped during validation
|
|
10
|
+
SkipTests []string
|
|
11
|
+
// UniqueKey is an optional unique key for the validation instance
|
|
12
|
+
UniqueKey *string
|
|
13
|
+
// Store is an optional implementation of StorageInterface for persisting data across validations
|
|
14
|
+
Store StorageInterface
|
|
15
|
+
// OnlyInvalid if true, only invalid results will be returned
|
|
16
|
+
OnlyInvalid bool
|
|
17
|
+
// HideParentErrors hides nested error details if set to true
|
|
18
|
+
HideParentErrors bool
|
|
19
|
+
// Debug enables debug mode for additional diagnostic information
|
|
20
|
+
Debug bool
|
|
21
|
+
// SkipTestsDict is an internal map for quick lookup of tests to skip
|
|
22
|
+
SkipTestsDict map[string]bool
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ValidationOutput represents the output of a validation run.
|
|
26
|
+
// Each element corresponds to a single validation test result.
|
|
27
|
+
type ValidationOutput struct {
|
|
28
|
+
// TestName is the name of the validation test
|
|
29
|
+
TestName string `json:"testName"`
|
|
30
|
+
// Valid indicates whether the test passed (true) or failed (false)
|
|
31
|
+
Valid bool `json:"valid"`
|
|
32
|
+
// Code is a numeric code representing the result or error type
|
|
33
|
+
Code int `json:"code"`
|
|
34
|
+
// Description provides additional details about the test result
|
|
35
|
+
Description string `json:"description,omitempty"`
|
|
36
|
+
// DebugInfo contains diagnostic information useful for debugging
|
|
37
|
+
DebugInfo *DebugInfo `json:"_debugInfo,omitempty"`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// DebugInfo contains diagnostic information for validation results
|
|
41
|
+
type DebugInfo struct {
|
|
42
|
+
// FedConfig is the configuration used to generate the validation
|
|
43
|
+
FedConfig interface{} `json:"fedConfig"`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ExternalData holds external data references for validation as a map structure.
|
|
47
|
+
//
|
|
48
|
+
// Expected keys:
|
|
49
|
+
// - "_SELF": (interface{}) The current validation context object
|
|
50
|
+
//
|
|
51
|
+
// Example usage:
|
|
52
|
+
//
|
|
53
|
+
// data := ExternalData{
|
|
54
|
+
// "_SELF": currentObject,
|
|
55
|
+
// }
|
|
56
|
+
type ExternalData = map[string]interface{}
|
|
57
|
+
|
|
58
|
+
// ValidationInput represents the input data for validation functions
|
|
59
|
+
type ValidationInput struct {
|
|
60
|
+
Payload interface{} `json:"payload"`
|
|
61
|
+
ExternalData ExternalData `json:"_EXTERNAL,omitempty"`
|
|
62
|
+
Config ValidationConfig `json:"_CONFIG,omitempty"`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TestFunction is a function type that takes ValidationInput and returns a slice of ValidationOutput
|
|
66
|
+
type TestFunction func(input ValidationInput) ([]ValidationOutput, error)
|
|
67
|
+
|
|
68
|
+
// TestFunctionArray is a slice of test functions
|
|
69
|
+
type TestFunctionArray []TestFunction
|