mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 19:43:44 +08:00
19089f21d2
This commit adds API documentation for the new upload endpoints related to direct + multipart external uploads. Also included is a rake task which watches the files in the spec/requests/api directory and calls a script file (spec/regenerate_swagger_docs) whenever one changes. This script runs rake rswag:specs:swaggerize and then copies the openapi.yml file over to the discourse_api_docs repo directory, and hits a script there to convert the YML to JSON so the API docs are refreshed while the server is still running. This makes the loop of making a doc change and seeing it in the local server much faster. The rake task is rake autospec:swagger
43 lines
1.4 KiB
Ruby
43 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# I like guard, don't get me wrong, but it is just not working right
|
|
# architecturally it can not do what I want it to do, this is how I want
|
|
# it to behave
|
|
|
|
desc "Run all specs automatically as needed"
|
|
task "autospec" => :environment do
|
|
require 'autospec/manager'
|
|
|
|
debug = ARGV.any? { |a| a == "d" || a == "debug" } || ENV["DEBUG"]
|
|
force_polling = ARGV.any? { |a| a == "p" || a == "polling" }
|
|
latency = ((ARGV.find { |a| a =~ /l=|latency=/ } || "").split("=")[1] || 3).to_i
|
|
|
|
if force_polling
|
|
puts "Polling has been forced (slower) - checking every #{latency} #{"second".pluralize(latency)}"
|
|
else
|
|
puts "If file watching is not working, you can force polling with: bundle exec rake autospec p l=3"
|
|
end
|
|
|
|
puts "@@@@@@@@@@@@ Running in debug mode" if debug
|
|
|
|
Autospec::Manager.run(force_polling: force_polling, latency: latency, debug: debug)
|
|
end
|
|
|
|
desc "Regenerate swagger docs on API spec change"
|
|
task "autospec:swagger" => :environment do
|
|
require 'listen'
|
|
require 'open3'
|
|
|
|
puts "Listening to changes in spec/requests/api to regenerate Swagger docs."
|
|
listener = Listen.to("spec/requests/api") do |modified, added, removed|
|
|
puts "API doc file changed."
|
|
Open3.popen3("spec/regenerate_swagger_docs") do |stdin, stdout, stderr, wait_thr|
|
|
while line = stdout.gets
|
|
puts line
|
|
end
|
|
end
|
|
end
|
|
listener.start
|
|
sleep
|
|
end
|