class Lacerda::Conversion::DataStructure::Member

Attributes

name[R]

Public Class Methods

from_data_structure_content(data_structure_content, scope) click to toggle source
# File lib/lacerda/conversion/data_structure/member.rb, line 9
def self.from_data_structure_content(data_structure_content, scope)
  return [] if data_structure_content.nil?
  # In the case that you create a nested data structure when type == 'object',
  # the possible_members can be just a Hash, instead of an array
  if data_structure_content.is_a?(Hash)
    data_structure_content = [data_structure_content] 
  end
  members = data_structure_content.select do |d|
    d['element'] == 'member'
  end
  members.map { |member| Member.new(member, scope) }
end
new(member, scope) click to toggle source
# File lib/lacerda/conversion/data_structure/member.rb, line 22
def initialize(member, scope)
  @description = member.dig('meta', 'description')
  @content = member['content']
  @name = Lacerda.underscore(@content['key']['content'])
  @attributes = member.dig('attributes', 'typeAttributes') || []
  @is_required = @attributes.include?('required')
  @type = Type.new(@content['value'], @is_required, @scope)
  @scope = scope
end

Public Instance Methods

required?() click to toggle source
# File lib/lacerda/conversion/data_structure/member.rb, line 32
def required?
  @is_required
end
spec() click to toggle source
# File lib/lacerda/conversion/data_structure/member.rb, line 36
def spec
    spec = {}
    # We might have a description
    spec['description'] = @description
    spec.merge!(@type.to_hash)
    # Add the type of the array objects (if it is an array)
    spec['items'] = @type.array_type
      # If it's an object, we need recursion
    if @type.object?
      data_structure = DataStructure.new('tmp', [@content['value']], @scope).to_json
      spec['properties'] = data_structure['properties']
    end
    spec
end