module OasRails::JsonSchemaGenerator

def self.parse_object_properties(str)

Returns:
  • (Hash) - A hash where keys are property names and values are their JSON schema types.

Parameters:
  • str (String) -- The string representation of the object's properties.
def self.parse_object_properties(str)
  properties = {}
  stack = []
  current_key = ''
  current_value = ''
  str.each_char.with_index do |char, index|
    case char
    when '{', '<'
      stack.push(char)
      current_value += char
    when '}', '>'
      stack.pop
      current_value += char
    when ','
      if stack.empty?
        properties[current_key.strip.to_sym] = parse_type(current_value.strip)
        current_key = ''
        current_value = ''
      else
        current_value += char
      end
    when ':'
      if stack.empty?
        current_key = current_value
        current_value = ''
      else
        current_value += char
      end
    else
      current_value += char
    end
    properties[current_key.strip.to_sym] = parse_type(current_value.strip) if index == str.length - 1 && !current_key.empty?
  end
  properties
end