Methods
- D
- I
Included Modules
Constants
PATH_IGNORES | = | ["Rhino::OpenApiInfo", "Rhino::InfoGraph"].freeze |
RESPONSE_CODES | = | [200, 400, 403, 422].freeze |
SUCCESS_CODES | = | [200].freeze |
Class Public methods
describe()
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 13 def self.describe 14 nil 15 end
describe_info()
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 98 def self.describe_info 99 { 100 title: "#{Rails.application.class.module_parent_name} API", 101 version: '0.0.0', 102 'x-rhino': { 103 modules: Rhino.registered_modules 104 } 105 } 106 end
describe_parameter(param)
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 32 def self.describe_parameter(param) 33 { 34 name: param, 35 in: "path", 36 required: true 37 } 38 end
describe_path(path)
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 59 def self.describe_path(path) # rubocop:todo Metrics/AbcSize 60 new_path = path.index_by { |p| p[:verb].downcase.to_sym } 61 new_path.transform_values! do |verb_values| 62 klass = verb_values[:rhino_resource].constantize 63 64 verb_info = { 65 operationId: "#{klass.model_name.singular}-#{verb_values[:action]}", 66 parameters: verb_values[:required_names].map { |param| describe_parameter(param) }, 67 responses: describe_path_responses(klass), 68 tags: [klass.model_name.singular] 69 } 70 71 verb_info 72 end 73 74 new_path 75 end
describe_path_content(klass, code)
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 43 def self.describe_path_content(klass, code) 44 { 45 'application/json': 46 ({ schema: { "$ref": "#/components/schemas/#{klass.model_name.singular}" } } if SUCCESS_CODES.include?(code)) || {} 47 } 48 end
describe_path_responses(klass)
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 50 def self.describe_path_responses(klass) 51 RESPONSE_CODES.index_with do |code| 52 { 53 description: Rack::Utils::HTTP_STATUS_CODES[code], 54 content: describe_path_content(klass, code) 55 } 56 end 57 end
describe_paths()
Link
Source: show
# File rhino/rhino/app/resources/rhino/open_api_info.rb 78 def self.describe_paths # rubocop:todo Metrics/AbcSize 79 routes = Rails.application.routes.routes 80 81 # Extract the path information we need 82 paths = routes.map { |r| r.defaults.merge(verb: r.verb, path: r.path.spec.to_s, required_names: r.path.required_names) } 83 paths = paths.group_by { |r| r[:path] } 84 85 # Get rid of non-rhino paths 86 # Rhino paths have rhino_resource set as an attribute when the routes are created 87 paths.transform_values! { |v| v.select { |p| p[:rhino_resource].present? && PATH_IGNORES.exclude?(p[:rhino_resource]) } } 88 89 # Remove empty hashes 90 paths.compact_blank! 91 92 # For each path, list the verbs it supports 93 paths.transform_values! do |path| 94 describe_path(path) 95 end 96 end