项目作者: Narazaka

项目描述 :
Yet another JSON Schema subset DSL for Ruby
高级语言: Ruby
项目地址: git://github.com/Narazaka/json-schema-subset-dsl.git
创建时间: 2019-11-30T07:53:21Z
项目社区:https://github.com/Narazaka/json-schema-subset-dsl

开源协议:zlib License

下载


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:

  1. gem 'json-schema-subset-dsl'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install json-schema-subset-dsl

Usage

  1. options = {
  2. reference_name: ->(name) { name.sub(/Serializer$/, ""),
  3. }
  4. dsl = Json::Schema::Subset::DSL.new(options) do
  5. title! "Example"
  6. id :integer
  7. name :string, minLength: 1, optional: true
  8. items :array, optional: true do
  9. end
  10. other_names :array, optional: true do
  11. string!
  12. null!
  13. end
  14. meta :object do
  15. description :string
  16. params :array do
  17. ref! "#/components/schemas/Param"
  18. end
  19. opt_params :array do
  20. cref! "OptParamSerializer"
  21. end
  22. uuid :ref, "#/UUID", optional: true
  23. end
  24. end
  25. dsl.compile! == {
  26. "type" => "object",
  27. "properties" => {
  28. "id" => { "type" => "integer" },
  29. "name" => { "minLength" => 1, "type" => "string" },
  30. "items" => { "items" => { "type" => "object", "properties" => {} }, "type" => "array" },
  31. "other_names" => { "items" => { "type" => %w[string null] }, "type" => "array" },
  32. "meta" => {
  33. "type" => "object",
  34. "properties" => {
  35. "description" => { "type" => "string" },
  36. "params" => { "items" => { "$ref" => "#/components/schemas/Param" }, "type" => "array" },
  37. "opt_params" => { "items" => { "$ref" => "#/components/schemas/OptParam" }, "type" => "array" },
  38. "uuid" => { "$ref" => "#/UUID" },
  39. },
  40. "required" => %w[description params opt_params],
  41. },
  42. },
  43. "required" => %w[id meta],
  44. "title" => "Example",
  45. }

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.