ondc-code-generator 0.8.9 → 1.0.0

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.
Files changed (95) hide show
  1. package/alpha/possible-json-paths.json +34134 -0
  2. package/alpha/table/page/index.html +11487 -0
  3. package/alpha/table/page/style.css +449 -0
  4. package/alpha/table/rag-table-docs/confirm.md +63 -0
  5. package/alpha/table/rag-table-docs/init.md +81 -0
  6. package/alpha/table/rag-table-docs/on_confirm.md +164 -0
  7. package/alpha/table/rag-table-docs/on_init.md +146 -0
  8. package/alpha/table/rag-table-docs/on_search.md +163 -0
  9. package/alpha/table/rag-table-docs/on_select.md +99 -0
  10. package/alpha/table/rag-table-docs/on_status.md +153 -0
  11. package/alpha/table/rag-table-docs/on_update.md +164 -0
  12. package/alpha/table/rag-table-docs/raw_table.json +11198 -0
  13. package/alpha/table/rag-table-docs/search.md +128 -0
  14. package/alpha/table/rag-table-docs/select.md +70 -0
  15. package/alpha/table/rag-table-docs/status.md +44 -0
  16. package/alpha/table/rag-table-docs/update.md +51 -0
  17. package/alpha/table/readme.md +1312 -0
  18. package/alpha/table/validPaths.json +34134 -0
  19. package/alpha/table.zip +0 -0
  20. package/dist/bin/cli.js +4 -0
  21. package/dist/generator/config-compiler.d.ts +16 -2
  22. package/dist/generator/config-compiler.js +57 -19
  23. package/dist/generator/generators/classes/abstract-generator.d.ts +2 -0
  24. package/dist/generator/generators/documentation/md-generator.d.ts +12 -5
  25. package/dist/generator/generators/documentation/md-generator.js +23 -28
  26. package/dist/generator/generators/documentation/templates/index.mustache +162 -26
  27. package/dist/generator/generators/documentation/templates/style.css +387 -142
  28. package/dist/generator/generators/go/go-generator.js +1 -1
  29. package/dist/generator/generators/javascript/js-generator.js +1 -1
  30. package/dist/generator/generators/python/py-generator.js +1 -1
  31. package/dist/generator/generators/rag/rag-generator.d.ts +48 -0
  32. package/dist/generator/generators/rag/rag-generator.js +185 -0
  33. package/dist/generator/generators/rag/rag-table-generator.d.ts +55 -0
  34. package/dist/generator/generators/rag/rag-table-generator.js +269 -0
  35. package/dist/generator/generators/typescript/ts-generator.js +1 -1
  36. package/dist/index.test.js +12 -3
  37. package/dist/types/build.d.ts +4 -0
  38. package/dist/types/compiler-types.d.ts +3 -1
  39. package/dist/types/compiler-types.js +2 -0
  40. package/package.json +1 -1
  41. package/alpha/docs/page/index.html +0 -6137
  42. package/alpha/docs/page/style.css +0 -204
  43. package/alpha/docs/readme.md +0 -5939
  44. package/alpha/docs/validPaths.json +0 -14351
  45. package/alpha/page/index.html +0 -6137
  46. package/alpha/page/style.css +0 -204
  47. package/alpha/readme.md +0 -5939
  48. package/alpha/validationpkg/examples/search.json +0 -143
  49. package/alpha/validationpkg/examples_output/search/case-001/output.json +0 -12
  50. package/alpha/validationpkg/go.mod +0 -8
  51. package/alpha/validationpkg/go.sum +0 -4
  52. package/alpha/validationpkg/jsonvalidations/cancel.go +0 -1289
  53. package/alpha/validationpkg/jsonvalidations/confirm.go +0 -9121
  54. package/alpha/validationpkg/jsonvalidations/init.go +0 -4864
  55. package/alpha/validationpkg/jsonvalidations/issue.go +0 -4868
  56. package/alpha/validationpkg/jsonvalidations/on_cancel.go +0 -7111
  57. package/alpha/validationpkg/jsonvalidations/on_confirm.go +0 -8903
  58. package/alpha/validationpkg/jsonvalidations/on_init.go +0 -4445
  59. package/alpha/validationpkg/jsonvalidations/on_issue.go +0 -2828
  60. package/alpha/validationpkg/jsonvalidations/on_issue_status.go +0 -1938
  61. package/alpha/validationpkg/jsonvalidations/on_search.go +0 -3356
  62. package/alpha/validationpkg/jsonvalidations/on_status.go +0 -8129
  63. package/alpha/validationpkg/jsonvalidations/on_track.go +0 -1415
  64. package/alpha/validationpkg/jsonvalidations/on_update.go +0 -8700
  65. package/alpha/validationpkg/jsonvalidations/search.go +0 -3585
  66. package/alpha/validationpkg/jsonvalidations/status.go +0 -1073
  67. package/alpha/validationpkg/jsonvalidations/track.go +0 -1073
  68. package/alpha/validationpkg/jsonvalidations/update.go +0 -3012
  69. package/alpha/validationpkg/main-validator.go +0 -196
  70. package/alpha/validationpkg/main-validator_test.go +0 -165
  71. package/alpha/validationpkg/storageutils/api_save_utils.go +0 -83
  72. package/alpha/validationpkg/storageutils/cancel.go +0 -30
  73. package/alpha/validationpkg/storageutils/confirm.go +0 -30
  74. package/alpha/validationpkg/storageutils/index.go +0 -132
  75. package/alpha/validationpkg/storageutils/init.go +0 -30
  76. package/alpha/validationpkg/storageutils/issue.go +0 -30
  77. package/alpha/validationpkg/storageutils/on_cancel.go +0 -30
  78. package/alpha/validationpkg/storageutils/on_confirm.go +0 -30
  79. package/alpha/validationpkg/storageutils/on_init.go +0 -30
  80. package/alpha/validationpkg/storageutils/on_issue.go +0 -30
  81. package/alpha/validationpkg/storageutils/on_issue_status.go +0 -30
  82. package/alpha/validationpkg/storageutils/on_search.go +0 -30
  83. package/alpha/validationpkg/storageutils/on_status.go +0 -30
  84. package/alpha/validationpkg/storageutils/on_track.go +0 -30
  85. package/alpha/validationpkg/storageutils/on_update.go +0 -30
  86. package/alpha/validationpkg/storageutils/save_utils.go +0 -75
  87. package/alpha/validationpkg/storageutils/search.go +0 -30
  88. package/alpha/validationpkg/storageutils/status.go +0 -30
  89. package/alpha/validationpkg/storageutils/track.go +0 -30
  90. package/alpha/validationpkg/storageutils/update.go +0 -30
  91. package/alpha/validationpkg/validationutils/json_normalizer.go +0 -152
  92. package/alpha/validationpkg/validationutils/json_path_utils.go +0 -173
  93. package/alpha/validationpkg/validationutils/storage-interface.go +0 -107
  94. package/alpha/validationpkg/validationutils/test-config.go +0 -69
  95. package/alpha/validationpkg/validationutils/validation_utils.go +0 -429
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_cancel stores data from payload to storage for the on_cancel action
11
- func Store_on_cancel(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_cancel successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_cancel loads stored data for the on_cancel action
22
- func LoadFor_on_cancel(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_cancel: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_confirm stores data from payload to storage for the on_confirm action
11
- func Store_on_confirm(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_confirm successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_confirm loads stored data for the on_confirm action
22
- func LoadFor_on_confirm(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_confirm: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_init stores data from payload to storage for the on_init action
11
- func Store_on_init(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_init successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_init loads stored data for the on_init action
22
- func LoadFor_on_init(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_init: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_issue stores data from payload to storage for the on_issue action
11
- func Store_on_issue(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_issue successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_issue loads stored data for the on_issue action
22
- func LoadFor_on_issue(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_issue: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_issue_status stores data from payload to storage for the on_issue_status action
11
- func Store_on_issue_status(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_issue_status successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_issue_status loads stored data for the on_issue_status action
22
- func LoadFor_on_issue_status(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_issue_status: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_search stores data from payload to storage for the on_search action
11
- func Store_on_search(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_search successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_search loads stored data for the on_search action
22
- func LoadFor_on_search(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_search: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_status stores data from payload to storage for the on_status action
11
- func Store_on_status(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_status successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_status loads stored data for the on_status action
22
- func LoadFor_on_status(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_status: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_track stores data from payload to storage for the on_track action
11
- func Store_on_track(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_track successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_track loads stored data for the on_track action
22
- func LoadFor_on_track(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_track: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_on_update stores data from payload to storage for the on_update action
11
- func Store_on_update(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action on_update successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_on_update loads stored data for the on_update action
22
- func LoadFor_on_update(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action on_update: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,75 +0,0 @@
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,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_search stores data from payload to storage for the search action
11
- func Store_search(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action search successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_search loads stored data for the search action
22
- func LoadFor_search(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action search: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_status stores data from payload to storage for the status action
11
- func Store_status(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action status successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_status loads stored data for the status action
22
- func LoadFor_status(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action status: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_track stores data from payload to storage for the track action
11
- func Store_track(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action track successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_track loads stored data for the track action
22
- func LoadFor_track(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action track: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,30 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package storageutils
4
-
5
- import (
6
- "fmt"
7
- "validationpkg/validationutils"
8
- )
9
-
10
- // Store_update stores data from payload to storage for the update action
11
- func Store_update(
12
- uniquePrefix string,
13
- payload interface{},
14
- store validationutils.StorageInterface,
15
- config StorageConfig,
16
- ) error {
17
- fmt.Printf("Stored data for action update successfully\n")
18
- return nil
19
- }
20
-
21
- // LoadFor_update loads stored data for the update action
22
- func LoadFor_update(
23
- uniquePrefix string,
24
- store validationutils.StorageInterface,
25
- ) (validationutils.ExternalData, error) {
26
- result := validationutils.ExternalData{}
27
-
28
- fmt.Printf("Loaded external data for action update: %+v\n", result)
29
- return result, nil
30
- }
@@ -1,152 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package validationutils
4
-
5
- // NormalizeKeys normalizes JSON structures so that:
6
- // - All objects with the same property name share the union of keys seen anywhere
7
- // - All objects inside the same array share the union of keys at that array level
8
- // - Missing keys are filled with nil
9
- func NormalizeKeys(input interface{}) interface{} {
10
- // Step 1: Collect templates by property name
11
- templatesByPropName := make(map[string]map[string]struct{})
12
- collectTemplates(input, templatesByPropName)
13
-
14
- // Step 2: Apply templates and within-array unions
15
- return applyTemplates(input, templatesByPropName)
16
- }
17
-
18
- // collectTemplates walks the data structure and collects all keys for each property name
19
- func collectTemplates(node interface{}, templates map[string]map[string]struct{}) {
20
- switch v := node.(type) {
21
- case []interface{}:
22
- // Recurse into array items
23
- for _, item := range v {
24
- collectTemplates(item, templates)
25
- }
26
-
27
- case map[string]interface{}:
28
- // For each property: if it's an object (non-array), record its keys
29
- for propName, propValue := range v {
30
- if obj, ok := propValue.(map[string]interface{}); ok {
31
- // Initialize set for this property name if needed
32
- if templates[propName] == nil {
33
- templates[propName] = make(map[string]struct{})
34
- }
35
- // Add all keys from this object to the template
36
- for childKey := range obj {
37
- templates[propName][childKey] = struct{}{}
38
- }
39
- }
40
- // Recurse into the value
41
- collectTemplates(propValue, templates)
42
- }
43
- }
44
- }
45
-
46
- // applyTemplates applies the collected templates and array-level unions
47
- func applyTemplates(node interface{}, templates map[string]map[string]struct{}) interface{} {
48
- switch v := node.(type) {
49
- case []interface{}:
50
- // Compute union of keys across all object elements at this array level
51
- arrayUnion := make(map[string]struct{})
52
- for _, item := range v {
53
- if obj, ok := item.(map[string]interface{}); ok {
54
- for key := range obj {
55
- arrayUnion[key] = struct{}{}
56
- }
57
- }
58
- }
59
-
60
- // Apply union to each array element
61
- result := make([]interface{}, len(v))
62
- for i, item := range v {
63
- if obj, ok := item.(map[string]interface{}); ok {
64
- // Create new object with array union keys
65
- next := make(map[string]interface{})
66
-
67
- // Copy existing keys
68
- for k, val := range obj {
69
- next[k] = val
70
- }
71
-
72
- // Add missing keys from array union
73
- for key := range arrayUnion {
74
- if _, exists := next[key]; !exists {
75
- next[key] = nil
76
- }
77
- }
78
-
79
- // Now apply templates per property name for nested objects
80
- for propName, propValue := range next {
81
- if nestedObj, ok := propValue.(map[string]interface{}); ok {
82
- // Align to template for this property name
83
- next[propName] = fillFromTemplate(propName, nestedObj, templates)
84
- } else {
85
- // Recurse for arrays or other structures
86
- next[propName] = applyTemplates(propValue, templates)
87
- }
88
- }
89
- result[i] = next
90
- } else {
91
- // Not an object, just recurse
92
- result[i] = applyTemplates(item, templates)
93
- }
94
- }
95
- return result
96
-
97
- case map[string]interface{}:
98
- out := make(map[string]interface{})
99
- for propName, propValue := range v {
100
- if nestedObj, ok := propValue.(map[string]interface{}); ok {
101
- // Align object to the template for this property name
102
- out[propName] = fillFromTemplate(propName, nestedObj, templates)
103
- } else {
104
- out[propName] = applyTemplates(propValue, templates)
105
- }
106
- }
107
- return out
108
-
109
- default:
110
- // Primitives unchanged
111
- return v
112
- }
113
- }
114
-
115
- // fillFromTemplate applies the template for a given property name
116
- func fillFromTemplate(propName string, obj map[string]interface{}, templates map[string]map[string]struct{}) interface{} {
117
- // First recurse on children so nested arrays/objects also normalize
118
- base := applyTemplates(obj, templates).(map[string]interface{})
119
-
120
- // Get template for this property name
121
- template, hasTemplate := templates[propName]
122
- if !hasTemplate {
123
- return base // No known template keys for this prop
124
- }
125
-
126
- // Fill missing keys with nil
127
- filled := make(map[string]interface{})
128
- for k, v := range base {
129
- filled[k] = v
130
- }
131
- for key := range template {
132
- if _, exists := filled[key]; !exists {
133
- filled[key] = nil
134
- }
135
- }
136
-
137
- return filled
138
- }
139
-
140
- // DeepCloneJSON creates a deep clone of a JSON-serializable structure using sonic
141
- func DeepCloneJSON(v interface{}) interface{} {
142
- /* b, err := sonic.Marshal(v)
143
- if err != nil {
144
- panic(err) // or handle error
145
- }
146
- var out interface{}
147
- if err := sonic.Unmarshal(b, &out); err != nil {
148
- panic(err)
149
- }
150
- return out */
151
- return v
152
- }