Sha256: 8c5440d90f9759a1948e45a642a7110da0e024520119c4b2f1a33d881e1b23ce

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 KB

Contents

class OpenAPIParser::Config
  def initialize(config)
    # TODO: This deprecation warning can be removed after we set the default to `true`
    # in a later (major?) version update.
    unless config.key?(:strict_reference_validation)
      msg = "[DEPRECATION] strict_reference_validation config is not set. It defaults to `false` now, " +
          "but will be `true` in a future version. Please explicitly set to `false` " +
          "if you want to skip reference validation on schema load."
      warn(msg)
    end
    @config = config
  end

  def datetime_coerce_class
    @config[:datetime_coerce_class]
  end

  def coerce_value
    @config[:coerce_value]
  end

  def expand_reference
    @config.fetch(:expand_reference, true)
  end

  def strict_response_validation
    # TODO: in a major version update, change this to default to `true`.
    # https://github.com/ota42y/openapi_parser/pull/123/files#r767142217
    @config.fetch(:strict_response_validation, false)
  end

  def strict_reference_validation
    @config.fetch(:strict_reference_validation, false)
  end

  def validate_header
    @config.fetch(:validate_header, true)
  end

  # @return [OpenAPIParser::SchemaValidator::Options]
  def request_validator_options
    @request_validator_options ||= OpenAPIParser::SchemaValidator::Options.new(coerce_value: coerce_value,
                                                                               datetime_coerce_class: datetime_coerce_class,
                                                                               validate_header: validate_header)
  end

  alias_method :request_body_options, :request_validator_options
  alias_method :path_params_options, :request_validator_options

  # @return [OpenAPIParser::SchemaValidator::ResponseValidateOptions]
  def response_validate_options
    @response_validate_options ||= OpenAPIParser::SchemaValidator::ResponseValidateOptions.
                                     new(strict: strict_response_validation, validate_header: validate_header)
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
openapi_parser-2.2.3 lib/openapi_parser/config.rb
openapi_parser-2.2.2 lib/openapi_parser/config.rb
openapi_parser-2.2.1 lib/openapi_parser/config.rb
openapi_parser-2.2.0 lib/openapi_parser/config.rb
openapi_parser-2.1.0 lib/openapi_parser/config.rb
openapi_parser-2.0.0 lib/openapi_parser/config.rb
openapi_parser_firetail-1.0.0 lib/openapi_parser/config.rb
openapi_parser-1.0.0 lib/openapi_parser/config.rb
openapi_parser-1.0.0.beta1 lib/openapi_parser/config.rb