Class: OpenStax::Api::RepresentableSchemaPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/api/representable_schema_printer.rb

Class Method Summary collapse

Class Method Details

.json(representer, options = {}) ⇒ Object

Returns some formatted Markdown with HTML containing the JSON schema for a given representer



15
16
17
18
19
20
21
22
23
24
# File 'lib/openstax/api/representable_schema_printer.rb', line 15

def self.json(representer, options={})
  options[:include] ||= [:readable, :writeable]

  schema = json_schema(representer, options)

  json_string = JSON.pretty_generate(schema)

  "\n## Schema  {##{SecureRandom.hex(4)} .schema}\n" +
  "\n<pre class='code'>\n#{json_string}\n</pre>\n"
end

.json_schema(representer, options = {}) ⇒ Object

Returns the json schema for a representer



6
7
8
9
10
11
# File 'lib/openstax/api/representable_schema_printer.rb', line 6

def self.json_schema(representer, options = {})
  definitions = {}
  schema = json_object(representer, definitions, options)
  schema[:definitions] = definitions unless definitions.blank?
  schema
end