class R2OAS::Schema::V3::FromFiles::PathItemObject

Public Class Methods

new(doc, ref, opts = {}) click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 17
def initialize(doc, ref, opts = {})
  super(opts)
  @doc = doc
  @parent_ref = PathRef.new(ref)
  resolve_dependencies!
end

Public Instance Methods

call_ref_path!() click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 46
def call_ref_path!
  callback = proc { |obj| obj.ref_path }
  deep_call(@doc, '$ref', callback)
end
resolve_dependencies!() click to toggle source

Breaking changes to @doc

# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 34
def resolve_dependencies!
  local_ref_hash = ref_dup.to_h

  @doc.each do |verb, data_when_verb|
    local_ref_hash[:verb] = verb
    local_ref_hash[:tag_name] = data_when_verb['tags'].first

    resolve_dependencies_at_schema!(@doc, verb, data_when_verb, local_ref_hash)
    resolve_dependencies_at_request_body!(@doc, verb, data_when_verb, local_ref_hash)
  end
end
to_doc() click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 24
def to_doc
  call_ref_path!

  # MEMO:
  # If it is overwritten, it may lead to unexpected problems, so give a copy
  execute_transform_plugins(:path_item, @doc, ref_dup)
  @doc
end

Private Instance Methods

create_child_request_body_ref(schema_name, local_ref_hash) click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 97
def create_child_request_body_ref(schema_name, local_ref_hash)
  local_ref_hash_dup = local_ref_hash.dup
  # MEMO:
  # requestBody does not depend on http_status
  local_ref_hash_dup.delete(:http_status)

  ref_data = local_ref_hash_dup.merge({ from: :path_item, schema_name: schema_name, depth: 0 })
  ref = Components::RequestBodyRef.new(ref_data)
end
create_child_schema_ref(schema_name, local_ref_hash) click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 91
def create_child_schema_ref(schema_name, local_ref_hash)
  local_ref_hash_dup = local_ref_hash.dup
  ref_data = local_ref_hash_dup.merge({ from: :path_item, schema_name: schema_name, depth: 0 })
  ref = Components::SchemaRef.new(ref_data)
end
ref_dup() click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 53
def ref_dup
  @parent_ref.dup
end
resolve_dependencies_at_request_body!(data, verb, data_when_verb, local_ref_hash) click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 76
def resolve_dependencies_at_request_body!(data, verb, data_when_verb, local_ref_hash)
  deep_replace!(data_when_verb['requestBody'], '$ref') do |ref_path|
    schema_obj, schema_type, schema_name = ref_path.split('/').slice(1..-1)
    schema_doc = root_doc&.fetch(schema_obj, nil)&.fetch(schema_type, nil)&.fetch(schema_name, nil) || {}

    ref = create_child_request_body_ref(schema_name, local_ref_hash)
    obj = Components::RequestBodyObject.new(schema_doc, ref, opts)

    obj_store.add('components/requestBodies', schema_name, obj)

    data[verb]['requestBody']['$ref'] = obj
    obj
  end
end
resolve_dependencies_at_schema!(data, verb, data_when_verb, local_ref_hash) click to toggle source
# File lib/r2-oas/schema/v3/object/from_files/path_item_object.rb, line 57
def resolve_dependencies_at_schema!(data, verb, data_when_verb, local_ref_hash)
  data_when_verb['responses'].each do |http_status, data_when_http_status|
    local_ref_hash[:http_status] = http_status

    deep_replace!(data_when_http_status, '$ref') do |ref_path|
      schema_obj, schema_type, schema_name = ref_path.split('/').slice(1..-1)
      schema_doc = root_doc&.fetch(schema_obj, nil)&.fetch(schema_type, nil)&.fetch(schema_name, nil) || {}

      ref = create_child_schema_ref(schema_name, local_ref_hash)
      obj = Components::SchemaObject.new(schema_doc, ref, opts)

      obj_store.add('components/schemas', schema_name, obj)
      obj
    end

    data[verb]['responses'][http_status] = data_when_http_status
  end
end