Sha256: f9ef68eb899e665ccc76b2149c8d29ffaaea20b989551f4776f4ab0027371a83

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module OasParser
  class Parameter
    include OasParser::RawAccessor
    raw_keys :name, :in, :description, :style, :enum, :schema,
             :minimum, :maximum, :required

    attr_accessor :owner, :raw

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

    def type
      raw['type'] || schema['type']
    end

    def format
      raw['format'] || schema['format']
    end

    def array?
      type == 'array'
    end

    def object?
      type == 'object'
    end

    def collection?
      array? || object?
    end

    def items
      schema['items']
    end

    def example
      raw['example'] || schema['example']
    end

    def default
      raw['default'] || schema['default']
    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.map do |name, definition|
        OasParser::Property.new(self, raw, name, definition)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oas_parser-0.6.0 lib/oas_parser/parameter.rb
oas_parser-0.5.0 lib/oas_parser/parameter.rb
oas_parser-0.4.0 lib/oas_parser/parameter.rb
oas_parser-0.3.0 lib/oas_parser/parameter.rb
oas_parser-0.2.0 lib/oas_parser/parameter.rb