discourse/spec/requests/api/schemas/schema_loader.rb
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

31 lines
710 B
Ruby

# frozen_string_literal: true
require "json"
module SpecSchemas
class SpecLoader
def initialize(filename)
@filename = filename
end
def load
path = find_schema_file
raise "Schema file not found: #{@filename}.json" unless path
JSON.parse(File.read(path))
end
private
def find_schema_file
# Search plugin directories first
plugin_paths =
Dir.glob(Rails.root.join("plugins/*/spec/requests/api/schemas/json/#{@filename}.json"))
return plugin_paths.first if plugin_paths.any?
# Fall back to core
core_path = File.join(__dir__, "json", "#{@filename}.json")
File.exist?(core_path) ? core_path : nil
end
end
end