Exdantic.JsonSchema.ReferenceStore (exdantic v0.0.2)
View SourceManages schema references and definitions for JSON Schema generation.
This module provides a stateful store for tracking schema references and their corresponding JSON Schema definitions during conversion.
Summary
Functions
Adds a JSON Schema definition for a module.
Adds a schema module reference to track for processing.
Gets all schema definitions currently stored.
Gets all module references currently tracked in the store.
Checks if a schema definition exists for a module.
Checks if a module reference is already tracked in the store.
Generates a JSON Schema reference path for a module.
Starts a new reference store process.
Stops the reference store process.
Types
Functions
Adds a JSON Schema definition for a module.
Parameters
agent
- The reference store process PIDmodule
- The module for which to store the schema definitionschema
- The JSON Schema map representation
Examples
iex> schema = %{"type" => "object", "properties" => %{}}
iex> Exdantic.JsonSchema.ReferenceStore.add_definition(store, MySchema, schema)
:ok
Adds a schema module reference to track for processing.
Parameters
agent
- The reference store process PIDmodule
- The schema module to add as a reference
Examples
iex> Exdantic.JsonSchema.ReferenceStore.add_reference(store, MySchema)
:ok
Gets all schema definitions currently stored.
Parameters
agent
- The reference store process PID
Returns
- Map of module names to their JSON Schema definitions
Examples
iex> Exdantic.JsonSchema.ReferenceStore.get_definitions(store)
%{"MySchema" => %{"type" => "object"}}
Gets all module references currently tracked in the store.
Parameters
agent
- The reference store process PID
Returns
- List of module atoms
Examples
iex> Exdantic.JsonSchema.ReferenceStore.get_references(store)
[MySchema, AnotherSchema]
Checks if a schema definition exists for a module.
Parameters
agent
- The reference store process PIDmodule
- The module to check for a definition
Returns
true
if a definition exists,false
otherwise
Examples
iex> Exdantic.JsonSchema.ReferenceStore.has_definition?(store, MySchema)
false
Checks if a module reference is already tracked in the store.
Parameters
agent
- The reference store process PIDmodule
- The module to check for
Returns
true
if the module is tracked,false
otherwise
Examples
iex> Exdantic.JsonSchema.ReferenceStore.has_reference?(store, MySchema)
true
Generates a JSON Schema reference path for a module.
Parameters
module
- The module to generate a reference path for
Returns
- JSON Schema reference string in the format "#/definitions/ModuleName"
Examples
iex> Exdantic.JsonSchema.ReferenceStore.ref_path(MySchema)
"#/definitions/MySchema"
@spec start_link() :: {:ok, pid()}
Starts a new reference store process.
Returns
{:ok, pid}
on success
Examples
iex> {:ok, store} = Exdantic.JsonSchema.ReferenceStore.start_link()
{:ok, #PID<...>}
@spec stop(pid()) :: :ok
Stops the reference store process.
Parameters
agent
- The reference store process PID
Examples
iex> {:ok, store} = Exdantic.JsonSchema.ReferenceStore.start_link()
iex> Exdantic.JsonSchema.ReferenceStore.stop(store)
:ok