class Openapi3Parser::Node::Schema

@see github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject rubocop:disable Metrics/ClassLength

Public Instance Methods

additional_properties?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 172
def additional_properties?
  self["additionalProperties"] != false
end
additional_properties_schema() click to toggle source

@return [Schema, nil]

# 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_of() click to toggle source

@return [Node::Array<Schema>, nil]

# File lib/openapi3_parser/node/schema.rb, line 142
def all_of
  self["allOf"]
end
any_of() click to toggle source

@return [Node::Array<Schema>, nil]

# File lib/openapi3_parser/node/schema.rb, line 152
def any_of
  self["anyOf"]
end
default() click to toggle source

@return [Any]

# File lib/openapi3_parser/node/schema.rb, line 200
def default
  self["default"]
end
deprecated?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 240
def deprecated?
  self["deprecated"]
end
description() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 185
def description
  self["description"]
end
description_html() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 190
def description_html
  render_markdown(description)
end
discriminator() click to toggle source

@return [Discriminator, nil]

# File lib/openapi3_parser/node/schema.rb, line 210
def discriminator
  self["discriminator"]
end
enum() click to toggle source

@return [Node::Array<Object>, nil]

# File lib/openapi3_parser/node/schema.rb, line 132
def enum
  self["enum"]
end
example() click to toggle source

@return [Any]

# File lib/openapi3_parser/node/schema.rb, line 235
def example
  self["example"]
end
exclusive_maximum?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 57
def exclusive_maximum?
  self["exclusiveMaximum"]
end
exclusive_minimum?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 67
def exclusive_minimum?
  self["exclusiveMinimum"]
end
external_docs() click to toggle source

@return [ExternalDocumentation, nil]

# File lib/openapi3_parser/node/schema.rb, line 230
def external_docs
  self["externalDocs"]
end
format() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 195
def format
  self["format"]
end
items() click to toggle source

@return [Schema, nil]

# File lib/openapi3_parser/node/schema.rb, line 162
def items
  self["items"]
end
max_items() click to toggle source

@return [Integer, nil]

# File lib/openapi3_parser/node/schema.rb, line 87
def max_items
  self["maxItems"]
end
max_length() click to toggle source

@return [Integer, nil]

# File lib/openapi3_parser/node/schema.rb, line 72
def max_length
  self["maxLength"]
end
max_properties() click to toggle source

@return [Integer, nil]

# File lib/openapi3_parser/node/schema.rb, line 102
def max_properties
  self["maxProperties"]
end
maximum() click to toggle source

@return [Integer, nil]

# File lib/openapi3_parser/node/schema.rb, line 52
def maximum
  self["maximum"]
end
min_items() click to toggle source

@return [Integer]

# File lib/openapi3_parser/node/schema.rb, line 92
def min_items
  self["minItems"]
end
min_length() click to toggle source

@return [Integer]

# File lib/openapi3_parser/node/schema.rb, line 77
def min_length
  self["minLength"]
end
min_properties() click to toggle source

@return [Integer]

# File lib/openapi3_parser/node/schema.rb, line 107
def min_properties
  self["minProperties"]
end
minimum() click to toggle source

@return [Integer, nil]

# File lib/openapi3_parser/node/schema.rb, line 62
def minimum
  self["minimum"]
end
multiple_of() click to toggle source

@return [Numeric, nil]

# File lib/openapi3_parser/node/schema.rb, line 47
def multiple_of
  self["multipleOf"]
end
name() click to toggle source

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)

@return [String, nil]

# 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
not() click to toggle source

@return [Schema, nil]

# File lib/openapi3_parser/node/schema.rb, line 157
def not
  self["not"]
end
nullable?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 205
def nullable?
  self["nullable"]
end
one_of() click to toggle source

@return [Node::Array<Schema>, nil]

# File lib/openapi3_parser/node/schema.rb, line 147
def one_of
  self["oneOf"]
end
pattern() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 82
def pattern
  self["pattern"]
end
properties() click to toggle source

@return [Map<String, Schema>]

# File lib/openapi3_parser/node/schema.rb, line 167
def properties
  self["properties"]
end
read_only?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 215
def read_only?
  self["readOnly"]
end
required() click to toggle source

@return [Node::Array<String>, nil]

# File lib/openapi3_parser/node/schema.rb, line 112
def required
  self["required"]
end
requires?(property) click to toggle source

Returns whether a property is a required field or not. Can accept the property name or a schema

@param [String, Schema] property @return [Boolean]

# 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() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 42
def title
  self["title"]
end
type() click to toggle source

@return [String, nil]

# File lib/openapi3_parser/node/schema.rb, line 137
def type
  self["type"]
end
unique_items?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 97
def unique_items?
  self["uniqueItems"]
end
write_only?() click to toggle source

@return [Boolean]

# File lib/openapi3_parser/node/schema.rb, line 220
def write_only?
  self["writeOnly"]
end
xml() click to toggle source

@return [Xml, nil]

# File lib/openapi3_parser/node/schema.rb, line 225
def xml
  self["xml"]
end