Converts param type DSL definitions to JSON Schema.
Type DSL
:string → optional string
:string! → required string
:integer → optional integer
:boolean → optional boolean
:number → optional number
:object → optional object
{:string!, "desc"} → required string with description
{:array, :string} → array of strings
{{:array, :string}, "Tags"} → array with description
Summary
Functions
Strips ! from all param types, making everything optional.
Useful for update schemas where all fields should be optional.
Converts a keyword list of param definitions to a JSON Schema object.
Converts a single type spec to {json_schema_map, is_required}.
Types
@type param_type() :: :string | :string! | :integer | :integer! | :boolean | :boolean! | :number | :number! | :object | :object! | {:array, atom()} | {param_type(), String.t()}
Functions
Strips ! from all param types, making everything optional.
Useful for update schemas where all fields should be optional.
Converts a keyword list of param definitions to a JSON Schema object.
Example
iex> params_to_schema([name: :string!, id: {:string!, "Page ID"}])
%{
type: "object",
properties: %{
"name" => %{type: "string"},
"id" => %{type: "string", description: "Page ID"}
},
required: ["name", "id"]
}
@spec type_to_schema(param_type()) :: {map(), boolean()}
Converts a single type spec to {json_schema_map, is_required}.