Documentation
¶
Overview ¶
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.
Index ¶
- func CamelToSnake(s string) string
- func CoreModuleTypes() []string
- func ExportSnippetsJetBrains() ([]byte, error)
- func ExportSnippetsVSCode() ([]byte, error)
- func HandleGetModuleSchemas(w http.ResponseWriter, r *http.Request)
- func HandleGetSchema(w http.ResponseWriter, _ *http.Request)
- func HandleSchemaAPI(w http.ResponseWriter, r *http.Request)
- func KnownModuleTypes() []string
- func KnownStepTypes() map[string]bool
- func KnownTriggerTypes() []string
- func KnownWorkflowTypes() []string
- func LoadPluginTypesFromDir(pluginDir string) error
- func RegisterModuleType(moduleType string)
- func RegisterRoutes(mux *http.ServeMux)
- func RegisterTriggerType(triggerType string)
- func RegisterWorkflowType(workflowType string)
- func UnregisterModuleType(moduleType string)
- func UnregisterTriggerType(triggerType string)
- func UnregisterWorkflowType(workflowType string)
- func ValidateConfig(cfg *config.WorkflowConfig, opts ...ValidationOption) error
- type ConfigFieldDef
- type ConfigFieldType
- type EventSchema
- type EventSchemaRegistry
- func (r *EventSchemaRegistry) Get(eventType, version string) (*EventSchema, bool)
- func (r *EventSchemaRegistry) GetLatest(eventType string) (*EventSchema, bool)
- func (r *EventSchemaRegistry) List() []*EventSchema
- func (r *EventSchemaRegistry) ListTypes() []string
- func (r *EventSchemaRegistry) Register(schema *EventSchema) error
- func (r *EventSchemaRegistry) Remove(eventType, version string) bool
- func (r *EventSchemaRegistry) Validate(eventType string, data map[string]any) error
- func (r *EventSchemaRegistry) ValidateVersion(eventType, version string, data map[string]any) error
- type EventValidationError
- type EventValidationErrors
- type FieldDef
- type ModuleSchema
- type ModuleSchemaRegistry
- func (r *ModuleSchemaRegistry) All() []*ModuleSchema
- func (r *ModuleSchemaRegistry) AllMap() map[string]*ModuleSchema
- func (r *ModuleSchemaRegistry) Get(moduleType string) *ModuleSchema
- func (r *ModuleSchemaRegistry) Register(s *ModuleSchema)
- func (r *ModuleSchemaRegistry) Types() []string
- func (r *ModuleSchemaRegistry) Unregister(moduleType string)
- type Schema
- type SchemaService
- type ServiceIODef
- type Snippet
- type ValidationError
- type ValidationErrors
- type ValidationOption
- func WithAllowEmptyModules() ValidationOption
- func WithAllowNoEntryPoints() ValidationOption
- func WithExtraModuleTypes(types ...string) ValidationOption
- func WithExtraTriggerTypes(types ...string) ValidationOption
- func WithExtraWorkflowTypes(types ...string) ValidationOption
- func WithSkipModuleTypeCheck() ValidationOption
- func WithSkipTriggerTypeCheck() ValidationOption
- func WithSkipWorkflowTypeCheck() ValidationOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelToSnake ¶ added in v0.3.0
CamelToSnake converts a camelCase identifier to its snake_case equivalent. For example: "contentType" → "content_type", "dbPath" → "db_path". It treats consecutive uppercase letters (acronyms) as a single word: "webhookURL" → "webhook_url", "HTTPRequest" → "http_request".
func CoreModuleTypes ¶
func CoreModuleTypes() []string
CoreModuleTypes returns only the hardcoded built-in module type identifiers. Use this when you need the original list without any plugin-provided types.
func ExportSnippetsJetBrains ¶ added in v0.3.0
ExportSnippetsJetBrains returns all snippets in JetBrains live template XML format. The output can be saved to a .xml file in the JetBrains templates directory.
func ExportSnippetsVSCode ¶ added in v0.3.0
ExportSnippetsVSCode returns all snippets in VSCode snippet JSON format. The output can be saved to a .code-snippets file or a language-specific snippet file in the .vscode directory.
func HandleGetModuleSchemas ¶
func HandleGetModuleSchemas(w http.ResponseWriter, r *http.Request)
HandleGetModuleSchemas serves module config schemas. Query parameters:
- type: return schema for a specific module type (e.g. ?type=http.server)
Without ?type, returns all schemas as a map keyed by module type.
func HandleGetSchema ¶
func HandleGetSchema(w http.ResponseWriter, _ *http.Request)
HandleGetSchema serves the workflow JSON schema.
func HandleSchemaAPI ¶
func HandleSchemaAPI(w http.ResponseWriter, r *http.Request)
HandleSchemaAPI dispatches schema-related API requests. It handles:
- /api/schema → workflow JSON schema
- /api/v1/module-schemas → module config schemas (all or by type)
func KnownModuleTypes ¶
func KnownModuleTypes() []string
KnownModuleTypes returns all built-in module type identifiers plus any types registered at runtime by plugins. The result is sorted and deduplicated.
func KnownStepTypes ¶ added in v0.3.0
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 KnownTriggerTypes ¶
func KnownTriggerTypes() []string
KnownTriggerTypes returns all built-in trigger type identifiers plus any types registered at runtime by plugins. The result is sorted and deduplicated.
func KnownWorkflowTypes ¶
func KnownWorkflowTypes() []string
KnownWorkflowTypes returns all built-in workflow handler type identifiers plus any types registered at runtime by plugins. The result is sorted and deduplicated.
func LoadPluginTypesFromDir ¶ added in v0.3.0
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 RegisterModuleType ¶
func RegisterModuleType(moduleType string)
RegisterModuleType registers a module type so it is recognized by KnownModuleTypes.
func RegisterRoutes ¶
RegisterRoutes registers the schema API endpoint on the given mux.
func RegisterTriggerType ¶ added in v0.2.21
func RegisterTriggerType(triggerType string)
RegisterTriggerType registers a trigger type so it is recognized by KnownTriggerTypes.
func RegisterWorkflowType ¶ added in v0.2.21
func RegisterWorkflowType(workflowType string)
RegisterWorkflowType registers a workflow type so it is recognized by KnownWorkflowTypes.
func UnregisterModuleType ¶
func UnregisterModuleType(moduleType string)
UnregisterModuleType removes a dynamically registered module type. Intended for testing.
func UnregisterTriggerType ¶ added in v0.2.21
func UnregisterTriggerType(triggerType string)
UnregisterTriggerType removes a dynamically registered trigger type. Intended for testing.
func UnregisterWorkflowType ¶ added in v0.2.21
func UnregisterWorkflowType(workflowType string)
UnregisterWorkflowType removes a dynamically registered workflow type. Intended for testing.
func ValidateConfig ¶
func ValidateConfig(cfg *config.WorkflowConfig, opts ...ValidationOption) error
ValidateConfig validates a parsed WorkflowConfig, returning all detected problems. Returns nil if the config is valid.
Types ¶
type ConfigFieldDef ¶
type ConfigFieldDef struct {
Key string `json:"key"`
Label string `json:"label"`
Type ConfigFieldType `json:"type"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
DefaultValue any `json:"defaultValue,omitempty"`
Options []string `json:"options,omitempty"` // for select type
Placeholder string `json:"placeholder,omitempty"`
Group string `json:"group,omitempty"` // field grouping in UI
ArrayItemType string `json:"arrayItemType,omitempty"` // element type for array fields ("string", "number", etc.)
MapValueType string `json:"mapValueType,omitempty"` // value type for map fields ("string", "number", etc.)
InheritFrom string `json:"inheritFrom,omitempty"` // "{edgeType}.{sourceField}" pattern for config inheritance from connected nodes
Sensitive bool `json:"sensitive,omitempty"` // when true, the UI renders this as a password field with visibility toggle
}
ConfigFieldDef describes a single configuration field for a module type.
type ConfigFieldType ¶
type ConfigFieldType string
ConfigFieldType represents the type of a configuration field.
const ( FieldTypeString ConfigFieldType = "string" FieldTypeNumber ConfigFieldType = "number" FieldTypeBool ConfigFieldType = "boolean" FieldTypeSelect ConfigFieldType = "select" FieldTypeJSON ConfigFieldType = "json" FieldTypeDuration ConfigFieldType = "duration" FieldTypeArray ConfigFieldType = "array" FieldTypeMap ConfigFieldType = "map" FieldTypeFilePath ConfigFieldType = "filepath" FieldTypeSQL ConfigFieldType = "sql" )
type EventSchema ¶
type EventSchema struct {
Type string `json:"type" yaml:"type"` // e.g., "order.created"
Version string `json:"version" yaml:"version"` // semver
Description string `json:"description" yaml:"description"` // human-readable description
Fields map[string]FieldDef `json:"fields" yaml:"fields"` // field name -> definition
Required []string `json:"required" yaml:"required"` // required field names
Examples []map[string]any `json:"examples,omitempty" yaml:"examples,omitempty"` // example data payloads
}
EventSchema describes the expected shape of event data for a specific event type and version.
type EventSchemaRegistry ¶
type EventSchemaRegistry struct {
// contains filtered or unexported fields
}
EventSchemaRegistry stores and validates event schemas keyed by "type:version".
func NewEventSchemaRegistry ¶
func NewEventSchemaRegistry() *EventSchemaRegistry
NewEventSchemaRegistry creates a new empty event schema registry.
func (*EventSchemaRegistry) Get ¶
func (r *EventSchemaRegistry) Get(eventType, version string) (*EventSchema, bool)
Get retrieves an event schema by type and version. Returns nil and false if not found.
func (*EventSchemaRegistry) GetLatest ¶
func (r *EventSchemaRegistry) GetLatest(eventType string) (*EventSchema, bool)
GetLatest returns the latest version of the schema for a given event type, determined by lexicographic comparison of semantic version strings. Returns nil and false if no schema exists for the type.
func (*EventSchemaRegistry) List ¶
func (r *EventSchemaRegistry) List() []*EventSchema
List returns all registered schemas as a slice, sorted by type then version.
func (*EventSchemaRegistry) ListTypes ¶
func (r *EventSchemaRegistry) ListTypes() []string
ListTypes returns all unique registered event types, sorted alphabetically.
func (*EventSchemaRegistry) Register ¶
func (r *EventSchemaRegistry) Register(schema *EventSchema) error
Register validates and stores an event schema. It returns an error if a schema with the same type and version is already registered, or if the schema is missing required metadata.
func (*EventSchemaRegistry) Remove ¶
func (r *EventSchemaRegistry) Remove(eventType, version string) bool
Remove deletes a schema identified by event type and version. Returns true if the schema was found and removed, false otherwise.
func (*EventSchemaRegistry) Validate ¶
func (r *EventSchemaRegistry) Validate(eventType string, data map[string]any) error
Validate validates the given data map against the latest schema for the specified event type. Returns nil if valid, or an EventValidationErrors containing all failures.
func (*EventSchemaRegistry) ValidateVersion ¶
func (r *EventSchemaRegistry) ValidateVersion(eventType, version string, data map[string]any) error
ValidateVersion validates data against a specific version of the schema.
type EventValidationError ¶
EventValidationError represents a single event data validation failure.
func (*EventValidationError) Error ¶
func (e *EventValidationError) Error() string
type EventValidationErrors ¶
type EventValidationErrors []*EventValidationError
EventValidationErrors collects multiple event validation failures.
func (EventValidationErrors) Error ¶
func (ve EventValidationErrors) Error() string
type FieldDef ¶
type FieldDef struct {
Type string `json:"type" yaml:"type"` // string, number, boolean, object, array
Description string `json:"description" yaml:"description"` // human-readable description
Enum []string `json:"enum,omitempty" yaml:"enum,omitempty"` // allowed values (if constrained)
Format string `json:"format,omitempty" yaml:"format,omitempty"` // email, uri, date-time, uuid
}
FieldDef describes a single field within an event data payload.
type ModuleSchema ¶
type ModuleSchema struct {
Type string `json:"type"`
Label string `json:"label"`
Category string `json:"category"`
Description string `json:"description,omitempty"`
Inputs []ServiceIODef `json:"inputs,omitempty"`
Outputs []ServiceIODef `json:"outputs,omitempty"`
ConfigFields []ConfigFieldDef `json:"configFields"`
DefaultConfig map[string]any `json:"defaultConfig,omitempty"`
MaxIncoming *int `json:"maxIncoming,omitempty"` // nil=unlimited, 0=none, N=limit
MaxOutgoing *int `json:"maxOutgoing,omitempty"`
}
ModuleSchema describes the full configuration schema for a module type.
type ModuleSchemaRegistry ¶
type ModuleSchemaRegistry struct {
// contains filtered or unexported fields
}
ModuleSchemaRegistry holds all known module configuration schemas.
func GetModuleSchemaRegistry ¶
func GetModuleSchemaRegistry() *ModuleSchemaRegistry
GetModuleSchemaRegistry returns the global module schema registry, allowing callers to register additional schemas (e.g., custom module types).
func NewModuleSchemaRegistry ¶
func NewModuleSchemaRegistry() *ModuleSchemaRegistry
NewModuleSchemaRegistry creates a new registry with all built-in module schemas pre-registered.
func (*ModuleSchemaRegistry) All ¶
func (r *ModuleSchemaRegistry) All() []*ModuleSchema
All returns all registered schemas as a slice.
func (*ModuleSchemaRegistry) AllMap ¶
func (r *ModuleSchemaRegistry) AllMap() map[string]*ModuleSchema
AllMap returns all registered schemas as a map keyed by module type.
func (*ModuleSchemaRegistry) Get ¶
func (r *ModuleSchemaRegistry) Get(moduleType string) *ModuleSchema
Get returns the schema for a module type, or nil if not found.
func (*ModuleSchemaRegistry) Register ¶
func (r *ModuleSchemaRegistry) Register(s *ModuleSchema)
Register adds or replaces a module schema.
func (*ModuleSchemaRegistry) Types ¶
func (r *ModuleSchemaRegistry) Types() []string
Types returns a sorted list of all registered module type identifiers. This is the dynamic equivalent of KnownModuleTypes — it includes both built-in types and any types registered at runtime by plugins.
func (*ModuleSchemaRegistry) Unregister ¶
func (r *ModuleSchemaRegistry) Unregister(moduleType string)
Unregister removes a module schema by type. Intended for cleanup during testing.
type Schema ¶
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"`
}
Schema represents a JSON Schema document.
func GenerateApplicationSchema ¶ added in v0.3.0
func GenerateApplicationSchema() *Schema
GenerateApplicationSchema produces a JSON Schema for application-level configs.
func GenerateWorkflowSchema ¶
func GenerateWorkflowSchema() *Schema
GenerateWorkflowSchema produces the full JSON Schema describing a valid WorkflowConfig YAML file.
type SchemaService ¶
type SchemaService struct{}
SchemaService wraps the schema handlers as an http.Handler for delegate dispatch.
func NewSchemaService ¶
func NewSchemaService() *SchemaService
NewSchemaService creates a new SchemaService.
func (*SchemaService) ServeHTTP ¶
func (s *SchemaService) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for config-driven delegate dispatch.
type ServiceIODef ¶
type ServiceIODef struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
}
ServiceIODef describes a single input or output service port for a module type.
type Snippet ¶ added in v0.3.0
type Snippet struct {
Name string // human-readable name
Prefix string // trigger prefix / keyword
Description string // short description shown in IDE
Body []string // lines of the snippet body
}
Snippet represents a code snippet for IDE support. Body uses ${N:placeholder} VSCode-style syntax.
func GetSnippets ¶ added in v0.3.0
func GetSnippets() []Snippet
GetSnippets returns the canonical set of workflow configuration snippets.
type ValidationError ¶
type ValidationError struct {
Path string // dot-separated path (e.g. "modules[0].type")
Message string
}
ValidationError represents a single validation failure with the path to the offending field and a human-readable message.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []*ValidationError
ValidationErrors collects multiple validation failures.
func (ValidationErrors) Error ¶
func (ve ValidationErrors) Error() string
type ValidationOption ¶
type ValidationOption func(*validationOpts)
ValidationOption configures validation behaviour.
func WithAllowEmptyModules ¶
func WithAllowEmptyModules() ValidationOption
WithAllowEmptyModules disables the "at least one module" requirement.
func WithAllowNoEntryPoints ¶
func WithAllowNoEntryPoints() ValidationOption
WithAllowNoEntryPoints disables the check that requires at least one entry point (trigger, HTTP route, messaging subscription, or scheduler job).
func WithExtraModuleTypes ¶
func WithExtraModuleTypes(types ...string) ValidationOption
WithExtraModuleTypes registers additional module types as valid (e.g. from custom factories registered via AddModuleType).
func WithExtraTriggerTypes ¶
func WithExtraTriggerTypes(types ...string) ValidationOption
WithExtraTriggerTypes registers additional trigger types as valid.
func WithExtraWorkflowTypes ¶
func WithExtraWorkflowTypes(types ...string) ValidationOption
WithExtraWorkflowTypes registers additional workflow handler types as valid.
func WithSkipModuleTypeCheck ¶
func WithSkipModuleTypeCheck() ValidationOption
WithSkipModuleTypeCheck disables validation of module type identifiers. Useful for validating configs that use custom or placeholder module types.
func WithSkipTriggerTypeCheck ¶
func WithSkipTriggerTypeCheck() ValidationOption
WithSkipTriggerTypeCheck disables validation of trigger section keys. Useful when the engine resolves trigger types dynamically.
func WithSkipWorkflowTypeCheck ¶
func WithSkipWorkflowTypeCheck() ValidationOption
WithSkipWorkflowTypeCheck disables validation of workflow section keys. Useful when the engine resolves workflow types dynamically via handlers.