jsonschema

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateJSON

func ValidateJSON(schemaJSON string, payloadJSON string) (bool, []string, error)

ValidateJSON validates a raw JSON string (containing variables submitted by the user) against the provided raw JSON Schema string using the Google's jsonschema-go library.

Types

type InputEnvelope

type InputEnvelope struct {
	Action    string `json:"action"`
	Schema    string `json:"schema"`
	Data      string `json:"data,omitempty"`
	Variables string `json:"variables,omitempty"`
}

InputEnvelope defines the JSON envelope sent to standard input of the WASM binary.

type JSONSchema

type JSONSchema struct {
	Type       string                 `json:"type"`
	Title      string                 `json:"title,omitempty"`
	Properties map[string]*JSONSchema `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
	Enum       []string               `json:"enum,omitempty"`
	Default    interface{}            `json:"default,omitempty"`
	MinLength  *int                   `json:"minLength,omitempty"`
	MaxLength  *int                   `json:"maxLength,omitempty"`
	Minimum    *float64               `json:"minimum,omitempty"`
	Maximum    *float64               `json:"maximum,omitempty"`
	Pattern    string                 `json:"pattern,omitempty"`
	Format     string                 `json:"format,omitempty"`
	UIOrder    []string               `json:"ui:order,omitempty"`
	UIWidget   string                 `json:"ui:widget,omitempty"`
	XStep      int                    `json:"x-step,omitempty"`
}

type JSONSchemaBuilder

type JSONSchemaBuilder struct {
	// contains filtered or unexported fields
}

JSONSchemaBuilder builds JSONSchema structs fluently with sticky error tracking.

func NewBuilder

func NewBuilder() *JSONSchemaBuilder

func (*JSONSchemaBuilder) AddBoolean

func (b *JSONSchemaBuilder) AddBoolean(name string) *JSONSchemaPropertyBuilder

func (*JSONSchemaBuilder) AddInteger

func (b *JSONSchemaBuilder) AddInteger(name string) *JSONSchemaPropertyBuilder

func (*JSONSchemaBuilder) AddNumber

func (*JSONSchemaBuilder) AddString

func (*JSONSchemaBuilder) Build

func (b *JSONSchemaBuilder) Build() (*JSONSchema, error)

func (*JSONSchemaBuilder) BuildJSON

func (b *JSONSchemaBuilder) BuildJSON() (string, error)

func (*JSONSchemaBuilder) Error

func (b *JSONSchemaBuilder) Error() error

func (*JSONSchemaBuilder) Title

func (b *JSONSchemaBuilder) Title(title string) *JSONSchemaBuilder

func (*JSONSchemaBuilder) UIOrder

func (b *JSONSchemaBuilder) UIOrder(order ...string) *JSONSchemaBuilder

type JSONSchemaPropertyBuilder

type JSONSchemaPropertyBuilder struct {
	// contains filtered or unexported fields
}

JSONSchemaPropertyBuilder configures property validation constraints and settings.

func (*JSONSchemaPropertyBuilder) AddBoolean

func (*JSONSchemaPropertyBuilder) AddInteger

func (*JSONSchemaPropertyBuilder) AddNumber

func (*JSONSchemaPropertyBuilder) AddString

Chain methods back to the main builder to add more properties.

func (*JSONSchemaPropertyBuilder) Build

func (pb *JSONSchemaPropertyBuilder) Build() (*JSONSchema, error)

func (*JSONSchemaPropertyBuilder) BuildJSON

func (pb *JSONSchemaPropertyBuilder) BuildJSON() (string, error)

func (*JSONSchemaPropertyBuilder) Default

func (pb *JSONSchemaPropertyBuilder) Default(val interface{}) *JSONSchemaPropertyBuilder

func (*JSONSchemaPropertyBuilder) Enum

func (*JSONSchemaPropertyBuilder) Error

func (pb *JSONSchemaPropertyBuilder) Error() error

func (*JSONSchemaPropertyBuilder) Format

func (*JSONSchemaPropertyBuilder) Label

func (*JSONSchemaPropertyBuilder) MaxLength

func (*JSONSchemaPropertyBuilder) Maximum

func (*JSONSchemaPropertyBuilder) MinLength

func (*JSONSchemaPropertyBuilder) Minimum

func (*JSONSchemaPropertyBuilder) Pattern

func (*JSONSchemaPropertyBuilder) Required

func (*JSONSchemaPropertyBuilder) Title

func (*JSONSchemaPropertyBuilder) UIOrder

func (pb *JSONSchemaPropertyBuilder) UIOrder(order ...string) *JSONSchemaBuilder

func (*JSONSchemaPropertyBuilder) UIWidget

func (*JSONSchemaPropertyBuilder) XStep

type OutputEnvelope

type OutputEnvelope struct {
	Valid   *bool           `json:"valid,omitempty"`
	Errors  []string        `json:"errors,omitempty"`
	Widgets []*UIWidgetSpec `json:"widgets,omitempty"`
}

OutputEnvelope defines the JSON envelope received from standard output of the WASM binary.

type UIWidgetSpec

type UIWidgetSpec struct {
	Name      string      `json:"name"`
	Label     string      `json:"label"`
	Type      string      `json:"type"`
	Widget    string      `json:"widget"`
	Required  bool        `json:"required"`
	Value     interface{} `json:"value"`
	Options   []string    `json:"options"`
	MinLength *int        `json:"minLength,omitempty"`
	MaxLength *int        `json:"maxLength,omitempty"`
	Minimum   *float64    `json:"minimum,omitempty"`
	Maximum   *float64    `json:"maximum,omitempty"`
	Pattern   string      `json:"pattern,omitempty"`
	Format    string      `json:"format,omitempty"`
	XStep     int         `json:"xStep,omitempty"`
}

func ParseSchema

func ParseSchema(schemaJSON string, variables map[string]interface{}) ([]*UIWidgetSpec, error)

ParseSchema parses a raw JSON Schema string and compiles it into an ordered list of UIWidgetSpecs. If variables map is provided, the current values are injected into the widget specs.

Directories

Path Synopsis
cmd
jsonschema command

Jump to

Keyboard shortcuts

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