View Source Instructor.JSONSchema (Instructor v0.1.0)

Summary

Functions

Generates a JSON Schema from an Ecto schema.

Traverses a tree structure of maps and lists, allowing the user to update or remove elements.

Functions

Link to this function

from_ecto_schema(ecto_schema)

View Source

Generates a JSON Schema from an Ecto schema.

Note: This will output a correct JSON Schema for the given Ecto schema, but it will not necessarily be optimal, nor support all Ecto types.

Link to this function

traverse_and_update(tree, fun, opts \\ [])

View Source

Traverses a tree structure of maps and lists, allowing the user to update or remove elements.

Parameters

  • tree: The tree structure to traverse (can be a map, list, or any other type)
  • fun: A function that takes either:
    • Just the element if include_path: false (default)
    • A tuple of {element, path} if include_path: true, where path is a list of keys to reach this element The function should return either:
    • An updated element
    • nil to remove the element
    • The original element if no changes are needed
  • opts: Optional keyword list of options
    • include_path: boolean, when true includes the path to each element in the callback (default: false)

Returns

The updated tree structure