-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.go
More file actions
892 lines (845 loc) · 24 KB
/
schema.go
File metadata and controls
892 lines (845 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
// Package schema provides JSON Schema generation and validation for workflow
// configuration files. It generates a JSON Schema from the known config
// structure and module types, and validates parsed configs against it.
package schema
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"sync"
)
// dynamicModuleTypes holds module types registered at runtime by plugins.
var (
dynamicMu sync.RWMutex
dynamicModuleTypes = make(map[string]bool)
)
// dynamicTriggerTypes holds trigger types registered at runtime by plugins.
var (
dynamicTriggerMu sync.RWMutex
dynamicTriggerTypes = make(map[string]bool)
)
// dynamicWorkflowTypes holds workflow types registered at runtime by plugins.
var (
dynamicWorkflowMu sync.RWMutex
dynamicWorkflowTypes = make(map[string]bool)
)
// RegisterModuleType registers a module type so it is recognized by KnownModuleTypes.
func RegisterModuleType(moduleType string) {
dynamicMu.Lock()
defer dynamicMu.Unlock()
dynamicModuleTypes[moduleType] = true
}
// UnregisterModuleType removes a dynamically registered module type. Intended for testing.
func UnregisterModuleType(moduleType string) {
dynamicMu.Lock()
defer dynamicMu.Unlock()
delete(dynamicModuleTypes, moduleType)
}
// RegisterTriggerType registers a trigger type so it is recognized by KnownTriggerTypes.
func RegisterTriggerType(triggerType string) {
dynamicTriggerMu.Lock()
defer dynamicTriggerMu.Unlock()
dynamicTriggerTypes[triggerType] = true
}
// UnregisterTriggerType removes a dynamically registered trigger type. Intended for testing.
func UnregisterTriggerType(triggerType string) {
dynamicTriggerMu.Lock()
defer dynamicTriggerMu.Unlock()
delete(dynamicTriggerTypes, triggerType)
}
// RegisterWorkflowType registers a workflow type so it is recognized by KnownWorkflowTypes.
func RegisterWorkflowType(workflowType string) {
dynamicWorkflowMu.Lock()
defer dynamicWorkflowMu.Unlock()
dynamicWorkflowTypes[workflowType] = true
}
// UnregisterWorkflowType removes a dynamically registered workflow type. Intended for testing.
func UnregisterWorkflowType(workflowType string) {
dynamicWorkflowMu.Lock()
defer dynamicWorkflowMu.Unlock()
delete(dynamicWorkflowTypes, workflowType)
}
// Schema represents a JSON Schema document.
type Schema struct {
Schema string `json:"$schema,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Enum []string `json:"enum,omitempty"`
AdditionalProperties json.RawMessage `json:"additionalProperties,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty"`
AllOf []*Schema `json:"allOf,omitempty"`
If *Schema `json:"if,omitempty"`
Then *Schema `json:"then,omitempty"`
Default any `json:"default,omitempty"`
MinItems *int `json:"minItems,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Pattern string `json:"pattern,omitempty"`
Definitions map[string]*Schema `json:"$defs,omitempty"`
Ref string `json:"$ref,omitempty"`
}
// setAdditionalPropertiesBool sets additionalProperties to a boolean value.
func (s *Schema) setAdditionalPropertiesBool(v bool) {
if v {
s.AdditionalProperties = json.RawMessage(`true`)
} else {
s.AdditionalProperties = json.RawMessage(`false`)
}
}
// configFieldDefToSchema converts a ConfigFieldDef to a JSON Schema property.
func configFieldDefToSchema(f ConfigFieldDef) *Schema {
s := &Schema{
Description: f.Description,
}
if f.DefaultValue != nil {
s.Default = f.DefaultValue
}
switch f.Type {
case FieldTypeString, FieldTypeDuration, FieldTypeFilePath, FieldTypeSQL:
s.Type = "string"
case FieldTypeNumber:
s.Type = "number"
case FieldTypeBool:
s.Type = "boolean"
case FieldTypeSelect:
s.Type = "string"
if len(f.Options) > 0 {
s.Enum = f.Options
}
case FieldTypeArray:
s.Type = "array"
if f.ArrayItemType != "" {
s.Items = &Schema{Type: f.ArrayItemType}
} else {
s.Items = &Schema{Type: "string"}
}
case FieldTypeMap, FieldTypeJSON:
s.Type = "object"
default:
s.Type = "string"
}
return s
}
// coreModuleTypes is the hardcoded list of built-in module type identifiers
// recognized by the workflow engine's BuildFromConfig.
var coreModuleTypes = []string{
"actor.pool",
"actor.system",
"api.command",
"api.gateway",
"api.handler",
"api.query",
"app.container",
"argo.workflows",
"auth.jwt",
"auth.m2m",
"auth.oauth2",
"auth.token-blacklist",
"auth.user-store",
"aws.codebuild",
"cache.modular",
"cache.redis",
"cloud.account",
"config.provider",
"data.transformer",
"database.partitioned",
"database.workflow",
"dlq.service",
"dynamic.component",
"eventstore.service",
"featureflag.service",
"gitlab.client",
"gitlab.webhook",
"health.checker",
"http.handler",
"http.middleware.auth",
"http.middleware.cors",
"http.middleware.logging",
"http.middleware.otel",
"http.middleware.ratelimit",
"http.middleware.requestid",
"http.middleware.securityheaders",
"http.proxy",
"http.router",
"http.server",
"http.simple_proxy",
"iac.state",
"jsonschema.modular",
"license.validator",
"log.collector",
"messaging.broker",
"messaging.broker.eventbus",
"messaging.handler",
"messaging.kafka",
"messaging.nats",
"metrics.collector",
"nosql.dynamodb",
"nosql.memory",
"nosql.mongodb",
"nosql.redis",
"notification.slack",
"observability.otel",
"openapi",
"openapi.consumer",
"openapi.generator",
"persistence.store",
"platform.apigateway",
"platform.autoscaling",
"platform.context",
"platform.dns",
"platform.do_app",
"platform.do_database",
"platform.do_dns",
"platform.do_networking",
"platform.doks",
"platform.ecs",
"platform.kubernetes",
"platform.networking",
"platform.provider",
"platform.region",
"platform.region_router",
"platform.resource",
"policy.mock",
"processing.step",
"reverseproxy",
"scheduler.modular",
"secrets.aws",
"secrets.vault",
"security.field-protection",
"security.scanner",
"state.connector",
"state.tracker",
"statemachine.engine",
"static.fileserver",
"step.actor_ask",
"step.actor_send",
"step.ai_classify",
"step.ai_complete",
"step.ai_extract",
"step.apigw_apply",
"step.apigw_destroy",
"step.apigw_plan",
"step.apigw_status",
"step.app_deploy",
"step.app_rollback",
"step.app_status",
"step.argo_delete",
"step.argo_list",
"step.argo_logs",
"step.argo_status",
"step.argo_submit",
"step.artifact_delete",
"step.artifact_download",
"step.artifact_list",
"step.artifact_pull",
"step.artifact_push",
"step.artifact_upload",
"step.auth_required",
"step.auth_validate",
"step.authz_check",
"step.base64_decode",
"step.branch",
"step.build_binary",
"step.build_from_config",
"step.build_ui",
"step.cache_delete",
"step.cache_get",
"step.cache_set",
"step.circuit_breaker",
"step.cli_invoke",
"step.cli_print",
"step.cloud_validate",
"step.codebuild_create_project",
"step.codebuild_delete_project",
"step.codebuild_list_builds",
"step.codebuild_logs",
"step.codebuild_start",
"step.codebuild_status",
"step.conditional",
"step.constraint_check",
"step.container_build",
"step.db_create_partition",
"step.db_exec",
"step.db_query",
"step.db_query_cached",
"step.db_sync_partitions",
"step.delegate",
"step.deploy",
"step.deploy_blue_green",
"step.deploy_canary",
"step.deploy_rollback",
"step.deploy_rolling",
"step.deploy_verify",
"step.dlq_replay",
"step.dlq_send",
"step.dns_apply",
"step.dns_plan",
"step.dns_status",
"step.do_deploy",
"step.do_destroy",
"step.do_logs",
"step.do_scale",
"step.do_status",
"step.docker_build",
"step.docker_push",
"step.docker_run",
"step.drift_check",
"step.ecs_apply",
"step.ecs_destroy",
"step.ecs_plan",
"step.ecs_status",
"step.event_decrypt",
"step.event_publish",
"step.feature_flag",
"step.ff_gate",
"step.field_reencrypt",
"step.foreach",
"step.gate",
"step.git_checkout",
"step.git_clone",
"step.git_commit",
"step.git_push",
"step.git_tag",
"step.gitlab_create_mr",
"step.gitlab_mr_comment",
"step.gitlab_parse_webhook",
"step.gitlab_pipeline_status",
"step.gitlab_trigger_pipeline",
"step.graphql",
"step.hash",
"step.http_call",
"step.http_proxy",
"step.iac_apply",
"step.iac_destroy",
"step.iac_drift_detect",
"step.iac_plan",
"step.iac_status",
"step.jq",
"step.json_parse",
"step.json_response",
"step.k8s_apply",
"step.k8s_destroy",
"step.k8s_plan",
"step.k8s_status",
"step.log",
"step.m2m_token",
"step.marketplace_detail",
"step.marketplace_install",
"step.marketplace_installed",
"step.marketplace_search",
"step.marketplace_uninstall",
"step.marketplace_update",
"step.network_apply",
"step.network_plan",
"step.network_status",
"step.nosql_delete",
"step.nosql_get",
"step.nosql_put",
"step.nosql_query",
"step.oidc_auth_url",
"step.oidc_callback",
"step.parallel",
"step.pipeline_output",
"step.platform_apply",
"step.platform_destroy",
"step.platform_plan",
"step.platform_template",
"step.policy_evaluate",
"step.policy_list",
"step.policy_load",
"step.policy_test",
"step.publish",
"step.rate_limit",
"step.raw_response",
"step.regex_match",
"step.region_deploy",
"step.region_failover",
"step.region_promote",
"step.region_status",
"step.region_sync",
"step.region_weight",
"step.request_parse",
"step.resilient_circuit_breaker",
"step.retry_with_backoff",
"step.s3_upload",
"step.sandbox_exec",
"step.scaling_apply",
"step.scaling_destroy",
"step.scaling_plan",
"step.scaling_status",
"step.scan_container",
"step.scan_deps",
"step.scan_sast",
"step.secret_fetch",
"step.secret_rotate",
"step.set",
"step.shell_exec",
"step.statemachine_get",
"step.statemachine_transition",
"step.static_file",
"step.sub_workflow",
"step.token_revoke",
"step.trace_annotate",
"step.trace_extract",
"step.trace_inject",
"step.trace_link",
"step.trace_start",
"step.transform",
"step.ui_scaffold",
"step.ui_scaffold_analyze",
"step.validate",
"step.validate_pagination",
"step.validate_path_param",
"step.validate_request_body",
"step.webhook_verify",
"step.workflow_call",
"storage.artifact",
"storage.gcs",
"storage.local",
"storage.s3",
"storage.sqlite",
"timeline.service",
"tracing.propagation",
"webhook.sender",
"workflow.registry",
}
// CoreModuleTypes returns only the hardcoded built-in module type identifiers.
// Use this when you need the original list without any plugin-provided types.
func CoreModuleTypes() []string {
out := make([]string, len(coreModuleTypes))
copy(out, coreModuleTypes)
return out
}
// KnownModuleTypes returns all built-in module type identifiers plus any types
// registered at runtime by plugins. The result is sorted and deduplicated.
func KnownModuleTypes() []string {
dynamicMu.RLock()
defer dynamicMu.RUnlock()
if len(dynamicModuleTypes) == 0 {
out := make([]string, len(coreModuleTypes))
copy(out, coreModuleTypes)
return out
}
seen := make(map[string]bool, len(coreModuleTypes)+len(dynamicModuleTypes))
for _, t := range coreModuleTypes {
seen[t] = true
}
for t := range dynamicModuleTypes {
seen[t] = true
}
result := make([]string, 0, len(seen))
for t := range seen {
result = append(result, t)
}
sort.Strings(result)
return result
}
// KnownTriggerTypes returns all built-in trigger type identifiers plus any types
// registered at runtime by plugins. The result is sorted and deduplicated.
func KnownTriggerTypes() []string {
core := []string{
"http",
"schedule",
"event",
"eventbus",
}
dynamicTriggerMu.RLock()
defer dynamicTriggerMu.RUnlock()
if len(dynamicTriggerTypes) == 0 {
out := make([]string, len(core))
copy(out, core)
sort.Strings(out)
return out
}
seen := make(map[string]bool, len(core)+len(dynamicTriggerTypes))
for _, t := range core {
seen[t] = true
}
for t := range dynamicTriggerTypes {
seen[t] = true
}
result := make([]string, 0, len(seen))
for t := range seen {
result = append(result, t)
}
sort.Strings(result)
return result
}
// KnownWorkflowTypes returns all built-in workflow handler type identifiers plus any types
// registered at runtime by plugins. The result is sorted and deduplicated.
func KnownWorkflowTypes() []string {
core := []string{
"event",
"http",
"messaging",
"statemachine",
"scheduler",
"integration",
}
dynamicWorkflowMu.RLock()
defer dynamicWorkflowMu.RUnlock()
if len(dynamicWorkflowTypes) == 0 {
out := make([]string, len(core))
copy(out, core)
sort.Strings(out)
return out
}
seen := make(map[string]bool, len(core)+len(dynamicWorkflowTypes))
for _, t := range core {
seen[t] = true
}
for t := range dynamicWorkflowTypes {
seen[t] = true
}
result := make([]string, 0, len(seen))
for t := range seen {
result = append(result, t)
}
sort.Strings(result)
return result
}
// pluginManifestTypes holds the type declarations from a plugin.json manifest.
// This is a minimal subset of the full plugin manifest to avoid import cycles.
// It supports both the flat format (types at root level) and the registry-manifest
// nested capabilities object format.
type pluginManifestTypes struct {
ModuleTypes []string `json:"moduleTypes"`
StepTypes []string `json:"stepTypes"`
TriggerTypes []string `json:"triggerTypes"`
WorkflowTypes []string `json:"workflowTypes"`
// Capabilities is stored as raw JSON to safely handle both the registry-manifest
// format (object with moduleTypes/stepTypes/etc.) and the engine-internal format
// (array of CapabilityDecl). A non-object value is silently ignored.
Capabilities json.RawMessage `json:"capabilities,omitempty"`
}
// pluginManifestCapabilities holds the nested capabilities object used in the
// registry manifest plugin.json format (not the engine-internal format, which
// uses a JSON array of CapabilityDecl instead).
type pluginManifestCapabilities struct {
ModuleTypes []string `json:"moduleTypes"`
StepTypes []string `json:"stepTypes"`
TriggerTypes []string `json:"triggerTypes"`
WorkflowHandlers []string `json:"workflowHandlers"`
}
// LoadPluginTypesFromDir scans pluginDir for subdirectories containing a
// plugin.json manifest, reads each manifest's type declarations, and registers
// them with the schema package so that they appear in all type listings and
// pass validation. Unknown or malformed manifests are silently skipped.
// Returns an error only if pluginDir cannot be read at all.
func LoadPluginTypesFromDir(pluginDir string) error {
entries, err := os.ReadDir(pluginDir)
if err != nil {
return fmt.Errorf("read plugin dir %q: %w", pluginDir, err)
}
for _, e := range entries {
if !e.IsDir() {
continue
}
manifestPath := filepath.Join(pluginDir, e.Name(), "plugin.json")
data, err := os.ReadFile(manifestPath) //nolint:gosec // G304: path is within the trusted plugins directory
if err != nil {
continue
}
var m pluginManifestTypes
if err := json.Unmarshal(data, &m); err != nil {
continue
}
for _, t := range m.ModuleTypes {
RegisterModuleType(t)
}
for _, t := range m.StepTypes {
// Step types share the module type registry (identified by "step." prefix).
RegisterModuleType(t)
}
for _, t := range m.TriggerTypes {
RegisterTriggerType(t)
}
for _, t := range m.WorkflowTypes {
RegisterWorkflowType(t)
}
// Also handle the registry-manifest nested capabilities object format.
// The capabilities field may be a JSON array (engine-internal CapabilityDecl format)
// or a JSON object (registry manifest format). Only process it when it's an object.
if len(m.Capabilities) > 0 && m.Capabilities[0] == '{' {
var cap pluginManifestCapabilities
if err := json.Unmarshal(m.Capabilities, &cap); err == nil {
for _, t := range cap.ModuleTypes {
RegisterModuleType(t)
}
for _, t := range cap.StepTypes {
RegisterModuleType(t)
}
for _, t := range cap.TriggerTypes {
RegisterTriggerType(t)
}
for _, t := range cap.WorkflowHandlers {
RegisterWorkflowType(t)
}
}
}
}
return nil
}
// moduleIfThen builds an if/then conditional schema for a specific module type
// that adds per-type config property validation.
func moduleIfThen(moduleType string, ms *ModuleSchema) *Schema {
props := make(map[string]*Schema, len(ms.ConfigFields))
required := make([]string, 0)
for i := range ms.ConfigFields {
f := &ms.ConfigFields[i]
props[f.Key] = configFieldDefToSchema(*f)
if f.Required {
required = append(required, f.Key)
}
}
configSchema := &Schema{
Type: "object",
Properties: props,
}
configSchema.setAdditionalPropertiesBool(false)
if len(required) > 0 {
configSchema.Required = required
}
then := &Schema{
Properties: map[string]*Schema{
"config": configSchema,
},
}
return &Schema{
If: &Schema{
Required: []string{"type"},
Properties: map[string]*Schema{
"type": {Enum: []string{moduleType}},
},
},
Then: then,
}
}
// GenerateWorkflowSchema produces the full JSON Schema describing a valid
// WorkflowConfig YAML file.
func GenerateWorkflowSchema() *Schema {
one := 1
reg := NewModuleSchemaRegistry()
moduleBase := &Schema{
Type: "object",
Required: []string{"name", "type"},
Properties: map[string]*Schema{
"name": {
Type: "string",
Description: "Unique name for this module instance",
Pattern: "^[a-zA-Z][a-zA-Z0-9._-]*$",
},
"type": {
Type: "string",
Description: "Module type identifier (built-in or plugin-provided)",
Enum: reg.Types(),
},
"config": {
Type: "object",
Description: "Module-specific configuration key/value pairs",
},
"dependsOn": {
Type: "array",
Description: "List of module names this module depends on",
Items: &Schema{Type: "string"},
},
"branches": {
Type: "object",
Description: "Branch configuration for conditional routing",
},
},
}
moduleBase.setAdditionalPropertiesBool(false)
// Build if/then conditionals per registered module type.
allOf := make([]*Schema, 0, len(reg.schemas))
types := reg.Types()
for _, t := range types {
ms := reg.Get(t)
if ms == nil || len(ms.ConfigFields) == 0 {
continue
}
allOf = append(allOf, moduleIfThen(t, ms))
}
if len(allOf) > 0 {
moduleBase.AllOf = allOf
}
// Step schema — type enum built from KnownStepTypes.
stepTypes := KnownStepTypes()
stepTypeEnum := make([]string, 0, len(stepTypes))
for t := range stepTypes {
stepTypeEnum = append(stepTypeEnum, t)
}
sort.Strings(stepTypeEnum)
stepSchema := &Schema{
Type: "object",
Required: []string{"type"},
Properties: map[string]*Schema{
"type": {
Type: "string",
Description: "Step type identifier",
Enum: stepTypeEnum,
},
"name": {Type: "string", Description: "Step name (used to reference output in later steps)"},
"config": {
Type: "object",
Description: "Step-specific configuration",
},
"dependsOn": {
Type: "array",
Items: &Schema{Type: "string"},
},
},
}
// Build per-step if/then config conditionals from the registry.
// TODO: register step config field schemas in ModuleSchemaRegistry so these
// conditionals can enforce per-step config shapes (similar to module types).
stepAllOf := make([]*Schema, 0)
for _, t := range stepTypeEnum {
ms := reg.Get(t)
if ms == nil || len(ms.ConfigFields) == 0 {
continue
}
stepAllOf = append(stepAllOf, moduleIfThen(t, ms))
}
if len(stepAllOf) > 0 {
stepSchema.AllOf = stepAllOf
}
// Trigger schema — KnownTriggerTypes() returns a sorted []string.
triggerEnum := KnownTriggerTypes()
triggerSchema := &Schema{
Type: "object",
Description: "Trigger configurations keyed by trigger type",
Properties: map[string]*Schema{},
}
for _, t := range triggerEnum {
triggerSchema.Properties[t] = &Schema{
Type: "object",
Description: "Configuration for the " + t + " trigger",
}
}
triggerSchema.setAdditionalPropertiesBool(false)
// Pipeline schema.
pipelineSchema := &Schema{
Type: "object",
Description: "Named pipeline definitions",
Properties: map[string]*Schema{
"trigger": {
Type: "object",
Description: "Inline trigger definition for this pipeline",
Properties: map[string]*Schema{
"type": {
Type: "string",
Description: "Trigger type",
Enum: triggerEnum,
},
"config": {Type: "object", Description: "Trigger-specific configuration"},
},
},
"steps": {
Type: "array",
Description: "Ordered list of pipeline steps",
Items: stepSchema,
},
},
}
root := &Schema{
Schema: "https://json-schema.org/draft/2020-12/schema",
Title: "Workflow Configuration",
Description: "Schema for GoCodeAlone/workflow engine YAML configuration files",
Type: "object",
Required: []string{"modules"},
Properties: map[string]*Schema{
"modules": {
Type: "array",
Description: "List of module definitions to instantiate",
Items: moduleBase,
MinItems: &one,
},
"workflows": {
Type: "object",
Description: "Workflow handler configurations keyed by workflow type (e.g. http, messaging, statemachine, scheduler, integration)",
},
"triggers": triggerSchema,
"pipelines": buildPipelinesSchema(pipelineSchema),
"imports": {
Type: "array",
Description: "List of external config files to import",
Items: &Schema{Type: "string"},
},
"requires": {
Type: "object",
Description: "Plugin dependency declarations",
Properties: map[string]*Schema{
"plugins": {
Type: "array",
Items: &Schema{Type: "string"},
},
"version": {Type: "string", Description: "Minimum engine version"},
},
},
"platform": {
Type: "object",
Description: "Platform-level configuration (kubernetes, cloud, etc.)",
},
},
}
return root
}
// KnownStepTypes returns all step type identifiers derived from KnownModuleTypes
// by filtering for types with the "step." prefix. This ensures the set is always
// complete and consistent with the module type registry.
func KnownStepTypes() map[string]bool {
all := KnownModuleTypes()
result := make(map[string]bool, 64)
for _, t := range all {
if len(t) > 5 && t[:5] == "step." {
result[t] = true
}
}
return result
}
// buildPipelinesSchema constructs the pipelines object schema using
// AdditionalProperties so that any pipeline name (arbitrary string key) is
// validated against pipelineSchema rather than creating a literal "*" property.
func buildPipelinesSchema(pipelineSchema *Schema) *Schema {
raw, err := json.Marshal(pipelineSchema)
if err != nil {
// Fallback: allow any object if marshal fails (should never happen).
s := &Schema{
Type: "object",
Description: "Named pipeline definitions",
}
s.setAdditionalPropertiesBool(true)
return s
}
return &Schema{
Type: "object",
Description: "Named pipeline definitions",
AdditionalProperties: json.RawMessage(raw),
}
}
// GenerateApplicationSchema produces a JSON Schema for application-level configs.
func GenerateApplicationSchema() *Schema {
workflowSchema := GenerateWorkflowSchema()
return &Schema{
Schema: "https://json-schema.org/draft/2020-12/schema",
Title: "Application Configuration",
Description: "Schema for GoCodeAlone/workflow application-level YAML configuration files",
Type: "object",
Properties: map[string]*Schema{
"name": {Type: "string", Description: "Application name"},
"version": {Type: "string", Description: "Application version"},
"engine": workflowSchema,
"services": {
Type: "object",
Description: "Named service configurations",
},
},
}
}