Sha256: 14e1cf4bf66f4e0ca286eb7ba84667b8d7539bf65373f180c4f1de1a0e334cfb

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module OasParser
  class Property
    include OasParser::RawAccessor
    raw_keys :name, :description, :type, :enum, :minimum, :maximum,
             :example, :default, :items

    attr_accessor :owner, :name, :schema, :raw

    def initialize(owner, schema, name, raw)
      @owner = owner
      @name = name
      @schema = schema
      @raw = raw
    end

    def required
      return false unless schema['required']
      schema['required'].include? name
    end

    def array?
      type == 'array'
    end

    def object?
      type == 'object'
    end

    def collection?
      array? || object?
    end

    def properties
      return convert_property_schema_to_properties(raw['properties']) if object?
      return convert_property_schema_to_properties(items) if array?
      nil
    end

    def convert_property_schema_to_properties(schema)
      schema = schema['properties'] if schema['properties']
      schema.map do |name, definition|
        OasParser::Property.new(self, raw, name, definition)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oas_parser-0.1.2 lib/oas_parser/property.rb
oas_parser-0.1.1 lib/oas_parser/property.rb
oas_parser-0.1.0 lib/oas_parser/property.rb