examples/inline_schema.exs
defmodule InlinePerson do
use AutoStruct.JsonSchema,
schema: """
{
"type": "object",
"additionalProperties": false,
"properties": {
"first_name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["first_name"]
}
"""
end
{:ok, person} = InlinePerson.new(first_name: "Ada", age: 36)
json = InlinePerson.to_json(person)
{:ok, ^person} = InlinePerson.from_json(json)
IO.inspect(person, label: "validated struct")
IO.inspect(JSON.encode!(json), label: "encoded JSON")