AttestoMCP.Server.Schema (attesto_mcp_server v0.14.0)

Copy Markdown View Source

Bounded JSON Schema 2020-12 validation without remote reference fetching.

Summary

Functions

Applies bounded, direct JSON Schema property defaults and validates the result.

Returns the secure default JSON value budget.

Checks that a term can be represented losslessly as JSON.

Returns the maximum configurable JSON value budget.

Returns the secure default byte budget used for bounded JSON values.

Returns the minimum configurable JSON value budget.

Validates the original JSON-compatible instance against a bounded subset.

Validates the bounded modern result variants emitted by this package.

Checks a schema without validating an instance. No network references are fetched.

Functions

apply_property_defaults(value, schema, opts \\ [])

@spec apply_property_defaults(map(), map() | boolean(), keyword()) ::
  {:ok, map()} | {:error, term()}

Applies bounded, direct JSON Schema property defaults and validates the result.

Only defaults reached through literal properties entries are applied. The helper recurses into existing object properties and objects supplied by an explicit property default. It does not infer defaults through references, combinators, conditionals, array items, or pattern properties, and it never creates an absent parent object unless that property declares its own default.

Presence is determined with Map.has_key?/2, so nil, false, zero, and an empty string are never replaced. At most 500 defaults are applied, and the completed value must satisfy the normal depth, node, byte, and schema bounds. Server dispatch never calls this helper automatically.

default_instance_bytes()

@spec default_instance_bytes() :: pos_integer()

Returns the secure default JSON value budget.

json_value(value, opts \\ [])

@spec json_value(
  term(),
  keyword()
) :: :ok | {:error, :not_json}

Checks that a term can be represented losslessly as JSON.

max_allowed_instance_bytes()

@spec max_allowed_instance_bytes() :: pos_integer()

Returns the maximum configurable JSON value budget.

max_instance_bytes()

@spec max_instance_bytes() :: pos_integer()

Returns the secure default byte budget used for bounded JSON values.

min_allowed_instance_bytes()

@spec min_allowed_instance_bytes() :: pos_integer()

Returns the minimum configurable JSON value budget.

validate(value, schema, opts \\ [])

@spec validate(term(), term(), keyword()) :: :ok | {:error, term()}

Validates the original JSON-compatible instance against a bounded subset.

JSON Schema default values are annotations and are never inserted by this function. Hosts that explicitly want direct property defaults can call apply_property_defaults/2 before invoking a handler.

validate_modern_result(result, opts \\ [])

@spec validate_modern_result(
  map(),
  keyword()
) :: :ok | {:error, term()}

Validates the bounded modern result variants emitted by this package.

validate_schema(schema, opts \\ [])

@spec validate_schema(
  term(),
  keyword()
) :: :ok | {:error, term()}

Checks a schema without validating an instance. No network references are fetched.