Bazaar.Validator (Bazaar v0.3.0)

Copy Markdown View Source

Validates data against UCP and ACP schemas.

UCP schemas (checkout, order, profile) are validated via JSV against the bundled JSON Schema files. ACP JSON schemas (checkout_session, delegate_payment_req, etc.) are validated via JSV against bundle schemas with $defs. The OpenAI product feed is validated via an Ecto embedded schema changeset.

Note

This module requires the jsv dependency. Add {:jsv, "~> 0.15"} to your mix.exs deps to use validation features.

Usage

case Bazaar.Validator.validate_checkout(checkout_data) do
  {:ok, validated} -> # Data conforms to spec
  {:error, errors} -> # Validation errors
end

# Or use validate/2 with any schema atom
Bazaar.Validator.validate(data, :checkout_session)

Available Validators

Summary

Functions

Lists all available schemas bundled with Bazaar, grouped by protocol.

Returns the raw JSON schema for a given UCP schema name.

Validates data against a specific UCP or ACP schema.

Validates data against the UCP checkout response schema.

Validates data against the UCP order schema.

Validates a UCP discovery profile (the /.well-known/ucp response).

Functions

available_schemas()

Lists all available schemas bundled with Bazaar, grouped by protocol.

get_schema(schema_name)

Returns the raw JSON schema for a given UCP schema name.

validate(data, schema_name)

Validates data against a specific UCP or ACP schema.

UCP schemas

  • :checkout - Checkout session response
  • :order - Order response
  • :profile - Discovery profile

ACP schemas (from open ACP repo)

  • :checkout_session - Checkout session response
  • :checkout_session_with_order - Checkout session response with order
  • :checkout_create_req - Create checkout request
  • :checkout_update_req - Update checkout request
  • :checkout_complete_req - Complete checkout request
  • :cancel_session_req - Cancel session request
  • :delegate_payment_req - Delegate payment request
  • :delegate_payment_resp - Delegate payment response

ACP schemas (OpenAI-specific)

  • :openai_product_feed - Product feed

validate_checkout(data)

Validates data against the UCP checkout response schema.

Returns {:ok, data} if valid, or {:error, errors} with validation errors.

validate_order(data)

Validates data against the UCP order schema.

Returns {:ok, data} if valid, or {:error, errors} with validation errors.

validate_profile(data)

Validates a UCP discovery profile (the /.well-known/ucp response).

Returns {:ok, data} if valid, or {:error, errors} with validation errors.