Skip to content

Instantly share code, notes, and snippets.

@bougyman
Created March 26, 2023 13:47
Show Gist options
  • Save bougyman/4be2401570f7a621c2fe4df7e1b219f1 to your computer and use it in GitHub Desktop.
Save bougyman/4be2401570f7a621c2fe4df7e1b219f1 to your computer and use it in GitHub Desktop.
Monkey patch to use swagger_yard with Roda (spec/swagger_yard.rb)
# frozen_string_literal: true
require 'swagger_yard'
require_relative '../lib/payments'
# Monkey Patches to Support our modules
module SwaggerYard
def self.yard_class_objects_from_file(file_path)
yard_objects_from_file(file_path, :class, :module)
end
# Opening ApiGroup to add support for controllers as modules for us
class ApiGroup
def add_yard_object(yard_object) # rubocop:disable Metrics/MethodLength
return self if yard_object.visibility == :private && !SwaggerYard.config.include_private
case yard_object.type
when :class, :module # controller
add_info(yard_object)
if valid?
yard_object.children.each do |child_object|
add_yard_object(child_object)
end
end
when :method # actions
add_path_item(yard_object)
end
self
end
end
end
SwaggerYard.configure do |config|
config.api_version = '1.0'
# Every file in payments/route_methods/**/* is a module which contains methods of our api, documented with swagger_yard tags
# These modules get included into our routes classes
config.controller_path = LIBROOT.join 'payments/route_methods/**/*'
# <SNIP> More configuration here
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment