model

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 3 Imported by: 3

Documentation

Overview

Package model defines the typed form model consumed by renderers, following the structure documented in go-form-gen.md:97-158. Builders reside in internal/model but return the types defined here. Validation rules expose canonical identifiers (min/max, minLength/maxLength, pattern) with string parameters so renderers can map numeric bounds (including exclusive limits), textual constraints, and regexes onto HTML attributes or runtime validators without sacrificing deterministic JSON snapshots. Schema extensions under the `x-formgen` namespace flow into `FormModel` and `Field` metadata while the curated `UIHints` map surfaces renderer-facing directives such as `placeholder`, `helpText`, `cssClass`, `inputType`, `widget`, `repeaterLabel`, and visibility toggles like `hideLabel`. Renderers can rely on these hints to adjust layout without having to parse raw extension payloads.

Index

Constants

View Source
const (
	FieldTypeString  = internalmodel.FieldTypeString
	FieldTypeInteger = internalmodel.FieldTypeInteger
	FieldTypeNumber  = internalmodel.FieldTypeNumber
	FieldTypeBoolean = internalmodel.FieldTypeBoolean
	FieldTypeArray   = internalmodel.FieldTypeArray
	FieldTypeObject  = internalmodel.FieldTypeObject
)
View Source
const (
	RelationshipBelongsTo = internalmodel.RelationshipBelongsTo
	RelationshipHasOne    = internalmodel.RelationshipHasOne
	RelationshipHasMany   = internalmodel.RelationshipHasMany
)
View Source
const (
	ValidationRuleMin       = internalmodel.ValidationRuleMin
	ValidationRuleMax       = internalmodel.ValidationRuleMax
	ValidationRuleMinLength = internalmodel.ValidationRuleMinLength
	ValidationRuleMaxLength = internalmodel.ValidationRuleMaxLength
	ValidationRulePattern   = internalmodel.ValidationRulePattern
)

Validation rule identifiers mirror OpenAPI keyword semantics and are emitted by the form model builder when schemas define matching constraints.

Variables

This section is empty.

Functions

func ParseUIExtensions added in v0.15.0

func ParseUIExtensions(ext map[string]any) (map[string]string, map[string]string)

ParseUIExtensions extracts metadata and UI hints from x-formgen/x-admin extensions. It returns nil maps when no supported metadata is found.

Types

type Builder

type Builder interface {
	Build(form schema.Form) (FormModel, error)
	Decorate(form *FormModel) error
}

Builder converts normalized schema forms into form models and applies optional decorators for UI schema overlays.

func NewBuilder

func NewBuilder(options ...BuilderOption) Builder

NewBuilder returns a Builder backed by the internal implementation.

type BuilderOption

type BuilderOption func(*builderOptions)

BuilderOption configures the builder behaviour.

func WithDecorators

func WithDecorators(decorators ...Decorator) BuilderOption

WithDecorators registers decorators that should run when Decorate is called.

func WithLabeler

func WithLabeler(labeler func(string) string) BuilderOption

WithLabeler overrides the default label generation function.

type Decorator

type Decorator interface {
	Decorate(*FormModel) error
}

Decorator enriches a form model with additional metadata after the canonical OpenAPI-derived structure has been built.

type DecoratorFunc

type DecoratorFunc func(*FormModel) error

DecoratorFunc adapts a function into a Decorator.

func (DecoratorFunc) Decorate

func (fn DecoratorFunc) Decorate(form *FormModel) error

Decorate calls the underlying function.

type Field

type Field = internalmodel.Field

Field mirrors internal model fields for renderer consumption.

type FieldType

type FieldType = internalmodel.FieldType

FieldType re-exports the internal FieldType enumeration.

type FormModel

type FormModel = internalmodel.FormModel

type Relationship

type Relationship = internalmodel.Relationship

Relationship exposes typed relationship metadata alongside the existing dotted keys for backward compatibility. See docs/adr/RELATIONSHIP_STRUCT_ADR.md.

type RelationshipKind

type RelationshipKind = internalmodel.RelationshipKind

RelationshipKind re-exports the relationship enum defined in docs/adr/RELATIONSHIP_STRUCT_ADR.md.

type ValidationRule

type ValidationRule = internalmodel.ValidationRule

ValidationRule represents an OpenAPI-derived constraint. Threshold-based rules encode their limit in Params["value"], pattern rules preserve the original expression in Params["pattern"], and boolean qualifiers such as exclusivity remain string typed to keep JSON snapshots deterministic.

Jump to

Keyboard shortcuts

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