class OasParser::RequestBody

Attributes

endpoint[RW]
raw[RW]

Public Class Methods

new(endpoint, raw) click to toggle source
# File lib/oas_parser/request_body.rb, line 8
def initialize(endpoint, raw)
  @endpoint = endpoint
  @raw = raw
end

Public Instance Methods

deep_safe_merge(source_hash, new_hash) click to toggle source
# File lib/oas_parser/request_body.rb, line 47
def deep_safe_merge(source_hash, new_hash)
  source_hash.merge(new_hash) do |key, old, new|
    if new.respond_to?(:blank) && new.blank?
      old
    elsif (old.kind_of?(Hash) and new.kind_of?(Hash))
      old.deep_merge(new)
    elsif (old.kind_of?(Array) and new.kind_of?(Array))
      old.concat(new).uniq
    else
      new
    end
  end
end
handle_all_of(schema) click to toggle source
# File lib/oas_parser/request_body.rb, line 30
def handle_all_of(schema)
  newSchema = {}
  if schema['allOf']
    schema['allOf'].each do |p|
      newSchema = deep_safe_merge(newSchema, p)
      if newSchema['allOf']
        newSchema = deep_safe_merge(newSchema, handle_all_of(newSchema))
        newSchema.delete('allOf')
      end
    end
  else
    newSchema = schema
  end

  newSchema
end
properties_for_format(format) click to toggle source
# File lib/oas_parser/request_body.rb, line 13
def properties_for_format(format)
  s = schema(format)
  s = handle_all_of(s)
  s['properties'].map do |name, definition|
    OasParser::Property.new(self, s, name, definition)
  end
end
split_properties_for_format(format) click to toggle source
# File lib/oas_parser/request_body.rb, line 21
def split_properties_for_format(format)
  split_schemas(format).map do |schema|
    schema = handle_all_of(schema)
    schema['properties'].map do |name, definition|
      OasParser::Property.new(self, schema, name, definition)
    end
  end
end