AgentBlueprintProtocol.Schema (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

This module parses bounded schemas and validates tagged JSON instances.

Use it when validating a schema document or an instance against a supported dialect.

This module does not authorize operations.

Example

{:ok, schema_value} = AgentBlueprintProtocol.Json.decode(~s({"type":"string"}))
{:ok, schema} =
  AgentBlueprintProtocol.Schema.parse(
    schema_value,
    AgentBlueprintProtocol.Schema.dialect()
  )
AgentBlueprintProtocol.Schema.validate_instance(
  schema,
  {:string, "ready"},
  AgentBlueprintProtocol.Schema.dialect()
)

Summary

Types

t()

The public data type for AgentBlueprintProtocol.Schema.

Functions

Returns the maximum schema complexity accepted by this module.

Returns the complexity measure for a schema value.

Returns the schema dialect supported by this module.

Compares two values for equality under this module’s rules.

Parses a schema document for the requested dialect.

Validates a tagged JSON instance against a schema.

Types

t()

(since 1.0.0)
@type t() :: %AgentBlueprintProtocol.Schema{
  complexity: non_neg_integer(),
  dialect: binary(),
  pointers: pointers(),
  root: AgentBlueprintProtocol.Json.value()
}

The public data type for AgentBlueprintProtocol.Schema.

Functions

ceiling()

(since 1.0.0)
@spec ceiling() :: pos_integer()

Returns the maximum schema complexity accepted by this module.

Example

AgentBlueprintProtocol.Schema.ceiling()

complexity(value)

(since 1.0.0)

Returns the complexity measure for a schema value.

Example

AgentBlueprintProtocol.Schema.complexity({:object, [{"ready", {:boolean, true}}]})

dialect()

(since 1.0.0)
@spec dialect() :: binary()

Returns the schema dialect supported by this module.

Example

AgentBlueprintProtocol.Schema.dialect()

equal?(arg1, arg2)

(since 1.0.0)

Compares two values for equality under this module’s rules.

Example

AgentBlueprintProtocol.Schema.equal?({:integer, 1}, {:float, 1.0})

parse(value, dialect)

(since 1.0.0)
@spec parse(AgentBlueprintProtocol.Json.value(), binary()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}

Parses a schema document for the requested dialect.

Example

{:ok, schema_value} = AgentBlueprintProtocol.Json.decode(~s({"type":"string"}))

match?(
  {:ok, %AgentBlueprintProtocol.Schema{}},
  AgentBlueprintProtocol.Schema.parse(
    schema_value,
    AgentBlueprintProtocol.Schema.dialect()
  )
)

validate_instance(schema, instance, dialect)

(since 1.0.0)

Validates a tagged JSON instance against a schema.

Example

{:ok, schema_value} = AgentBlueprintProtocol.Json.decode(~s({"type":"string"}))
{:ok, schema} =
  AgentBlueprintProtocol.Schema.parse(
    schema_value,
    AgentBlueprintProtocol.Schema.dialect()
  )

AgentBlueprintProtocol.Schema.validate_instance(
  schema,
  {:string, "ready"},
  AgentBlueprintProtocol.Schema.dialect()
)