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
172
173
174
|
# File 'lib/openapi3_parser/node/schema.rb', line 172
def additional_properties?
self["additionalProperties"] != false
end
|
#additional_properties_schema ⇒ Schema?
177
178
179
180
181
182
|
# File 'lib/openapi3_parser/node/schema.rb', line 177
def additional_properties_schema
properties = self["additionalProperties"]
return if [true, false].include?(properties)
properties
end
|
142
143
144
|
# File 'lib/openapi3_parser/node/schema.rb', line 142
def all_of
self["allOf"]
end
|
152
153
154
|
# File 'lib/openapi3_parser/node/schema.rb', line 152
def any_of
self["anyOf"]
end
|
#default ⇒ Any
200
201
202
|
# File 'lib/openapi3_parser/node/schema.rb', line 200
def default
self["default"]
end
|
#deprecated? ⇒ Boolean
240
241
242
|
# File 'lib/openapi3_parser/node/schema.rb', line 240
def deprecated?
self["deprecated"]
end
|
#description ⇒ String?
185
186
187
|
# File 'lib/openapi3_parser/node/schema.rb', line 185
def description
self["description"]
end
|
#description_html ⇒ String?
190
191
192
|
# File 'lib/openapi3_parser/node/schema.rb', line 190
def description_html
render_markdown(description)
end
|
210
211
212
|
# File 'lib/openapi3_parser/node/schema.rb', line 210
def discriminator
self["discriminator"]
end
|
132
133
134
|
# File 'lib/openapi3_parser/node/schema.rb', line 132
def enum
self["enum"]
end
|
#example ⇒ Any
235
236
237
|
# File 'lib/openapi3_parser/node/schema.rb', line 235
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
|
230
231
232
|
# File 'lib/openapi3_parser/node/schema.rb', line 230
def external_docs
self["externalDocs"]
end
|
195
196
197
|
# File 'lib/openapi3_parser/node/schema.rb', line 195
def format
self["format"]
end
|
162
163
164
|
# File 'lib/openapi3_parser/node/schema.rb', line 162
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
|
157
158
159
|
# File 'lib/openapi3_parser/node/schema.rb', line 157
def not
self["not"]
end
|
#nullable? ⇒ Boolean
205
206
207
|
# File 'lib/openapi3_parser/node/schema.rb', line 205
def nullable?
self["nullable"]
end
|
147
148
149
|
# File 'lib/openapi3_parser/node/schema.rb', line 147
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>
167
168
169
|
# File 'lib/openapi3_parser/node/schema.rb', line 167
def properties
self["properties"]
end
|
#read_only? ⇒ Boolean
215
216
217
|
# File 'lib/openapi3_parser/node/schema.rb', line 215
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
|
# 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 == property }
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?
137
138
139
|
# File 'lib/openapi3_parser/node/schema.rb', line 137
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
220
221
222
|
# File 'lib/openapi3_parser/node/schema.rb', line 220
def write_only?
self["writeOnly"]
end
|
#xml ⇒ Xml?
225
226
227
|
# File 'lib/openapi3_parser/node/schema.rb', line 225
def xml
self["xml"]
end
|