No commit activity in last 3 years
No release in over 3 years
A DSL for generating JSON Schemas
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.1.0
~> 1.2.1
~> 1.1.0
~> 1.7.5
~> 1.0.9
~> 0.9.2
~> 0.8.8
~> 2.11.0
 Project Readme

SexyJSONSchemas

A DSL for generating JSON Schemas.

Based on draft 3 of the zyp-json-schema.

Installation

Add this line to your application's Gemfile:

gem 'sexy_json_schemas'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sexy_json_schemas

Usage

A simple customer schema:

module Api::V1::Schemas
  module Customer
    include SexyJSONSchemas
    extend self

    def schema_name
      "customer"
    end

    schema "customer" do
      integer_property "id", :minimum => 0, :required => true
      string_property "email", :required => true
      string_property "fullname", :required => true
      string_property "created_at", :required => true, :format => "date-time"
      string_property "updated_at", :required => true, :format => "date-time"
      string_property "logged_in_at", :format => "date-time"
      string_property "phone"
      ref_property "store_credit", "https://apitest-api.crystalcommerce.com/v1/schemas/money#"
      string_property "notes"
      string_property "locale"
      string_property "membership_number"
    end
  end
end

And the call to Api::V1::Schemas::Customer.as_json will generate a schema like:

{
  "name": "customer",
  "type": "object",
  "properties": {
    "customer": {
      "type": "object",
      "properties": {
        "created_at": {
          "required": true,
          "format": "date-time",
          "type": "string"
        },
        "dynamic_attributes": {
          "type": "object",
          "properties": {
            
          }
        },
        "notes": {
          "type": "string"
        },
        "store_credit": {
          "$ref": "https:\/\/apitest-api.crystalcommerce.com\/v1\/schemas\/money#"
        },
        "updated_at": {
          "required": true,
          "format": "date-time",
          "type": "string"
        },
        "fullname": {
          "required": true,
          "type": "string"
        },
        "id": {
          "required": true,
          "type": "integer",
          "minimum": 0
        },
        "phone": {
          "type": "string"
        },
        "logged_in_at": {
          "format": "date-time",
          "type": "string"
        },
        "locale": {
          "type": "string"
        },
        "membership_number": {
          "type": "string"
        },
        "email": {
          "required": true,
          "type": "string"
        }
      }
    }
  }
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

sexy_json_schemas is released under the MIT License.