Class: Grape::API
- Inherits:
-
Object
- Object
- Grape::API
- Defined in:
- lib/grape-swagger.rb
Class Attribute Summary collapse
-
.combined_namespace_identifiers ⇒ Object
Returns the value of attribute combined_namespace_identifiers.
-
.combined_namespace_routes ⇒ Object
Returns the value of attribute combined_namespace_routes.
-
.combined_namespaces ⇒ Object
Returns the value of attribute combined_namespaces.
-
.combined_routes ⇒ Object
Returns the value of attribute combined_routes.
-
.endpoint_mapping ⇒ Object
Returns the value of attribute endpoint_mapping.
Class Method Summary collapse
Class Attribute Details
.combined_namespace_identifiers ⇒ Object
Returns the value of attribute combined_namespace_identifiers.
12 13 14 |
# File 'lib/grape-swagger.rb', line 12 def combined_namespace_identifiers @combined_namespace_identifiers end |
.combined_namespace_routes ⇒ Object
Returns the value of attribute combined_namespace_routes.
12 13 14 |
# File 'lib/grape-swagger.rb', line 12 def combined_namespace_routes @combined_namespace_routes end |
.combined_namespaces ⇒ Object
Returns the value of attribute combined_namespaces.
12 13 14 |
# File 'lib/grape-swagger.rb', line 12 def combined_namespaces @combined_namespaces end |
.combined_routes ⇒ Object
Returns the value of attribute combined_routes.
12 13 14 |
# File 'lib/grape-swagger.rb', line 12 def combined_routes @combined_routes end |
.endpoint_mapping ⇒ Object
Returns the value of attribute endpoint_mapping.
13 14 15 |
# File 'lib/grape-swagger.rb', line 13 def endpoint_mapping @endpoint_mapping end |
Class Method Details
.add_swagger_documentation(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/grape-swagger.rb', line 15 def add_swagger_documentation( = {}) documentation_class = create_documentation_class = { target_class: self }.merge() @target_class = [:target_class] documentation_class.setup() mount(documentation_class) @target_class.combined_routes = {} @target_class.routes.each do |route| route_path = route.route_path route_match = route_path.split(/^.*?#{route.route_prefix.to_s}/).last next unless route_match route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)$') next unless route_match resource = route_match.captures.first next if resource.empty? resource.downcase! @target_class.combined_routes[resource] ||= [] next if documentation_class.hide_documentation_path && route.route_path.match(/#{documentation_class.mount_path}($|\/|\(\.)/) @target_class.combined_routes[resource] << route end @target_class.endpoint_mapping = {} @target_class.combined_namespaces = {} combine_namespaces(@target_class) @target_class.combined_namespace_routes = {} @target_class.combined_namespace_identifiers = {} combine_namespace_routes(@target_class.combined_namespaces) exclusive_route_keys = @target_class.combined_routes.keys - @target_class.combined_namespaces.keys exclusive_route_keys.each { |key| @target_class.combined_namespace_routes[key] = @target_class.combined_routes[key] } documentation_class end |