Packages

Spectral provides type-driven JSON encoding/decoding, JSON Schema generation, and OpenAPI 3.1 specification generation. It uses Elixir's type system to automatically handle serialization based on struct type definitions.

Current section

Files

Jump to
spectral lib person.ex
Raw

lib/person.ex

defmodule Person do
@moduledoc """
Example module demonstrating Spectral usage with nested structs.
"""
defmodule Address do
@moduledoc """
Address struct representing a person's address.
"""
defstruct [:street, :city]
@type t :: %Address{
street: String.t(),
city: String.t()
}
end
defstruct [:name, :age, :address]
@type t :: %Person{
name: String.t(),
age: non_neg_integer() | nil,
address: Address.t() | nil
}
def testdata do
%Person{name: "Alice", age: 30}
end
def testjson do
~s({"name":"Alice","age":30})
end
end