Exdantic.JsonSchema.ReferenceStore (exdantic v0.0.2)

View Source

Manages 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

state()

@type state() :: %{
  refs: MapSet.t(module()),
  definitions: %{required(String.t()) => map()}
}

Functions

add_definition(agent, module, schema)

@spec add_definition(pid(), module(), map()) :: :ok

Adds a JSON Schema definition for a module.

Parameters

  • agent - The reference store process PID
  • module - The module for which to store the schema definition
  • schema - The JSON Schema map representation

Examples

iex> schema = %{"type" => "object", "properties" => %{}}
iex> Exdantic.JsonSchema.ReferenceStore.add_definition(store, MySchema, schema)
:ok

add_reference(agent, module)

@spec add_reference(pid(), module()) :: :ok

Adds a schema module reference to track for processing.

Parameters

  • agent - The reference store process PID
  • module - The schema module to add as a reference

Examples

iex> Exdantic.JsonSchema.ReferenceStore.add_reference(store, MySchema)
:ok

get_definitions(agent)

@spec get_definitions(pid()) :: %{required(String.t()) => map()}

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"}}

get_references(agent)

@spec get_references(pid()) :: [module()]

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]

has_definition?(agent, module)

@spec has_definition?(pid(), module()) :: boolean()

Checks if a schema definition exists for a module.

Parameters

  • agent - The reference store process PID
  • module - 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

has_reference?(agent, module)

@spec has_reference?(pid(), module()) :: boolean()

Checks if a module reference is already tracked in the store.

Parameters

  • agent - The reference store process PID
  • module - The module to check for

Returns

  • true if the module is tracked, false otherwise

Examples

iex> Exdantic.JsonSchema.ReferenceStore.has_reference?(store, MySchema)
true

ref_path(module)

@spec ref_path(module()) :: String.t()

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"

start_link()

@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<...>}

stop(agent)

@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