Documentation
¶
Overview ¶
Package schema is part of the GoFastr framework. See https://github.com/DonaldMurillo/gofastr for documentation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONSchema ¶
JSONSchema generates a JSON Schema draft-07 object from a slice of Field definitions. The returned map can be marshaled directly to JSON.
Types ¶
type AutoGenerate ¶
type AutoGenerate int
AutoGenerate controls how a field value is automatically produced server-side.
const ( AutoNone AutoGenerate = iota // not auto-generated AutoUUID // UUID v4 AutoTimestamp // current RFC 3339 timestamp AutoIncrement // auto-incrementing integer )
type Field ¶
type Field struct {
Name string // field name (must be unique within a Schema)
Type FieldType // field type
Required bool // value must be present and non-zero
Unique bool // value must be unique across entities
Default any // default value when omitted
AutoGenerate AutoGenerate // server-side auto-generation strategy
ReadOnly bool // excluded from create/update request bodies
Hidden bool // excluded from API responses
Max *float64 // upper bound (numeric max / string max-length)
Min *float64 // lower bound (numeric min / string min-length)
Pattern string // regex pattern for string validation
Values []string // allowed values for Enum
To string // target entity name for Relation
Many bool // has-many relation flag
RawType string // explicit SQL column type, overrides Type→SQL mapping (e.g. "NUMERIC(10,2)", "INET")
}
Field defines a single field in an entity schema.
type FieldType ¶
type FieldType int
FieldType enumerates all supported field types in a GoFastr entity schema.
const ( String FieldType = iota // short string Text // long text / textarea Int // integer Float // floating point Decimal // fixed-precision decimal (stored as string) Bool // boolean Enum // one of a fixed set of strings UUID // UUID v4 identifier Timestamp // RFC 3339 timestamp Date // calendar date (2006-01-02) JSON // arbitrary JSON blob Relation // reference to another entity Image // image URL or path File // file URL or path )
type Schema ¶
type Schema struct {
Fields []Field
}
Schema is an ordered collection of Fields with convenience helpers.
func (Schema) AutoGeneratedFields ¶
AutoGeneratedFields returns fields that are auto-generated server-side.
func (Schema) FieldByName ¶
FieldByName returns the field with the given name and true, or the zero Field and false if not found.
func (Schema) RequiredFields ¶
RequiredFields returns only the required fields.
func (Schema) VisibleFields ¶
VisibleFields returns fields that are included in API responses (not hidden).
func (Schema) WritableFields ¶
WritableFields returns fields that can be set by the client (not auto-generated, not read-only).
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors map[string][]string // field name → list of error messages
}
ValidationResult holds the outcome of validating a full map of values.
func ValidateAll ¶
func ValidateAll(s Schema, values map[string]any) ValidationResult
ValidateAll validates a map of values against every Field in the Schema. Unknown keys are ignored; missing required fields produce errors.
func ValidatePartial ¶
func ValidatePartial(s Schema, values map[string]any) ValidationResult
ValidatePartial validates only the fields that are present in `values`. Missing fields — required or not — are not reported. Use this for partial-update flows (PUT/PATCH with only the fields the caller wants to change) so a sparse update doesn't fail because some other required field happens not to be in the body.