module ApiRegulator class Webhook attr_reader :event_name, :description, :params, :responses, :examples, :tags, :title def initialize(event_name, desc: nil, title: nil, tags: [], &block) @event_name = event_name @description = desc @title = title @tags = tags @params = [] @responses = {} instance_eval(&block) if block_given? end def param(name, type = nil, item_type: nil, desc: "", location: :body, **options, &block) param = Param.new(name, type, item_type: item_type, desc: desc, location: location, **options, &block) @params << param end def ref(ref_name, except: [], only: []) shared_schema = ApiRegulator.shared_schema(ref_name) raise "Shared schema #{ref_name} not found" unless shared_schema # Filter parameters based on `only` or `except` options filtered_params = shared_schema.params if only.any? filtered_params = filtered_params.select { |param| only.include?(param.name) } elsif except.any? filtered_params = filtered_params.reject { |param| except.include?(param.name) } end filtered_params.each do |shared_param| @params << shared_param end end def response(status_code, description, &block) @responses[status_code] = Param.new(:root, :object, desc: description, &block) end def example(name, value, default: false) @examples ||= {} @examples[name] = { summary: "#{name} Example", value: value } @default_example = value if default end end class << self def webhook_definitions @webhook_definitions ||= [] end def reset_webhook_definitions @webhook_definitions = [] end end end