serializers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGoPlaygroundValidator

func NewGoPlaygroundValidator[Model any](
	rules map[string]any,
) *goPlaygroundValidator[Model]

func TransformError

func TransformError(err *jsonschema.ValidationError) map[string][]string

TransformError recursively transforms a ValidationError into a map[string][]string.

Types

type MissingSerializer

type MissingSerializer[Model any] struct {
}

func (*MissingSerializer[Model]) FromDB

func (s *MissingSerializer[Model]) FromDB(raw map[string]any, ctx *gin.Context) (models.InternalValue, error)

func (*MissingSerializer[Model]) ToInternalValue

func (s *MissingSerializer[Model]) ToInternalValue(raw map[string]any, ctx *gin.Context) (models.InternalValue, error)

func (*MissingSerializer[Model]) ToRepresentation

func (s *MissingSerializer[Model]) ToRepresentation(intVal models.InternalValue, ctx *gin.Context) (Representation, error)

type ModelSerializer

type ModelSerializer[Model any] struct {
	Fields map[string]*fields.Field[Model]
	// contains filtered or unexported fields
}

func NewModelSerializer

func NewModelSerializer[Model any]() *ModelSerializer[Model]

func (*ModelSerializer[Model]) ToInternalValue

func (s *ModelSerializer[Model]) ToInternalValue(raw map[string]any, ctx *gin.Context) (models.InternalValue, error)

func (*ModelSerializer[Model]) ToRepresentation

func (s *ModelSerializer[Model]) ToRepresentation(intVal models.InternalValue, ctx *gin.Context) (Representation, error)

func (*ModelSerializer[Model]) Validate

func (s *ModelSerializer[Model]) Validate(intVal models.InternalValue, ctx *gin.Context) error

func (*ModelSerializer[Model]) WithField

func (s *ModelSerializer[Model]) WithField(name string, updateFunc func(oldField *fields.Field[Model])) *ModelSerializer[Model]

func (*ModelSerializer[Model]) WithModelFields

func (s *ModelSerializer[Model]) WithModelFields(passedFields []string) *ModelSerializer[Model]

func (*ModelSerializer[Model]) WithNewField

func (s *ModelSerializer[Model]) WithNewField(field *fields.Field[Model]) *ModelSerializer[Model]

type Representation

type Representation map[string]any

type Serializer

type Serializer interface {
	ToInternalValue(map[string]any, *gin.Context) (models.InternalValue, error)
	ToRepresentation(models.InternalValue, *gin.Context) (Representation, error)
}

type ValidatingSerializer

type ValidatingSerializer[Model any] struct {
	// contains filtered or unexported fields
}

func NewValidatingSerializer

func NewValidatingSerializer[Model any](child Serializer, validator ...Validator) *ValidatingSerializer[Model]

func (*ValidatingSerializer[Model]) AddValidator

func (s *ValidatingSerializer[Model]) AddValidator(validator Validator) *ValidatingSerializer[Model]

func (*ValidatingSerializer[Model]) ToInternalValue

func (s *ValidatingSerializer[Model]) ToInternalValue(raw map[string]any, ctx *gin.Context) (models.InternalValue, error)

func (*ValidatingSerializer[Model]) ToRepresentation

func (s *ValidatingSerializer[Model]) ToRepresentation(intVal models.InternalValue, ctx *gin.Context) (Representation, error)

type ValidationError

type ValidationError struct {
	FieldErrors map[string][]string
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

Uses string builder to build error message

type Validator

type Validator interface {
	Validate(models.InternalValue) error
}

func NewJSONSchemaValidator

func NewJSONSchemaValidator(rawSchema map[string]any) Validator

func NewSimpleValidator

func NewSimpleValidator(validateFunc func(models.InternalValue) error) Validator

Jump to

Keyboard shortcuts

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