Class: Openapi3Parser::Node::Schema

Inherits:
Object
  • Object
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

Constructor Details

This class inherits a constructor from Openapi3Parser::Node::Object

Instance Method Details

#additional_properties?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/openapi3_parser/node/schema.rb', line 174

def additional_properties?
  self["additionalProperties"] != false
end

#additional_properties_schemaSchema?

Returns:



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

#all_ofNode::Array<Schema>?

Returns:



144
145
146
# File 'lib/openapi3_parser/node/schema.rb', line 144

def all_of
  self["allOf"]
end

#any_ofNode::Array<Schema>?

Returns:



154
155
156
# File 'lib/openapi3_parser/node/schema.rb', line 154

def any_of
  self["anyOf"]
end

#defaultAny

Returns:

  • (Any)


202
203
204
# File 'lib/openapi3_parser/node/schema.rb', line 202

def default
  self["default"]
end

#deprecated?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/openapi3_parser/node/schema.rb', line 242

def deprecated?
  self["deprecated"]
end

#descriptionString?

Returns:

  • (String, nil)


187
188
189
# File 'lib/openapi3_parser/node/schema.rb', line 187

def description
  self["description"]
end

#description_htmlString?

Returns:

  • (String, nil)


192
193
194
# File 'lib/openapi3_parser/node/schema.rb', line 192

def description_html
  render_markdown(description)
end

#discriminatorDiscriminator?

Returns:



212
213
214
# File 'lib/openapi3_parser/node/schema.rb', line 212

def discriminator
  self["discriminator"]
end

#enumNode::Array<Object>?

Returns:



134
135
136
# File 'lib/openapi3_parser/node/schema.rb', line 134

def enum
  self["enum"]
end

#exampleAny

Returns:

  • (Any)


237
238
239
# File 'lib/openapi3_parser/node/schema.rb', line 237

def example
  self["example"]
end

#exclusive_maximum?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/openapi3_parser/node/schema.rb', line 57

def exclusive_maximum?
  self["exclusiveMaximum"]
end

#exclusive_minimum?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/openapi3_parser/node/schema.rb', line 67

def exclusive_minimum?
  self["exclusiveMinimum"]
end

#external_docsExternalDocumentation?

Returns:



232
233
234
# File 'lib/openapi3_parser/node/schema.rb', line 232

def external_docs
  self["externalDocs"]
end

#formatString?

Returns:

  • (String, nil)


197
198
199
# File 'lib/openapi3_parser/node/schema.rb', line 197

def format
  self["format"]
end

#itemsSchema?

Returns:



164
165
166
# File 'lib/openapi3_parser/node/schema.rb', line 164

def items
  self["items"]
end

#max_itemsInteger?

Returns:

  • (Integer, nil)


87
88
89
# File 'lib/openapi3_parser/node/schema.rb', line 87

def max_items
  self["maxItems"]
end

#max_lengthInteger?

Returns:

  • (Integer, nil)


72
73
74
# File 'lib/openapi3_parser/node/schema.rb', line 72

def max_length
  self["maxLength"]
end

#max_propertiesInteger?

Returns:

  • (Integer, nil)


102
103
104
# File 'lib/openapi3_parser/node/schema.rb', line 102

def max_properties
  self["maxProperties"]
end

#maximumInteger?

Returns:

  • (Integer, nil)


52
53
54
# File 'lib/openapi3_parser/node/schema.rb', line 52

def maximum
  self["maximum"]
end

#min_itemsInteger

Returns:

  • (Integer)


92
93
94
# File 'lib/openapi3_parser/node/schema.rb', line 92

def min_items
  self["minItems"]
end

#min_lengthInteger

Returns:

  • (Integer)


77
78
79
# File 'lib/openapi3_parser/node/schema.rb', line 77

def min_length
  self["minLength"]
end

#min_propertiesInteger

Returns:

  • (Integer)


107
108
109
# File 'lib/openapi3_parser/node/schema.rb', line 107

def min_properties
  self["minProperties"]
end

#minimumInteger?

Returns:

  • (Integer, nil)


62
63
64
# File 'lib/openapi3_parser/node/schema.rb', line 62

def minimum
  self["minimum"]
end

#multiple_ofNumeric?

Returns:

  • (Numeric, nil)


47
48
49
# File 'lib/openapi3_parser/node/schema.rb', line 47

def multiple_of
  self["multipleOf"]
end

#nameString?

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)

Returns:

  • (String, nil)


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

#notSchema?

Returns:



159
160
161
# File 'lib/openapi3_parser/node/schema.rb', line 159

def not
  self["not"]
end

#nullable?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/openapi3_parser/node/schema.rb', line 207

def nullable?
  self["nullable"]
end

#one_ofNode::Array<Schema>?

Returns:



149
150
151
# File 'lib/openapi3_parser/node/schema.rb', line 149

def one_of
  self["oneOf"]
end

#patternString?

Returns:

  • (String, nil)


82
83
84
# File 'lib/openapi3_parser/node/schema.rb', line 82

def pattern
  self["pattern"]
end

#propertiesMap<String, Schema>

Returns:



169
170
171
# File 'lib/openapi3_parser/node/schema.rb', line 169

def properties
  self["properties"]
end

#read_only?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/openapi3_parser/node/schema.rb', line 217

def read_only?
  self["readOnly"]
end

#requiredNode::Array<String>?

Returns:



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

Parameters:

Returns:

  • (Boolean)


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)
    # compare node_context of objects to ensure references aren't treated
    # as equal - only direct properties of this object will pass.
    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

#titleString?

Returns:

  • (String, nil)


42
43
44
# File 'lib/openapi3_parser/node/schema.rb', line 42

def title
  self["title"]
end

#typeString?

Returns:

  • (String, nil)


139
140
141
# File 'lib/openapi3_parser/node/schema.rb', line 139

def type
  self["type"]
end

#unique_items?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/openapi3_parser/node/schema.rb', line 97

def unique_items?
  self["uniqueItems"]
end

#write_only?Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/openapi3_parser/node/schema.rb', line 222

def write_only?
  self["writeOnly"]
end

#xmlXml?

Returns:



227
228
229
# File 'lib/openapi3_parser/node/schema.rb', line 227

def xml
  self["xml"]
end