View Source Ostara (Ostara v0.4.4)
Ostara
transforms Ecto schema
modules into JSON Schema structures.
example
Example
Given the following schema module:
defmodule Product do
@moduledoc "A product from Acme's catalog",
use Ecto.Schema
@primary_key false
embedded_schema do
field :product_name, :string
field :price, :float
end
def changeset(data, params) do
data
|> cast(params, [:product_name, :price])
|> validate_required([:product_name])
|> validate_number(:price, greater_than: 0)
end
end
transmute/1
will produce the following map:
%{
"$schema" => "https://json-schema.org/draft/2020-12/schema",
"title" => "Product",
"type" => "object",
"description" => "A product from Acme's catalog",
"properties" => %{
"productName" => %{
"type" => "string"
},
"price" => %{
"type" => "number",
"exclusiveMinimum" => 0
}
},
"required" => ["productName"]
}
Link to this section Summary
Functions
Produces a JSON Schema based on the given source
module.
Link to this section Functions
Produces a JSON Schema based on the given source
module.
options
Options
:format
- If:json
, returns the data as pretty-printed JSON