Module: Raif::Concerns::JsonSchemaDefinition

Extended by:
ActiveSupport::Concern
Included in:
ModelTool, Task
Defined in:
app/models/raif/concerns/json_schema_definition.rb

Instance Method Summary collapse

Instance Method Details

#schema_for_instance(schema_name) ⇒ Object

Instance method to build schema with instance context



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/raif/concerns/json_schema_definition.rb', line 75

def schema_for_instance(schema_name)
  block = self.class.instance_variable_get(:@schema_blocks)&.[](schema_name)

  if block
    # Build schema with instance context
    builder = Raif::JsonSchemaBuilder.new
    builder.build_with_instance(self, &block)
    builder.to_schema
  elsif self.class.schema_defined?(schema_name)
    # Fall back to class-level schema (handles both static and dynamic)
    self.class.schema_for(schema_name)
  end
end