Casts field defaults and validates them against the generated JSON Schema.
This internal module is used while compiling schemas.
Summary
Functions
Casts a default value to the field type and validates it with the corresponding JSON Schema.
Functions
@spec normalize!([ExParamsSchema.Definition.Field.t()], ExJsonSchema.Schema.Root.t()) :: [ ExParamsSchema.Definition.Field.t() ]
Casts a default value to the field type and validates it with the corresponding JSON Schema.
iex> fields = ExParamsSchema.Definition.compile_fields!([
...> {:count, :integer, [default: "2", minimum: 1]}
...> ])
iex> {json_schema, _errors} = ExParamsSchema.Schema.JsonSchema.build(fields, false)
iex> resolved = ExJsonSchema.Schema.resolve(json_schema)
iex> [field] = ExParamsSchema.Schema.Defaults.normalize!(fields, resolved)
iex> Keyword.fetch!(field.options, :default)
2Values that cannot be cast or do not satisfy constraints raise ArgumentError.