class Openapi3Parser::NodeFactory::Responses

Constants

KEY_REGEX

Public Class Methods

new(context) click to toggle source
Calls superclass method Openapi3Parser::NodeFactory::Map::new
# File lib/openapi3_parser/node_factory/responses.rb, line 18
def initialize(context)
  factory = NodeFactory::OptionalReference.new(NodeFactory::Response)

  super(context,
        allow_extensions: true,
        value_factory: factory,
        validate: :validate_keys)
end

Private Instance Methods

build_node(data, node_context) click to toggle source
# File lib/openapi3_parser/node_factory/responses.rb, line 29
def build_node(data, node_context)
  Node::Responses.new(data, node_context)
end
validate_keys(validatable) click to toggle source
# File lib/openapi3_parser/node_factory/responses.rb, line 33
def validate_keys(validatable)
  invalid = validatable.input.keys.reject do |key|
    NodeFactory::EXTENSION_REGEX.match(key) ||
      KEY_REGEX.match(key)
  end

  return if invalid.empty?

  codes = invalid.map { |k| "'#{k}'" }.join(", ")
  validatable.add_error("Invalid responses keys: #{codes} - default, "\
                        "status codes and status code ranges allowed")
end