Documentation
¶
Overview ¶
Package schema provides JSON Schema parsing, validation, and value coercion for Runware model request schemas. It is transport-agnostic and contains no CLI or HTTP dependencies.
Index ¶
- Constants
- Variables
- func AllLeafsProvided(prefix string, node Node, provided map[string]struct{}) bool
- func DeepSet(payload map[string]any, path []string, value any)
- func ExtractDeliveryMethod(node Node) (options []string, defaultVal string)
- func ExtractTaskType(node Node) (string, bool)
- func IsAuto(field string) bool
- func IsNumeric(s string) bool
- func IsProtected(field string) (hint string, ok bool)
- func MustAtoi(s string) int
- func NormalizeProvidedKey(arg string, node Node) string
- func ParseKV(arg string, node Node) (path []string, value any, err error)
- func ResolveDeliveryMethod(flagVal string, payload map[string]any, node Node) string
- func ValidateAllOf(node Node, payload map[string]any) error
- func ValidateConstraints(node Node, payload map[string]any) error
- func ValidateEnums(node Node, payload map[string]any) error
- func ValidateRequired(node Node, payload map[string]any) error
- type ManagedField
- type Node
- type SchemaType
Constants ¶
const ( TypeString = "string" TypeInteger = "integer" TypeArray = "array" TypeObject = "object" )
JSON Schema "type" field values.
Variables ¶
var ManagedFields = map[string]ManagedField{ "model": { Protected: true, Hint: "pass the model as the first positional argument", }, "taskType": { Protected: true, Hint: "use the --task-type flag instead", }, "taskUUID": { Protected: false, }, "deliveryMethod": { Protected: false, }, }
ManagedFields is the set of payload keys managed by the run command. Every entry is excluded from required-field checks and shell completions. Entries with Protected: true additionally reject user-supplied key=value args. deliveryMethod is not protected: it may be overridden via --delivery-method or a key=value argument.
Functions ¶
func AllLeafsProvided ¶
AllLeafsProvided reports whether every non-AutoField leaf path of node, rooted at prefix, is present in provided.
func DeepSet ¶
DeepSet writes value into payload at the location described by path, creating intermediate maps and slices as needed. Existing maps are merged rather than replaced.
func ExtractDeliveryMethod ¶
ExtractDeliveryMethod returns the allowed delivery method values and the schema-specified default for the model's deliveryMethod property.
func ExtractTaskType ¶
ExtractTaskType inspects node.Properties["taskType"] for a constant value using const → enum[0] → default precedence. Returns the task type string and true on success, or ("", false) when the schema does not encode a constant taskType.
func IsAuto ¶
IsAuto reports whether field is managed automatically by the run command and should be excluded from required-field validation and shell completions.
func IsProtected ¶
IsProtected reports whether field is a system-managed key that must not be supplied as a user key=value argument. When blocked, hint describes the correct mechanism to use instead.
func NormalizeProvidedKey ¶
NormalizeProvidedKey returns the canonical dot-notation key for a "key=value" completion argument by running it through ParseKV to apply auto-index sugar. Falls back to the verbatim key portion when ParseKV fails.
func ParseKV ¶
ParseKV splits a "key=value" argument on the first '=' and coerces the value to the Go type implied by the model schema. The key may use dot-notation to address nested fields (e.g. "speech.text=Hello" or "messages.0.role=user"). A non-numeric segment inside an array-typed parent is treated as index 0 (sugar for the common single-item case: "messages.role=user"). Returns a path slice (length ≥ 1) and the coerced value.
func ResolveDeliveryMethod ¶
ResolveDeliveryMethod determines the delivery method to use for a request. Priority: payload value > flagVal > schema default > first schema option.
func ValidateAllOf ¶
ValidateAllOf checks structural constraints expressed in the schema's allOf array: dependentRequired fields and oneOf const-property combinations.
func ValidateConstraints ¶ added in v0.13.1
ValidateConstraints checks the value constraints declared on each schema property against the corresponding payload value: numeric bounds, string length/pattern/format, and array length/uniqueness. It recurses into nested objects and array items, mirroring ValidateEnums.
func ValidateEnums ¶ added in v0.12.0
ValidateEnums checks that every string value in payload that maps to a schema property with a string-enum constraint (oneOf consts or direct enum) is one of the allowed values. It recurses into nested objects and arrays.
Types ¶
type ManagedField ¶
type ManagedField struct {
// Protected indicates that the user must not supply this field via a
// key=value CLI argument. When true, Hint is shown in the error message
// directing the user to the correct mechanism.
Protected bool
// Hint is a short human-readable explanation shown when a protected field
// is rejected. Empty for non-protected managed fields.
Hint string
}
ManagedField describes a system-managed payload key that is injected automatically by the run command.
type Node ¶
type Node struct {
Title string `json:"title"`
Description string `json:"description"`
Type SchemaType `json:"type"`
Default json.RawMessage `json:"default"`
Properties map[string]Node `json:"properties"`
Required []string `json:"required"`
// Enum and Const are used to extract constant values such as taskType.
Enum []json.RawMessage `json:"enum"`
Const json.RawMessage `json:"const"`
// Items holds the schema for elements of an array-typed property.
// Used to coerce values when dot-notation paths descend into arrays.
Items *Node `json:"items"`
// Minimum, Maximum, and MultipleOf carry numeric value constraints. Pointers
// so an absent keyword is distinguishable from a real zero bound (e.g. a
// minimum of 0 is meaningful and must not be treated as "no minimum").
Minimum *float64 `json:"minimum"`
Maximum *float64 `json:"maximum"`
MultipleOf *float64 `json:"multipleOf"`
ExclusiveMinimum *float64 `json:"exclusiveMinimum"`
ExclusiveMaximum *float64 `json:"exclusiveMaximum"`
// String constraints. Pattern and Format are absent when empty.
MinLength *int `json:"minLength"`
MaxLength *int `json:"maxLength"`
Pattern string `json:"pattern"`
Format string `json:"format"`
// Array constraints.
MinItems *int `json:"minItems"`
MaxItems *int `json:"maxItems"`
UniqueItems bool `json:"uniqueItems"`
// AllOf, OneOf, and DependentRequired support structural constraints used by
// model schemas to express mutually-exclusive option sets (e.g. dimension
// combinations) and co-dependent fields.
AllOf []Node `json:"allOf"`
OneOf []Node `json:"oneOf"`
DependentRequired map[string][]string `json:"dependentRequired"`
}
Node is a minimal representation of a JSON Schema node used for task-type extraction, input validation, and value coercion. It covers all fields needed by the run command; it intentionally omits fields only used by model schema display.
type SchemaType ¶ added in v0.11.0
type SchemaType string
SchemaType holds the JSON Schema "type" value. JSON Schema allows "type" to be either a string or an array of strings (e.g. ["string", "null"] for nullable fields). UnmarshalJSON normalizes both forms to the first non-"null" type string.
func (*SchemaType) UnmarshalJSON ¶ added in v0.11.0
func (t *SchemaType) UnmarshalJSON(b []byte) error