class SwaggerDocsGenerator::MetadataDefinition
# Metadata
generated
Generate metadata for block definition in swagger file
@see github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitions-object
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/swagger_docs_generator/metadata/definition.rb, line 12 def initialize super @model = nil end
Public Instance Methods
construct_swagger_file()
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 17 def construct_swagger_file { definitions: search_definition } end
Private Instance Methods
contruct_hash()
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 61 def contruct_hash { @model.name => { type: 'object', properties: @model.attribute_properties } } end
each_controller(model_name)
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 50 def each_controller(model_name) read_model(model_name) || {} end
files_tmp()
click to toggle source
:reek: UtilityFunction
# File lib/swagger_docs_generator/metadata/definition.rb, line 77 def files_tmp Dir[Rails.root.join(SwaggerDocsGenerator.temporary_folder, '*.json')] end
find_in_jsons()
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 36 def find_in_jsons hash = {} files_tmp.each do |file| hash.merge!(read_part_json(file, 'definitions')) end hash end
find_models()
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 27 def find_models hash = {} all_class_documentation.each do |controller| data = each_controller(controller::CONTROLLER) hash.merge!(data) unless data.empty? end hash end
read_file(file)
click to toggle source
:reek: UtilityFunction
# File lib/swagger_docs_generator/metadata/definition.rb, line 45 def read_file(file) json = JSON.parse(File.read(file)) json.key?('definitions') ? json['definitions'] : {} end
read_model(model_name)
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 54 def read_model(model_name) @model = Model.new(model_name) contruct_hash rescue NameError => message puts "-> [Model] #{message.name} -- doesn't exist" end
read_part_json(file, key)
click to toggle source
:reek: UtilityFunction
# File lib/swagger_docs_generator/metadata/definition.rb, line 82 def read_part_json(file, key) JSON.parse(File.read(file))[key] end
search_definition()
click to toggle source
# File lib/swagger_docs_generator/metadata/definition.rb, line 23 def search_definition find_models.merge!(find_in_jsons) end
temporary_file(controller)
click to toggle source
:reek: UtilityFunction
# File lib/swagger_docs_generator/metadata/definition.rb, line 71 def temporary_file(controller) File.join(SwaggerDocsGenerator.temporary_folder, "#{controller.controller_name}.json") end