Class: OasParser::Parameter

Inherits:
Object
  • Object
show all
Includes:
RawAccessor
Defined in:
lib/oas_parser/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RawAccessor

included, #method_missing, #respond_to_missing?

Constructor Details

#initialize(owner, raw) ⇒ Parameter

Returns a new instance of Parameter.



9
10
11
12
# File 'lib/oas_parser/parameter.rb', line 9

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OasParser::RawAccessor

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



7
8
9
# File 'lib/oas_parser/parameter.rb', line 7

def owner
  @owner
end

#rawObject

Returns the value of attribute raw.



7
8
9
# File 'lib/oas_parser/parameter.rb', line 7

def raw
  @raw
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/oas_parser/parameter.rb', line 22

def array?
  type == 'array'
end

#collection?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/oas_parser/parameter.rb', line 30

def collection?
  array? || object?
end

#convert_property_schema_to_properties(schema) ⇒ Object



52
53
54
55
56
# File 'lib/oas_parser/parameter.rb', line 52

def convert_property_schema_to_properties(schema)
  schema.map do |name, definition|
    OasParser::Property.new(self, raw, name, definition)
  end
end

#defaultObject



42
43
44
# File 'lib/oas_parser/parameter.rb', line 42

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

#exampleObject



38
39
40
# File 'lib/oas_parser/parameter.rb', line 38

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

#formatObject



18
19
20
# File 'lib/oas_parser/parameter.rb', line 18

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

#itemsObject



34
35
36
# File 'lib/oas_parser/parameter.rb', line 34

def items
  schema['items']
end

#object?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/oas_parser/parameter.rb', line 26

def object?
  type == 'object'
end

#propertiesObject



46
47
48
49
50
# File 'lib/oas_parser/parameter.rb', line 46

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

#typeObject



14
15
16
# File 'lib/oas_parser/parameter.rb', line 14

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