discourse/lib/tasks/api_docs.rake
Kelv daac912405
DEV: add api docs for discourse-calendar events index endpoint (#35400)
This creates an overriding `rswag:specs:swaggerize` rake task that also
adds plugin paths, and updates spec helpers to handle plugin paths.

Also adds the spec files for the discourse-calendar events index
endpoint.

### Testing

Running `rake rswag:specs:swaggerize` now generates the same
`openapi/openapi.yaml` file, with `/discourse-post-event/events.ics` and
`/discourse-post-event/events.json` GET documentation.
2025-10-16 07:39:08 +08:00

34 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
require "rspec/core/rake_task"
# Override the default rswag:specs:swaggerize task to include plugin API specs
namespace :rswag do
namespace :specs do
# Clear the existing task so we can redefine it
Rake::Task["rswag:specs:swaggerize"].clear if Rake::Task.task_defined?("rswag:specs:swaggerize")
desc "Generate Swagger JSON files from integration specs (including plugins)"
RSpec::Core::RakeTask.new("swaggerize") do |t|
# Automatically load plugins for API documentation
ENV["LOAD_PLUGINS"] = "1" unless ENV["LOAD_PLUGINS"]
# Include plugin API specs in the pattern
t.pattern =
ENV.fetch(
"PATTERN",
"spec/requests/**/*_spec.rb, spec/api/**/*_spec.rb, spec/integration/**/*_spec.rb, plugins/*/spec/requests/api/*_spec.rb",
)
additional_rspec_opts = ENV.fetch("ADDITIONAL_RSPEC_OPTS", "")
t.rspec_opts = [additional_rspec_opts]
if Rswag::Specs.config.rswag_dry_run
t.rspec_opts += ["--format Rswag::Specs::SwaggerFormatter", "--dry-run", "--order defined"]
else
t.rspec_opts += ["--format Rswag::Specs::SwaggerFormatter", "--order defined"]
end
end
end
end