Project

render

0.0
No commit activity in last 3 years
No release in over 3 years
Simple management of API calls.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 9.1.0
~> 10.1
~> 2.14
~> 1.17

Runtime

~> 1.7.1
>= 0
 Project Readme

Render

Render improves the way you work with APIs by dynamically modeling/requesting from JSON Schemas or Ruby equivalents thereof.

Setup

Update your Gemfile:

  gem "render"

Usage

Check out examples as part of the integration tests.

# Make requests
Render::Definition.load_from_directory!("/path/to/json/schema/dir")
Render::Graph.new("loaded-schema-id", { host: "films.local" }).render!

# Or mock data
Render.live = false
planned_schema = {
  definitions: {
    address: {
      type: Object,
      properties: {
        number: { type: Integer },
        street: { type: String }
      }
    }
  },

  type: Object,
  properties: {
    name: { type: String, minLength: 1 },
    email: { type: String, format: :email },
    sex: { type: String, enum: %w(MALE FEMALE) },
    address: { :$ref => "#/definitions/address" },
    nicknames: {
      type: Array,
      minItems: 1,
      maxItems: 1,
      items: { type: String }
    }
  }
}

mock_data = Render::Schema.new(planned_schema).render!
# {
#   :name => "name (generated)",
#   :email => "you@localhost",
#   :sex => "FEMALE",
#   :address => {
#     :number => 513948,
#     :street => "street (generated)"
#   },
#   :nicknames => ["nicknames (generated)"]
# }

Caveats/Notes/Assumptions

Render is not meant to be a validator and ignores:

  • Keywords that do not additively define schemas: not, minProperties, maxProperties, dependencies
  • Divergent responses, e.g. no errors will be raised if "abc" is returned for String with { "minLength": 4 }

It will help out, though, and defensively type response values based on definition (so you don't run into issues like "2" > 1).

Roadmap

  • links implementation as opposed to endpoint
  • Expanded keyword implementations:
    • additionalProperties, anyOf, allOf, oneOf
    • pattern/patternProperties
    • Tuples of varying types, e.g. [3, { name: "bob" }]
  • Relating to requests
    • Custom options, e.g. headers, timeouts
    • Drop-in custom requesting
  • Enhanced relationship calculation between nested Graphs
  • Enhanced $ref implementation

Contributing

  • Bugs and questions welcomed. If you know (or kind of know) what's going on:
    • Write a failing test, kudos for solving it
    • Put up a pull request