v0.4.0
Support for Dependencies and Conditionals
Adds given, dependent, and inline requires: DSL methods for expressing JSON Schema conditionals and dependencies.
requires: inline property dependencies
Maps to dependentRequired. The simplest form for "if this property is present, require those":
class PaymentSchema < RubyLLM::Schema
number :credit_card, required: false, requires: %i[billing_address cvv]
string :billing_address, required: false
string :cvv, required: false
enddependent property dependencies with validations
Use a block when you need validates, upgrades output to dependentSchemas:
dependent :credit_card do
requires :billing_address
validates :billing_address, type: :string, min_length: 1
endgiven if/then/else
Condition values are auto-coerced: strings → const, arrays → enum, regexps → pattern, hashes → raw schema.
class ShippingSchema < RubyLLM::Schema
boolean :domestic
string :state, required: false
string :country, required: false
given domestic: true do
requires :state
otherwise do
requires :country
end
end
endAll three propagate through nested schemas via of: and define/$defs.
Thanks to @marcoroth for his PR #31
Changelog
- 7ea8076 Updated badges
- 2c5629e Add support for Dependencies and Conditionals (#31)
- 1e2608c Bump version to 0.4.0
Full Changelog: v0.3.1...v0.4.0