Low commit activity in last 3 years
No release in over a year
Useful when writing a simple JSON schema.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Json::Schema::Subset::DSL

Actions Status Gem Version

Yet another JSON Schema subset DSL.

Useful when writing a simple JSON schema.

Installation

Add this line to your application's Gemfile:

gem 'json-schema-subset-dsl'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json-schema-subset-dsl

Usage

options = {
  reference_name: ->(name) { name.sub(/Serializer$/, ""),
}

dsl = Json::Schema::Subset::DSL.new(options) do
  title! "Example"
  id :integer
  name :string, minLength: 1, optional: true
  items :array, optional: true do
  end
  other_names :array, optional: true do
    string!
    null!
  end
  meta :object do
    description :string
    params :array do
      ref! "#/components/schemas/Param"
    end
    opt_params :array do
      cref! "OptParamSerializer"
    end
    uuid :ref, "#/UUID", optional: true
  end
end

dsl.compile! == {
  "type" => "object",
  "properties" => {
    "id" => { "type" => "integer" },
    "name" => { "minLength" => 1, "type" => "string" },
    "items" => { "items" => { "type" => "object", "properties" => {} }, "type" => "array" },
    "other_names" => { "items" => { "type" => %w[string null] }, "type" => "array" },
    "meta" => {
      "type" => "object",
      "properties" => {
        "description" => { "type" => "string" },
        "params" => { "items" => { "$ref" => "#/components/schemas/Param" }, "type" => "array" },
        "opt_params" => { "items" => { "$ref" => "#/components/schemas/OptParam" }, "type" => "array" },
        "uuid" => { "$ref" => "#/UUID" },
      },
      "required" => %w[description params opt_params],
    },
  },
  "required" => %w[id meta],
  "title" => "Example",
}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Narazaka/json-schema-subset-dsl.