ExParamsSchema.Schema.Projector (ex_params_schema v0.1.1)

Copy Markdown View Source

Converts cast values into JSON-compatible values for JSON Schema validation.

It handles dates, datetimes, enums, custom types, and nested objects and arrays.

Summary

Functions

Converts validated field values into a JSON-compatible map.

Converts a single value into a JSON-compatible value based on its type.

Functions

project(fields, parsed)

@spec project([ExParamsSchema.Definition.Field.t()], map()) :: map()

Converts validated field values into a JSON-compatible map.

Omits nil values for optional fields from the output.

iex> fields = ExParamsSchema.Definition.compile_fields!([
...>   {:published_on, :date, []},
...>   {:label, :string, [optional: true]}
...> ])
iex> ExParamsSchema.Schema.Projector.project(fields, %{published_on: ~D[2026-07-23], label: nil})
%{"published_on" => "2026-07-23"}

project_value(arg1, value)

Converts a single value into a JSON-compatible value based on its type.

iex> ExParamsSchema.Schema.Projector.project_value({:array, :date, []}, [~D[2026-07-22]])
["2026-07-22"]