Class: OasParser::AbstractAttribute
- Inherits:
-
Object
- Object
- OasParser::AbstractAttribute
show all
- Includes:
- RawAccessor
- Defined in:
- lib/oas_parser/abstract_attribute.rb
Instance Method Summary
collapse
included, #method_missing, #respond_to_missing?
Constructor Details
Returns a new instance of AbstractAttribute.
5
6
7
|
# File 'lib/oas_parser/abstract_attribute.rb', line 5
def initialize(name)
@name = name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class OasParser::RawAccessor
Instance Method Details
#allOf? ⇒ Boolean
23
24
25
|
# File 'lib/oas_parser/abstract_attribute.rb', line 23
def allOf?
raw['allOf'] ? true : false
end
|
#array? ⇒ Boolean
31
32
33
|
# File 'lib/oas_parser/abstract_attribute.rb', line 31
def array?
type == 'array'
end
|
#collection? ⇒ Boolean
39
40
41
|
# File 'lib/oas_parser/abstract_attribute.rb', line 39
def collection?
array? || object?
end
|
#empty? ⇒ Boolean
43
44
45
46
47
48
|
# File 'lib/oas_parser/abstract_attribute.rb', line 43
def empty?
raise 'Called empty? on non collection type' unless collection?
return true if object? && raw['properties'].blank?
return true if array? && items.blank?
false
end
|
#enum ⇒ Object
19
20
21
|
# File 'lib/oas_parser/abstract_attribute.rb', line 19
def enum
raw['enum'] || (schema ? schema['enum'] : nil)
end
|
#has_xml_name? ⇒ Boolean
75
76
77
78
|
# File 'lib/oas_parser/abstract_attribute.rb', line 75
def has_xml_name?
return false unless has_xml_options?
xml_name || false
end
|
#has_xml_options? ⇒ Boolean
59
60
61
|
# File 'lib/oas_parser/abstract_attribute.rb', line 59
def has_xml_options?
raw['xml'].present?
end
|
#is_xml_attribute? ⇒ Boolean
63
64
65
66
|
# File 'lib/oas_parser/abstract_attribute.rb', line 63
def is_xml_attribute?
return false unless has_xml_options?
raw['xml']['attribute'] || false
end
|
#is_xml_text? ⇒ Boolean
68
69
70
71
72
73
|
# File 'lib/oas_parser/abstract_attribute.rb', line 68
def is_xml_text?
return false unless has_xml_options?
return true if raw['xml']['text'] || false
raw['xml']['x-text'] || false
end
|
#name(format = nil) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/oas_parser/abstract_attribute.rb', line 9
def name(format = nil)
default = @name || raw['name']
return default unless format
case format
when 'text/xml'
has_xml_name? ? xml_name : default
else default
end
end
|
#object? ⇒ Boolean
35
36
37
|
# File 'lib/oas_parser/abstract_attribute.rb', line 35
def object?
type == 'object'
end
|
#oneOf? ⇒ Boolean
27
28
29
|
# File 'lib/oas_parser/abstract_attribute.rb', line 27
def oneOf?
raw['oneOf'] ? true : false
end
|
#properties ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/oas_parser/abstract_attribute.rb', line 50
def properties
return convert_property_schema_to_properties(raw) if (oneOf? || allOf?)
return nil unless collection?
return [] if empty?
return convert_property_schema_to_properties(raw['properties']) if object?
return convert_property_schema_to_properties(items) if array?
nil
end
|
#subproperties_are_one_of_many? ⇒ Boolean
84
85
86
87
|
# File 'lib/oas_parser/abstract_attribute.rb', line 84
def subproperties_are_one_of_many?
return false unless array?
items['oneOf'].present?
end
|
#xml_name ⇒ Object
80
81
82
|
# File 'lib/oas_parser/abstract_attribute.rb', line 80
def xml_name
raw['xml']['name']
end
|