class OpenAPIParser::SchemaLoader::Creator
loader base class for create OpenAPI::Schemas::Base object
Attributes
allow_data_type[R]
allow_reference[R]
klass[R]
Public Class Methods
new(variable_name, options)
click to toggle source
@param [String] variable_name @param [Hash] options
Calls superclass method
OpenAPIParser::SchemaLoader::Base::new
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 5 def initialize(variable_name, options) super(variable_name, options) @klass = options[:klass] @allow_reference = options[:reference] || false @allow_data_type = options[:allow_data_type] end
Private Instance Methods
build_object_reference_from_base(base, names)
click to toggle source
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 17 def build_object_reference_from_base(base, names) names = [names] unless names.kind_of?(Array) ref = names.map { |n| escape_reference(n) }.join('/') "#{base}/#{ref}" end
build_openapi_object_from_option(target_object, ref, schema)
click to toggle source
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 37 def build_openapi_object_from_option(target_object, ref, schema) return nil if schema.nil? if @allow_data_type && !check_object_schema?(schema) schema elsif @allow_reference && check_reference_schema?(schema) OpenAPIParser::Schemas::Reference.new(ref, target_object, target_object.root, schema) else @klass.new(ref, target_object, target_object.root, schema) end end
check_object_schema?(check_schema)
click to toggle source
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 29 def check_object_schema?(check_schema) check_schema.kind_of?(::Hash) end
check_reference_schema?(check_schema)
click to toggle source
@return Boolean
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 25 def check_reference_schema?(check_schema) check_object_schema?(check_schema) && !check_schema['$ref'].nil? end
escape_reference(str)
click to toggle source
# File lib/openapi_parser/concerns/schema_loader/creator.rb, line 33 def escape_reference(str) str.to_s.gsub('/', '~1') end