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
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 172 def additional_properties? self["additionalProperties"] != false end
@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
@return [Node::Array<Schema>, nil]
# File lib/openapi3_parser/node/schema.rb, line 142 def all_of self["allOf"] end
@return [Node::Array<Schema>, nil]
# File lib/openapi3_parser/node/schema.rb, line 152 def any_of self["anyOf"] end
@return [Any]
# File lib/openapi3_parser/node/schema.rb, line 200 def default self["default"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 240 def deprecated? self["deprecated"] end
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 185 def description self["description"] end
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 190 def description_html render_markdown(description) end
@return [Discriminator, nil]
# File lib/openapi3_parser/node/schema.rb, line 210 def discriminator self["discriminator"] end
@return [Node::Array<Object>, nil]
# File lib/openapi3_parser/node/schema.rb, line 132 def enum self["enum"] end
@return [Any]
# File lib/openapi3_parser/node/schema.rb, line 235 def example self["example"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 57 def exclusive_maximum? self["exclusiveMaximum"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 67 def exclusive_minimum? self["exclusiveMinimum"] end
@return [ExternalDocumentation, nil]
# File lib/openapi3_parser/node/schema.rb, line 230 def external_docs self["externalDocs"] end
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 195 def format self["format"] end
@return [Schema, nil]
# File lib/openapi3_parser/node/schema.rb, line 162 def items self["items"] end
@return [Integer, nil]
# File lib/openapi3_parser/node/schema.rb, line 87 def max_items self["maxItems"] end
@return [Integer, nil]
# File lib/openapi3_parser/node/schema.rb, line 72 def max_length self["maxLength"] end
@return [Integer, nil]
# File lib/openapi3_parser/node/schema.rb, line 102 def max_properties self["maxProperties"] end
@return [Integer, nil]
# File lib/openapi3_parser/node/schema.rb, line 52 def maximum self["maximum"] end
@return [Integer]
# File lib/openapi3_parser/node/schema.rb, line 92 def min_items self["minItems"] end
@return [Integer]
# File lib/openapi3_parser/node/schema.rb, line 77 def min_length self["minLength"] end
@return [Integer]
# File lib/openapi3_parser/node/schema.rb, line 107 def min_properties self["minProperties"] end
@return [Integer, nil]
# File lib/openapi3_parser/node/schema.rb, line 62 def minimum self["minimum"] end
@return [Numeric, nil]
# File lib/openapi3_parser/node/schema.rb, line 47 def multiple_of self["multipleOf"] end
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
@return [Schema, nil]
# File lib/openapi3_parser/node/schema.rb, line 157 def not self["not"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 205 def nullable? self["nullable"] end
@return [Node::Array<Schema>, nil]
# File lib/openapi3_parser/node/schema.rb, line 147 def one_of self["oneOf"] end
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 82 def pattern self["pattern"] end
@return [Map<String, Schema>]
# File lib/openapi3_parser/node/schema.rb, line 167 def properties self["properties"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 215 def read_only? self["readOnly"] end
@return [Node::Array<String>, nil]
# File lib/openapi3_parser/node/schema.rb, line 112 def required self["required"] end
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
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 42 def title self["title"] end
@return [String, nil]
# File lib/openapi3_parser/node/schema.rb, line 137 def type self["type"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 97 def unique_items? self["uniqueItems"] end
@return [Boolean]
# File lib/openapi3_parser/node/schema.rb, line 220 def write_only? self["writeOnly"] end
@return [Xml, nil]
# File lib/openapi3_parser/node/schema.rb, line 225 def xml self["xml"] end