Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/narazaka/json-schema-subset-dsl
Yet another JSON Schema subset DSL for Ruby
https://github.com/narazaka/json-schema-subset-dsl
json-schema ruby
Last synced: 26 days ago
JSON representation
Yet another JSON Schema subset DSL for Ruby
- Host: GitHub
- URL: https://github.com/narazaka/json-schema-subset-dsl
- Owner: Narazaka
- License: zlib
- Created: 2019-11-30T07:53:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-08T08:52:55.000Z (almost 3 years ago)
- Last Synced: 2024-04-25T09:42:32.138Z (8 months ago)
- Topics: json-schema, ruby
- Language: Ruby
- Size: 24.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Json::Schema::Subset::DSL
[![Actions Status](https://github.com/Narazaka/json-schema-subset-dsl/workflows/Ruby/badge.svg)](https://github.com/Narazaka/json-schema-subset-dsl/actions)
[![Gem Version](https://badge.fury.io/rb/json-schema-subset-dsl.svg)](https://badge.fury.io/rb/json-schema-subset-dsl)Yet another JSON Schema subset DSL.
Useful when writing a simple JSON schema.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'json-schema-subset-dsl'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install json-schema-subset-dsl
## Usage
```ruby
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
enddsl.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](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Narazaka/json-schema-subset-dsl.