/ backend / scripts / schema_doc.rb
schema_doc.rb
 1  require 'main'
 2  require 'json'
 3  require 'fileutils'
 4  include JSONModel
 5  
 6  FileUtils.mkdir_p File.join( "..", "schema_docs" )
 7  
 8  File.open( File.join( "..", "schema_docs", 'models.json' ), 'w' ) { |f| f << JSONModel.models.to_json }
 9  
10  JSONModel.models.each_pair do |k, v|
11    File.open( File.join( "..", "schema_docs", "#{k}.json" ), 'w') do |file|
12      json = v.send(:schema)
13  
14      json["required"] = []
15      json["properties"].each_pair do |k, v|
16        if v.has_key?("ifmissing")
17          json["required"] << k
18        end
19      end
20  
21      json["title"] = k
22      file << JSON.pretty_generate( json )
23    end
24  end