class R2OAS::Schema::V3::PathGenerator

Public Class Methods

new(schema_data = {}, options = {}) click to toggle source
Calls superclass method R2OAS::Schema::V3::BaseGenerator::new
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 12
def initialize(schema_data = {}, options = {})
  super(options)
  sorted_schema_data = deep_sort(schema_data, 'paths')
  @paths = sorted_schema_data['paths']
  @glob_schema_paths = create_glob_paths_paths
end

Public Instance Methods

generate_docs() click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 19
def generate_docs
  logger.info ' <From routes data>'
  generate_docs_from_routes_data
end

Private Instance Methods

create_glob_paths_paths() click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 46
def create_glob_paths_paths
  if many_paths_file_paths.present? && !skip_load_dot_paths
    many_paths_file_paths
  else
    ["#{schema_save_dir_path}/paths/**/**.yml"]
  end
end
generate_docs_from_routes_data() click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 28
def generate_docs_from_routes_data
  process_when_generate_docs do |save_file_path|
    logger.info "  Add schema file into store: \t#{save_file_path}"
  end
end
process_when_generate_docs() { |save_file_path| ... } click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 34
def process_when_generate_docs
  logger.info ' <Update schema files (paths)>'
  save_each_tags(@paths) do |tag_name, result|
    relative_path = "paths/#{tag_name}"
    file_manager = PathItemFileManager.new(relative_path, :relative)
    save_file_path = file_manager.save_file_path(type: :relative)
    store.add(save_file_path, result.to_yaml)

    yield save_file_path if block_given?
  end
end
save_each_tags(unit_paths_data) { |tag_name, result| ... } click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 70
def save_each_tags(unit_paths_data)
  unit_paths_data_group_by_tags(unit_paths_data).each do |tag_name, result|
    yield [tag_name, result] if block_given?
  end
end
unit_paths_data_group_by_tags(unit_paths_data) click to toggle source
# File lib/r2-oas/schema/v3/generator/path_generator.rb, line 54
def unit_paths_data_group_by_tags(unit_paths_data)
  unit_paths_data.each_with_object({}) do |(path, data_when_path), result|
    data_when_path.each do |verb, data_when_verb|
      tag_name = data_when_verb['tags'].first
      result[tag_name] ||= {}
      result[tag_name].deep_merge!(
        'paths' => {
          path => {
            verb => data_when_verb
          }
        }
      )
    end
  end
end