Module: ActiveAgent::SchemaGenerator

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_agent/schema_generator.rb

Overview

Provides automatic JSON Schema generation from ActiveRecord and ActiveModel classes.

This module can be included in any ActiveRecord or ActiveModel class to add the ability to generate JSON Schema representations. The generated schemas can be used for API documentation, validation, or as input to AI models that support structured outputs.

Examples:

Basic usage with ActiveRecord

class User < ApplicationRecord
  include ActiveAgent::SchemaGenerator
end

User.to_json_schema
# => { type: "object", properties: { ... }, required: [...] }

With options

User.to_json_schema(
  exclude: [:password_digest],
  include_associations: true,
  strict: true
)

ActiveModel usage

class ContactForm
  include ActiveModel::Model
  include ActiveAgent::SchemaGenerator

  attribute :name, :string
  attribute :email, :string
  attribute :message, :text
end

ContactForm.to_json_schema

See Also:

Defined Under Namespace

Modules: ActiveModelClassMethods, ActiveRecordClassMethods Classes: Builder

Instance Method Summary collapse

Instance Method Details

#generate_schema_view(model_class, options = {}) ⇒ String

Deprecated.

This method may be removed in future versions. Use the class method ‘to_json_schema` instead.

Generates a JSON string representation of a model’s schema.

This is an instance method that can be used to generate schema views for individual model instances, though it operates on the class level.

Parameters:

Returns:

  • (String)

    JSON string representation of the schema



427
428
429
430
# File 'lib/active_agent/schema_generator.rb', line 427

def generate_schema_view(model_class, options = {})
  schema = ActiveAgent::SchemaGenerator::Builder.json_schema_from_model(model_class, options)
  schema.to_json
end