diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..1ab7d5c --- /dev/null +++ b/.github/release.yml @@ -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: + - "*" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5ed0789 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/README.md b/README.md index ac924da..7091e0b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/lib/ruby_llm/schema/dsl.rb b/lib/ruby_llm/schema/dsl.rb index d7b9489..5f315c0 100644 --- a/lib/ruby_llm/schema/dsl.rb +++ b/lib/ruby_llm/schema/dsl.rb @@ -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 diff --git a/spec/ruby_llm/schema_spec.rb b/spec/ruby_llm/schema_spec.rb index 19817e3..734fafd 100644 --- a/spec/ruby_llm/schema_spec.rb +++ b/spec/ruby_llm/schema_spec.rb @@ -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 # ===========================================