Module: Croods::Api

Defined in:
lib/croods/api.rb

Class Method Summary collapse

Class Method Details

.initial_schemaObject



6
7
8
# File 'lib/croods/api.rb', line 6

def initial_schema
  File.read(File.expand_path('api/initial_schema.json', __dir__))
end

.json_schemaObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/croods/api.rb', line 10

def json_schema
  schema = JSON.parse(initial_schema)

  Croods.resources.each do |resource|
    next unless resource.table_exists?

    name = resource.resource_name
    schema['definitions'][name] = resource.json_schema
    schema['properties'][name] = resource.ref
  end

  schema.deep_stringify_keys!
  Committee::Drivers::HyperSchema::Driver.new.parse(schema)
end