CommandedAggregateless.StructValidation (commanded_aggregateless v1.0.0)

Copy Markdown

Provides a default validate/1 function for structs using Vex

Summary

Functions

Builds a new struct with the given attributes and type then validates it using Vex

Validates the given struct using Vex

Types

struct(type)

@type struct(type) :: %{:__struct__ => type, optional(atom()) => any()}

validation_result(struct_type)

@type validation_result(struct_type) ::
  CommandedAggregateless.result(
    struct_type,
    CommandedAggregateless.StructValidation.ValidationError.t()
  )

Functions

new(attrs, struct_type)

@spec new(Enum.t() | struct(type), type) ::
  CommandedAggregateless.result(
    struct(type),
    CommandedAggregateless.StructValidation.ValidationError.t()
  )
when type: atom()

Builds a new struct with the given attributes and type then validates it using Vex

Returns {:ok, struct} if the struct is valid, otherwise {:error, errors} where errors is a keyword list with keys being the invalid fields and the values being keyword lists of the validation errors for that field.

validate(data)

@spec validate(struct_type) :: validation_result(struct_type)
when struct_type: struct()

Validates the given struct using Vex

Returns {:ok, struct} if the struct is valid, otherwise {:error, errors} where errors is a keyword list with keys being the invalid fields and the values being keyword lists of the validation errors for that field.