class Swagger::Docs::ApiDeclarationFile
Attributes
apis[R]
metadata[R]
Public Class Methods
new(metadata, apis, models)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 6 def initialize(metadata, apis, models) @metadata = metadata @apis = camelize_keys_deep apis @models = models end
Public Instance Methods
api_version()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 31 def api_version metadata.api_version end
base_path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 19 def base_path metadata.base_path end
camelize_model_properties()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 39 def camelize_model_properties metadata.camelize_model_properties end
controller_base_path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 35 def controller_base_path metadata.controller_base_path end
generate_resource()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 12 def generate_resource resource = build_resource_root_hash # Add the already-normalized models to the resource. resource = resource.merge({:models => models}) if models.present? resource end
models()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 51 def models normalize_model_properties @models end
path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 23 def path metadata.path end
resource_file_path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 47 def resource_file_path trim_leading_slash(debased_path.to_s.underscore) end
resource_path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 43 def resource_path metadata.overridden_resource_path || demod end
swagger_version()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 27 def swagger_version metadata.swagger_version end
Private Instance Methods
build_resource_root_hash()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 61 def build_resource_root_hash { "apiVersion" => api_version, "swaggerVersion" => swagger_version, "basePath" => base_path, "resourcePath" => resource_path, "apis" => apis, "resourceFilePath" => resource_file_path, "authorizations" => authorizations } end
camelize_keys_deep(obj)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 97 def camelize_keys_deep(obj) process_keys_deep(obj){|key| key.to_s.camelize(:lower)} end
debased_path()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 88 def debased_path path.gsub("#{controller_base_path}", "") end
demod()
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 84 def demod "#{debased_path.to_s.camelize}".demodulize.camelize.underscore end
normalize_model_properties(models)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 73 def normalize_model_properties(models) Hash[ models.map do |k, v| if camelize_model_properties [k.to_s, camelize_keys_deep(v)] else [k.to_s, stringify_keys_deep(v)] end end] end
process_keys_deep(obj, &block)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 105 def process_keys_deep(obj, &block) if obj.is_a? Hash Hash[ obj.map do |k, v| new_key = block.call(k) new_value = process_keys_deep v, &block [new_key, new_value] end ] elsif obj.is_a? Array new_value = obj.collect do |a| process_keys_deep a, &block end else obj end end
stringify_keys_deep(obj)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 101 def stringify_keys_deep(obj) process_keys_deep(obj){|key| key.to_s} end
trim_leading_slash(str)
click to toggle source
# File lib/swagger/docs/api_declaration_file.rb, line 92 def trim_leading_slash(str) return str if !str str.gsub(/\A\/+/, '') end