schema

package
v0.0.0-...-dac86b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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 recognized by the workflow engine's BuildFromConfig.

func KnownTriggerTypes

func KnownTriggerTypes() []string

KnownTriggerTypes returns all built-in trigger type identifiers.

func KnownWorkflowTypes

func KnownWorkflowTypes() []string

KnownWorkflowTypes returns all built-in workflow handler type identifiers.

func RegisterRoutes

func RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers the schema API endpoint on the given mux.

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

type EventValidationError struct {
	Field   string
	Message string
}

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"`
}

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.

type Schema

type Schema struct {
	Schema      string             `json:"$schema"`
	Title       string             `json:"title"`
	Description string             `json:"description,omitempty"`
	Type        string             `json:"type"`
	Required    []string           `json:"required,omitempty"`
	Properties  map[string]*Schema `json:"properties,omitempty"`
	Items       *Schema            `json:"items,omitempty"`
	Enum        []string           `json:"enum,omitempty"`
	AdditionalP *bool              `json:"additionalProperties,omitempty"`
	AnyOf       []*Schema          `json:"anyOf,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 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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL