Module: ActiveAgent::SchemaGenerator::ActiveRecordClassMethods

Defined in:
lib/active_agent/schema_generator.rb

Overview

Class methods added to ActiveRecord models.

Instance Method Summary collapse

Instance Method Details

#to_json_schema(options = {}) ⇒ Hash

Generates a JSON Schema representation of the ActiveRecord model.

Examples:

Basic schema generation

User.to_json_schema

Exclude specific fields

User.to_json_schema(exclude: [:password_digest, :created_at])

Include associations

User.to_json_schema(include_associations: true, nested_associations: true)

OpenAI strict mode

User.to_json_schema(strict: true, name: "user")

Parameters:

  • options (Hash) (defaults to: {})

    Options for schema generation

Options Hash (options):

  • :exclude (Array<Symbol>)

    Attributes to exclude from the schema

  • :include_id (Boolean) — default: false

    Whether to include the id field

  • :include_associations (Boolean) — default: false

    Whether to include associations

  • :exclude_associations (Array<Symbol>)

    Associations to exclude

  • :nested_associations (Boolean) — default: false

    Whether to include nested association schemas

  • :strict (Boolean) — default: false

    Enable OpenAI strict mode (requires all properties)

  • :name (String)

    Custom name for the schema (used with strict mode)

  • :additional_properties (Boolean) — default: false

    Allow additional properties in the schema

Returns:

  • (Hash)

    JSON Schema representation of the model



79
80
81
# File 'lib/active_agent/schema_generator.rb', line 79

def to_json_schema(options = {})
  ActiveAgent::SchemaGenerator::Builder.json_schema_from_model(self, options)
end