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)

172
173
174
# File 'lib/openapi3_parser/node/schema.rb', line 172

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

#additional_properties_schemaSchema?

Returns:


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

#all_ofNode::Array<Schema>?

Returns:


142
143
144
# File 'lib/openapi3_parser/node/schema.rb', line 142

def all_of
  self["allOf"]
end

#any_ofNode::Array<Schema>?

Returns:


152
153
154
# File 'lib/openapi3_parser/node/schema.rb', line 152

def any_of
  self["anyOf"]
end

#defaultAny

Returns:

  • (Any)

200
201
202
# File 'lib/openapi3_parser/node/schema.rb', line 200

def default
  self["default"]
end

#deprecated?Boolean

Returns:

  • (Boolean)

240
241
242
# File 'lib/openapi3_parser/node/schema.rb', line 240

def deprecated?
  self["deprecated"]
end

#descriptionString?

Returns:

  • (String, nil)

185
186
187
# File 'lib/openapi3_parser/node/schema.rb', line 185

def description
  self["description"]
end

#description_htmlString?

Returns:

  • (String, nil)

190
191
192
# File 'lib/openapi3_parser/node/schema.rb', line 190

def description_html
  render_markdown(description)
end

#discriminatorDiscriminator?

Returns:


210
211
212
# File 'lib/openapi3_parser/node/schema.rb', line 210

def discriminator
  self["discriminator"]
end

#enumNode::Array<Object>?

Returns:


132
133
134
# File 'lib/openapi3_parser/node/schema.rb', line 132

def enum
  self["enum"]
end

#exampleAny

Returns:

  • (Any)

235
236
237
# File 'lib/openapi3_parser/node/schema.rb', line 235

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:


230
231
232
# File 'lib/openapi3_parser/node/schema.rb', line 230

def external_docs
  self["externalDocs"]
end

#formatString?

Returns:

  • (String, nil)

195
196
197
# File 'lib/openapi3_parser/node/schema.rb', line 195

def format
  self["format"]
end

#itemsSchema?

Returns:


162
163
164
# File 'lib/openapi3_parser/node/schema.rb', line 162

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:


157
158
159
# File 'lib/openapi3_parser/node/schema.rb', line 157

def not
  self["not"]
end

#nullable?Boolean

Returns:

  • (Boolean)

205
206
207
# File 'lib/openapi3_parser/node/schema.rb', line 205

def nullable?
  self["nullable"]
end

#one_ofNode::Array<Schema>?

Returns:


147
148
149
# File 'lib/openapi3_parser/node/schema.rb', line 147

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:


167
168
169
# File 'lib/openapi3_parser/node/schema.rb', line 167

def properties
  self["properties"]
end

#read_only?Boolean

Returns:

  • (Boolean)

215
216
217
# File 'lib/openapi3_parser/node/schema.rb', line 215

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
# 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

#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)

137
138
139
# File 'lib/openapi3_parser/node/schema.rb', line 137

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)

220
221
222
# File 'lib/openapi3_parser/node/schema.rb', line 220

def write_only?
  self["writeOnly"]
end

#xmlXml?

Returns:


225
226
227
# File 'lib/openapi3_parser/node/schema.rb', line 225

def xml
  self["xml"]
end