Class: OpenStax::Api::RepresentableSchemaPrinter
- Inherits:
-
Object
- Object
- OpenStax::Api::RepresentableSchemaPrinter
- Defined in:
- lib/openstax/api/representable_schema_printer.rb
Class Method Summary collapse
-
.json(representer, options = {}) ⇒ Object
Returns some formatted Markdown with HTML containing the JSON schema for a given representer.
-
.json_schema(representer, options = {}) ⇒ Object
Returns the json schema for a representer.
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, ={}) [:include] ||= [:readable, :writeable] schema = json_schema(representer, ) 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, = {}) definitions = {} schema = json_object(representer, definitions, ) schema[:definitions] = definitions unless definitions.blank? schema end |