model

package
v0.0.0-...-b554ef6 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package model contains the data models for the Mason API.

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyEmpty = errors.New("body empty")

ErrBodyEmpty occurs when the body of the reponse was empty.

Functions

func IsJSONFieldError

func IsJSONFieldError(err error) bool

IsJSONFieldError checks if an error of type FieldErrors exists.

func New

func New[T any]() T

func SortErrors

func SortErrors(e *ValidationError)

func Validate

func Validate(schema []byte, body []byte) error

Validate validates the provided model against it's declared tags.

Types

type DerivedType

type DerivedType interface {
	Unwrap() WithSchema
}

type Entity

type Entity interface {
	WithSchema
	Serializable
}

Entity is a domain model that can be serialized and has a schema. The term comes from Domain-Driven Design (DDD).

type FieldError

type FieldError struct {
	Message string `json:"message"`
	// contains filtered or unexported fields
}

FieldError is used to indicate an error with a specific request field.

func (FieldError) Details

func (fe FieldError) Details() map[string]interface{}

func (FieldError) Field

func (fe FieldError) Field() string

type Nil

type Nil struct{}

Nil is a model that represents an empty object.

func (Nil) Example

func (n Nil) Example() []byte

func (Nil) Marshal

func (n Nil) Marshal() (json.RawMessage, error)

func (Nil) Name

func (n Nil) Name() string

func (Nil) Schema

func (n Nil) Schema() []byte

func (Nil) Unmarshal

func (n Nil) Unmarshal(data json.RawMessage) error

type Serializable

type Serializable interface {
	Marshal() (json.RawMessage, error)
	Unmarshal(data json.RawMessage) error
}

Serializable is an interface for serializing and deserializing data. Serializble is used for data types sent and received over the wire.

type ValidationError

type ValidationError struct {
	Errors []FieldError `json:"errors"`
}

ValidationError represents a collection of field errors.

func ToValidationError

func ToValidationError(result *gojsonschema.Result) ValidationError

func (ValidationError) Error

func (fe ValidationError) Error() string

Error implements the error interface on FieldErrors.

type WithName

type WithName interface {
	Name() string
}

WithName is an interface for defining a name for a data type. The name is used for generating API documentation and for uniquely identifying the data type.

type WithSchema

type WithSchema interface {
	WithName
	Schema() []byte
	Example() []byte
}

WithSchema is an interface for defining a schema and example data for a data type. The schema is used for validating data and for generating API documentation, along with the example data.

Directories

Path Synopsis
Package sync provides utilities for vetting models against their declared schemas.
Package sync provides utilities for vetting models against their declared schemas.

Jump to

Keyboard shortcuts

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