Sha256: d8b79df8449527be85a335ad84563c124971382b18f4329d47d8c206ed79a6c7
Contents?: true
Size: 1.1 KB
Versions: 7
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true require "openapi3_parser/node_factory/map" module Openapi3Parser module NodeFactory class Responses < NodeFactory::Map KEY_REGEX = / \A ( default | [1-5]([0-9][0-9]|XX) ) \Z /x.freeze def initialize(context) factory = NodeFactory::OptionalReference.new(NodeFactory::Response) super(context, allow_extensions: true, value_factory: factory, validate: :validate_keys) end private def build_node(data, node_context) Node::Responses.new(data, node_context) end 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 end end end
Version data entries
7 entries across 7 versions & 2 rubygems