Confispex.Schema behaviour (confispex v0.1.0)
Example
defmodule MyApp.RuntimeConfigSchema do
import Confispex.Schema
@behaviour Confispex.Schema
alias Confispex.Type
defvariables(%{
"RUNTIME_CONFIG_REPORT" => %{
cast: {Type.Enum, values: ["disabled", "detailed", "brief"]},
default: "disabled",
groups: [:misc]
},
"TZDATA_AUTOUPDATE_ENABLED" => %{
doc: "Autoupdate timezones from IANA Time Zone Database",
cast: Type.Boolean,
default: "false",
groups: [:base],
context: [env: [:dev, :prod]]
},
"LOG_LEVEL" => %{
cast:
{Type.Enum,
values: [
"emergency",
"alert",
"critical",
"error",
"warning",
"notice",
"info",
"debug",
"none"
]},
default_lazy: fn
%{env: :test} -> "warning"
%{env: :dev} -> "debug"
%{env: :prod} -> "debug"
end,
groups: [:base]
},
"DATABASE_URL" => %{
aliases: ["DB_URL"],
doc: "Full DB URL",
cast: Type.URL,
context: [env: [:prod]],
groups: [:primary_db],
required: [:primary_db]
},
"DATABASE_POOL_SIZE" => %{
aliases: ["DB_POOL_SIZE", "POOL_SIZE"],
cast: {Type.Integer, scope: :positive},
default: "10",
context: [env: [:prod]],
groups: [:primary_db]
}
})
end
Link to this section Summary
Functions
A helper which performs basic validations of the input schema and then defines variables_schema/0 function.
Link to this section Types
Link to this type
variable_name()
Specs
variable_name() :: term()
Link to this type
variable_spec()
Specs
variable_spec() :: %{
:cast => module() | {module(), opts :: keyword()},
:groups => [atom()],
optional(:doc) => String.t(),
optional(:default) => String.t(),
optional(:default_lazy) => (context :: map() -> String.t()),
optional(:required) => [atom()],
optional(:context) => [{atom(), atom()}],
optional(:aliases) => [variable_name()]
}
A spec for a single variable
:cast- describes how value should be cast.:groups- a list of groups which are affected by variable.:doc- a description about variable, shown in generated.envrcfile.:default- default value. Must be set in raw format. Raw format was choosen to populate.envrcfile with default values.:defaut_lazy- default value based on given context. Useful when default value must be different for different environments. Cannot be used alongside with:defaultparameter.:required- a list of groups in which variable is required. When all required variables of the group are cast successfully, then the group is considered as ready for using.:context- specifies context in which variable is used.:aliases- a list of alias names.
Link to this section Functions
A helper which performs basic validations of the input schema and then defines variables_schema/0 function.
Link to this section Callbacks
Link to this callback
variables_schema()
Specs
variables_schema() :: %{required(variable_name()) => variable_spec()}