AttestoMCP.Server.Schema (attesto_mcp_server v2.8.0)

Copy Markdown View Source

Bounded JSON Schema 2020-12 and draft-07 validation.

JSV evaluates the declared dialect, including reference scope and evaluation annotations. Network resolvers and data casting are disabled. Format assertions remain enabled for compatibility; pass formats: false to use the dialect's format annotation semantics. Defaults remain annotations unless explicitly applied.

Summary

Functions

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

Returns an exported schema root with the default dialect made explicit.

Checks that a term can be represented losslessly as JSON.

Returns the dialects accepted in an explicit $schema declaration.

Validates the original JSON instance without casting or inserting defaults.

Validates the bounded modern result variants emitted by this package.

Checks the schema's declared dialect without fetching network references.

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()

export_dialect(schema)

@spec export_dialect(term()) :: term()

Returns an exported schema root with the default dialect made explicit.

An object schema without $schema receives the canonical JSON Schema 2020-12 identifier, which is the dialect the validator already applies. An explicit $schema, a boolean schema, and every nested value are returned unchanged.

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()

max_instance_bytes()

min_allowed_instance_bytes()

supported_dialects()

@spec supported_dialects() :: [String.t()]

Returns the dialects accepted in an explicit $schema declaration.

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

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

Validates the original JSON instance without casting or inserting defaults.

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 the schema's declared dialect without fetching network references.