Class: Openapi3Parser::Node::Schema
- Inherits:
-
Object
- Object
- Object
- Openapi3Parser::Node::Schema
show all
- Defined in:
- lib/openapi3_parser/node/schema.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary
Attributes inherited from Object
#node_context, #node_data
Instance Method Summary
collapse
Methods inherited from Object
#==, #[], #each, #extension, #initialize, #inspect, #node_at, #render_markdown, #values
Instance Method Details
#additional_properties? ⇒ Boolean
174
175
176
|
# File 'lib/openapi3_parser/node/schema.rb', line 174
def additional_properties?
self["additionalProperties"] != false
end
|
#additional_properties_schema ⇒ Schema?
179
180
181
182
183
184
|
# File 'lib/openapi3_parser/node/schema.rb', line 179
def additional_properties_schema
properties = self["additionalProperties"]
return if [true, false].include?(properties)
properties
end
|
144
145
146
|
# File 'lib/openapi3_parser/node/schema.rb', line 144
def all_of
self["allOf"]
end
|
154
155
156
|
# File 'lib/openapi3_parser/node/schema.rb', line 154
def any_of
self["anyOf"]
end
|
#default ⇒ Any
202
203
204
|
# File 'lib/openapi3_parser/node/schema.rb', line 202
def default
self["default"]
end
|
#deprecated? ⇒ Boolean
242
243
244
|
# File 'lib/openapi3_parser/node/schema.rb', line 242
def deprecated?
self["deprecated"]
end
|
#description ⇒ String?
187
188
189
|
# File 'lib/openapi3_parser/node/schema.rb', line 187
def description
self["description"]
end
|
#description_html ⇒ String?
192
193
194
|
# File 'lib/openapi3_parser/node/schema.rb', line 192
def description_html
render_markdown(description)
end
|
212
213
214
|
# File 'lib/openapi3_parser/node/schema.rb', line 212
def discriminator
self["discriminator"]
end
|
134
135
136
|
# File 'lib/openapi3_parser/node/schema.rb', line 134
def enum
self["enum"]
end
|
#example ⇒ Any
237
238
239
|
# File 'lib/openapi3_parser/node/schema.rb', line 237
def example
self["example"]
end
|
#exclusive_maximum? ⇒ Boolean
57
58
59
|
# File 'lib/openapi3_parser/node/schema.rb', line 57
def exclusive_maximum?
self["exclusiveMaximum"]
end
|
#exclusive_minimum? ⇒ Boolean
67
68
69
|
# File 'lib/openapi3_parser/node/schema.rb', line 67
def exclusive_minimum?
self["exclusiveMinimum"]
end
|
232
233
234
|
# File 'lib/openapi3_parser/node/schema.rb', line 232
def external_docs
self["externalDocs"]
end
|
197
198
199
|
# File 'lib/openapi3_parser/node/schema.rb', line 197
def format
self["format"]
end
|
164
165
166
|
# File 'lib/openapi3_parser/node/schema.rb', line 164
def items
self["items"]
end
|
#max_items ⇒ Integer?
87
88
89
|
# File 'lib/openapi3_parser/node/schema.rb', line 87
def max_items
self["maxItems"]
end
|
#max_length ⇒ Integer?
72
73
74
|
# File 'lib/openapi3_parser/node/schema.rb', line 72
def max_length
self["maxLength"]
end
|
#max_properties ⇒ Integer?
102
103
104
|
# File 'lib/openapi3_parser/node/schema.rb', line 102
def max_properties
self["maxProperties"]
end
|
#maximum ⇒ Integer?
52
53
54
|
# File 'lib/openapi3_parser/node/schema.rb', line 52
def maximum
self["maximum"]
end
|
#min_items ⇒ Integer
92
93
94
|
# File 'lib/openapi3_parser/node/schema.rb', line 92
def min_items
self["minItems"]
end
|
#min_length ⇒ Integer
77
78
79
|
# File 'lib/openapi3_parser/node/schema.rb', line 77
def min_length
self["minLength"]
end
|
#min_properties ⇒ Integer
107
108
109
|
# File 'lib/openapi3_parser/node/schema.rb', line 107
def min_properties
self["minProperties"]
end
|
#minimum ⇒ Integer?
62
63
64
|
# File 'lib/openapi3_parser/node/schema.rb', line 62
def minimum
self["minimum"]
end
|
#multiple_of ⇒ Numeric?
47
48
49
|
# File 'lib/openapi3_parser/node/schema.rb', line 47
def multiple_of
self["multipleOf"]
end
|
#name ⇒ String?
This is used to provide a name for the schema based on it’s position in an OpenAPI document.
For example it’s common to have an OpenAPI document structured like so: components:
schemas:
Product:
properties:
product_id:
type: string
description:
type: string
and there is then implied meaning in the field name of Product, ie that schema now represents a product. This data is not easily or consistently made available as it is part of the path to the data rather than the data itself. Instead the field that would be more appropriate would be “title” within a schema.
As this is a common pattern in OpenAPI docs this provides a method to look up this contextual name of the schema so it can be referenced when working with the document, it only considers a field to be name if it is within a group called schemas (as is the case in #/components/schemas)
36
37
38
39
|
# File 'lib/openapi3_parser/node/schema.rb', line 36
def name
segments = node_context.source_location.pointer.segments
segments[-1] if segments[-2] == "schemas"
end
|
159
160
161
|
# File 'lib/openapi3_parser/node/schema.rb', line 159
def not
self["not"]
end
|
#nullable? ⇒ Boolean
207
208
209
|
# File 'lib/openapi3_parser/node/schema.rb', line 207
def nullable?
self["nullable"]
end
|
149
150
151
|
# File 'lib/openapi3_parser/node/schema.rb', line 149
def one_of
self["oneOf"]
end
|
#pattern ⇒ String?
82
83
84
|
# File 'lib/openapi3_parser/node/schema.rb', line 82
def pattern
self["pattern"]
end
|
#properties ⇒ Map<String, Schema>
169
170
171
|
# File 'lib/openapi3_parser/node/schema.rb', line 169
def properties
self["properties"]
end
|
#read_only? ⇒ Boolean
217
218
219
|
# File 'lib/openapi3_parser/node/schema.rb', line 217
def read_only?
self["readOnly"]
end
|
112
113
114
|
# File 'lib/openapi3_parser/node/schema.rb', line 112
def required
self["required"]
end
|
#requires?(property) ⇒ Boolean
Returns whether a property is a required field or not. Can accept the property name or a schema
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/openapi3_parser/node/schema.rb', line 121
def requires?(property)
if property.is_a?(Schema)
properties.to_h
.select { |k, _| required.to_a.include?(k) }
.any? { |_, schema| schema.node_context == property.node_context }
else
required.to_a.include?(property)
end
end
|
#title ⇒ String?
42
43
44
|
# File 'lib/openapi3_parser/node/schema.rb', line 42
def title
self["title"]
end
|
#type ⇒ String?
139
140
141
|
# File 'lib/openapi3_parser/node/schema.rb', line 139
def type
self["type"]
end
|
#unique_items? ⇒ Boolean
97
98
99
|
# File 'lib/openapi3_parser/node/schema.rb', line 97
def unique_items?
self["uniqueItems"]
end
|
#write_only? ⇒ Boolean
222
223
224
|
# File 'lib/openapi3_parser/node/schema.rb', line 222
def write_only?
self["writeOnly"]
end
|
#xml ⇒ Xml?
227
228
229
|
# File 'lib/openapi3_parser/node/schema.rb', line 227
def xml
self["xml"]
end
|