mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 05:09:20 +08:00
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.
31 lines
710 B
Ruby
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
|