Module: SwaggerDocumentationAdder

Includes:
SwaggerRouting
Defined in:
lib/grape-swagger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#combined_namespace_identifiersObject

Returns the value of attribute combined_namespace_identifiers.



110
111
112
# File 'lib/grape-swagger.rb', line 110

def combined_namespace_identifiers
  @combined_namespace_identifiers
end

#combined_namespace_routesObject

Returns the value of attribute combined_namespace_routes.



111
112
113
# File 'lib/grape-swagger.rb', line 111

def combined_namespace_routes
  @combined_namespace_routes
end

#combined_namespacesObject

Returns the value of attribute combined_namespaces.



110
111
112
# File 'lib/grape-swagger.rb', line 110

def combined_namespaces
  @combined_namespaces
end

#combined_routesObject

Returns the value of attribute combined_routes.



111
112
113
# File 'lib/grape-swagger.rb', line 111

def combined_routes
  @combined_routes
end

Instance Method Details

#add_swagger_documentation(options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/grape-swagger.rb', line 115

def add_swagger_documentation(options = {})
  documentation_class = create_documentation_class

  version_for(options)
  options = { target_class: self }.merge(options)
  @target_class = options[:target_class]
  auth_wrapper = options[:endpoint_auth_wrapper] || Class.new

  use auth_wrapper if auth_wrapper.method_defined?(:before) && !middleware.flatten.include?(auth_wrapper)

  documentation_class.setup(options)
  mount(documentation_class)

  @target_class.combined_routes = {}
  combine_routes(@target_class, documentation_class)

  @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 do |key|
    @target_class.combined_namespace_routes[key] = @target_class.combined_routes[key]
  end
  documentation_class
end