Skip to content

Commit

Permalink
add generation of json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Paret committed Jan 21, 2014
1 parent 2035c21 commit b1e1fb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.rst
Expand Up @@ -797,7 +797,8 @@ This will copy the Apipie views to ``app/views/apipie/apipies`` and
To generate a static version of documentation (perhaps to put it on
project site or something) run ``rake apipie:static`` task. It will
create set of html files (multi-pages, single-page, plain) in your doc
directory. By default the documentation for default API version is
directory. If you prefer a json version run ``rake apipie:static_json``.
By default the documentation for default API version is
used, you can specify the version with ``rake apipie:static[2.0]``

When you want to avoid any unnecessary computation in production mode,
Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/apipie.rake
Expand Up @@ -35,6 +35,16 @@ namespace :apipie do
end
end

desc "Generate static documentation json"
task :static_json, [:version] => :environment do |t, args|
with_loaded_documentation do
args.with_defaults(:version => Apipie.configuration.default_version)
out = ENV["OUT"] || File.join(::Rails.root, 'doc', 'apidoc')
doc = Apipie.to_json(args[:version])
generate_json_page(out, doc)
end
end

desc "Generate cache to avoid production dependencies on markup languages"
task :cache => :environment do
with_loaded_documentation do
Expand Down Expand Up @@ -79,6 +89,13 @@ namespace :apipie do
end
end

def generate_json_page(file_base, doc)
FileUtils.mkdir_p(file_base) unless File.exists?(file_base)

filename = 'schema_apipie.json'
File.open("#{file_base}/#{filename}", 'w') { |file| file.write(JSON.pretty_generate(doc)) }
end

def generate_one_page(file_base, doc)
FileUtils.mkdir_p(File.dirname(file_base)) unless File.exists?(File.dirname(file_base))

Expand Down

0 comments on commit b1e1fb9

Please sign in to comment.