class R2OAS::Schema::V3::BaseGenerator
Attributes
is_create_cache[RW]
skip_load_dot_paths[RW]
store[RW]
unit_paths_file_path[RW]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
R2OAS::Base::new
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 15 def initialize(options = {}) super options.keys.each do |key| send("#{key}=", options[key]) end @store = ::R2OAS::Store.create(:schema) @glob_schema_paths = create_glob_schema_paths end
Private Instance Methods
abs_cache_docs_path()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 108 def abs_cache_docs_path File.expand_path(relative_cahe_docs_path) end
cache_docs()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 94 def cache_docs if exists_cache? result = IO.binread(abs_cache_docs_path) inflate = Zlib::Inflate.inflate(result) @cache_docs ||= Marshal.load(inflate) else @cache_docs ||= {} end end
create_all_routes()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 45 def create_all_routes ::Rails.application.reload_routes! ::Rails.application.routes.routes end
create_docs()
click to toggle source
Scope Rails
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 34 def create_docs all_routes = create_all_routes parser = Routing::Parser.new(all_routes) routes_data = parser.routes_data tags_data = parser.tags_data schemas_data = parser.schemas_data Schema::V3::OpenapiObject.new(routes_data, tags_data, schemas_data).to_doc end
create_glob_schema_paths()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 54 def create_glob_schema_paths exclude_paths_regexp_paths = ["#{schema_save_dir_path}/**.yml"] paths_regexp_paths = ["#{schema_save_dir_path}/paths/**/**.yml"] components_schemas_regexp_paths = ["#{schema_save_dir_path}/components/**/**.yml"] components_security_schemes_regexp_paths = ["#{schema_save_dir_path}/components/securitySchemes/**/**.yml"] if exists_paths_files? # components/securitySchemes is not referenced in $ ref. exclude_paths_regexp_paths + many_paths_file_paths + many_components_file_paths + components_security_schemes_regexp_paths else exclude_paths_regexp_paths + paths_regexp_paths + components_schemas_regexp_paths end end
exists_cache?()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 104 def exists_cache? FileTest.exists?(abs_cache_docs_path) end
exists_paths_files?()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 90 def exists_paths_files? Dir.glob("#{schema_save_dir_path}/paths/**/**.yml").present? end
many_components_file_paths()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 82 def many_components_file_paths @many_components_file_paths ||= many_paths_file_paths.each_with_object([]) do |unit_paths_path, result| file_manager = PathItemFileManager.new(unit_paths_path, :full) components_file_paths_at_path = file_manager.descendants_ref_paths result.push(*components_file_paths_at_path) end.uniq end
many_paths_file_paths()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 72 def many_paths_file_paths if unit_paths_file_path.present? && !skip_load_dot_paths [unit_paths_file_path] elsif !unit_paths_file_path.present? && !skip_load_dot_paths && paths_config.all_load_paths? paths_config.many_paths_file_paths else Dir.glob("#{schema_save_dir_path}/paths/**/**.yml") end end
relative_cahe_docs_path()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 112 def relative_cahe_docs_path "#{@root_dir_path}/.docs" end
schema_file_do_not_exists?()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 50 def schema_file_do_not_exists? schema_files_paths.count == 0 end
schema_files_paths()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 68 def schema_files_paths Dir.glob(@glob_schema_paths) end
unknown_paths_path()
click to toggle source
# File lib/r2-oas/schema/v3/generator/base_generator.rb, line 116 def unknown_paths_path "#{@root_dir_path}/src/paths/unknown.yml" end