Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
changelog:
exclude:
labels:
- ignore-for-release
- dependencies
authors:
- dependabot[bot]
categories:
- title: 🚀 New Features
labels:
- enhancement
- feature
- title: 🐛 Bug Fixes
labels:
- bug
- fix
- title: 📚 Documentation
labels:
- documentation
- title: 🔧 Other Changes
labels:
- "*"
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Create Release with Auto-Generated Notes
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: ${{ steps.release_notes.outputs.body }}
draft: false
prerelease: false
generate_release_notes: true
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ end

### Schema Definitions and References

You can define sub-schemas and reference them in other schemas.
You can define sub-schemas and reference them in other schemas, or reference the root schema to generate recursive schemas.

```ruby
class MySchema < RubyLLM::Schema
Expand All @@ -281,6 +281,13 @@ class MySchema < RubyLLM::Schema
object :user do
reference :location
end

# Using a reference to the root schema
object :ui_schema do
string :element, enum: ["input", "button"]
string :label
object :sub_schema, reference: :root
end
end
```

Expand Down
6 changes: 5 additions & 1 deletion lib/ruby_llm/schema/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ def define(name, &)
end

def reference(schema_name)
{"$ref" => "#/$defs/#{schema_name}"}
if schema_name == :root
{"$ref" => "#"}
else
{"$ref" => "#/$defs/#{schema_name}"}
end
end

# Schema building methods
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby_llm/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@
user_props = json_output[:schema][:properties][:user][:properties]
expect(user_props[:addresses][:items]).to eq({"$ref" => "#/$defs/address"})
end

it "supports reference to the root schema" do
schema_class.string :element_type, enum: ["input", "button"]
schema_class.string :label
schema_class.object :sub_schema, reference: :root

instance = schema_class.new
json_output = instance.to_json_schema

expect(json_output[:schema][:properties][:sub_schema]).to eq({"$ref" => "#"})
end
end

# ===========================================
Expand Down