Class: ActiveAgent::SchemaGenerator::Builder Private
- Inherits:
-
Object
- Object
- ActiveAgent::SchemaGenerator::Builder
- Defined in:
- lib/active_agent/schema_generator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal builder class for constructing JSON Schemas from model classes.
This class handles the actual schema generation logic, supporting both ActiveRecord and ActiveModel classes with various options and configurations.
Class Method Summary collapse
-
.json_schema_from_model(model_class, options = {}) ⇒ Hash
private
Generates a JSON Schema from a model class.
Class Method Details
.json_schema_from_model(model_class, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a JSON Schema from a model class.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/active_agent/schema_generator.rb', line 124 def self.json_schema_from_model(model_class, = {}) schema = { type: "object", properties: {}, required: [], additional_properties: .fetch(:additional_properties, false) } if defined?(ActiveRecord::Base) && model_class < ActiveRecord::Base schema = build_activerecord_schema(schema, model_class, ) elsif defined?(ActiveModel::Model) && model_class.include?(ActiveModel::Model) schema = build_activemodel_schema(schema, model_class, ) else raise ArgumentError, "Model must be an ActiveRecord or ActiveModel class" end # OpenAI strict mode requires all properties to be in the required array # So we add all properties to required if strict mode is enabled schema[:required] = schema[:properties].keys.sort if [:strict] { name: [:name] || model_class.name.underscore, schema: schema, strict: [:strict] }.compact end |