put spec assembly into independent script

as in it doesn't require bundling or a database
conncetion as opposed to a rake task
pull/9421/head
Markus Kahl 3 years ago
parent 31588fa25a
commit d39609a41d
  1. 20
      lib/tasks/api.rake
  2. 28
      script/api/spec

@ -45,24 +45,4 @@ namespace :api do
puts "#{method} #{path}"
end
end
desc 'Saves the complete API spec (OAS 3.0) as a single json (default) or YAML file.'
task save_spec: [:environment] do
if ARGV.size != 2
$stderr.puts "usage: rake api:save_spec <file-name>"
exit 1
end
file_name = ARGV.last
format = (file_name =~ /\.ya?ml\Z/i) ? :yml : :json
spec = API::OpenAPI.spec
File.open(file_name, "w") do |f|
if format == :yml
f.puts spec.to_yaml
else
f.puts spec.to_json
end
end
end
end

@ -0,0 +1,28 @@
#!/usr/bin/env ruby
if ARGV.join(" ") =~ /((\-h)|(\-\-help))/
puts "Prints the self-contained OpenAPI 3.0 specification of OpenProject's APIv3"
puts
puts "usage: ./scripts/api/spec [--format JSON|yaml]"
return
end
require 'pathname'
require 'yaml'
require 'json'
require './lib/api/open_api.rb'
path = Pathname(__dir__).join("../../docs/api/apiv3/openapi-spec.yml")
spec = API::OpenAPI.assemble_spec path
format = ARGV.join(" ") =~ /((\-\-format)|(\-f))((=)|(\s+))ya?ml/ ? :yaml : :json
begin
if format == :yaml
puts spec.to_yaml
else
puts spec.to_json
end
rescue Errno::EPIPE
# `head` for instance closes the pipe when it has what it needs
end
Loading…
Cancel
Save