Kungfuig.Validator behaviour (Kungfuig v1.1.1)

View Source

Generic validator encapsulation.

Default implementation is NimbleOptions.

Example

defmodule TemperatureValidator do
  @moduledoc false

  use Kungfuig.Validator, schema: [
    city: [type: :string, required: true],
    temperature: [type: :integer, required: false]
  ]
end

Summary

Callbacks

Generates a documentation for expected options

Validates given options with the schema, provided by the implementation of this behaviour

Callbacks

doc(options)

@callback doc(options :: keyword()) :: String.t()

Generates a documentation for expected options

validate(options)

@callback validate(options :: map() | keyword()) ::
  {:ok, validated_options :: keyword()} | {:error, any()}

Validates given options with the schema, provided by the implementation of this behaviour