class OpenapiValidator::ResponseValidator

Attributes

data[R]
errors[R]
fragment[R]
media_type[R]
request[R]
response[R]
schema[R]

Public Class Methods

call(**params) click to toggle source
# File lib/openapi_validator/response_validator.rb, line 12
def self.call(**params)
  new(**params).call
end
new(request:, schema:, data:, fragment:, response:, media_type:) click to toggle source
# File lib/openapi_validator/response_validator.rb, line 25
def initialize(request:, schema:, data:, fragment:, response:, media_type:)
  @request = request
  @schema = schema
  @data = data
  @media_type = media_type
  @fragment = fragment
  @response = response
  @errors = []
end

Public Instance Methods

call() click to toggle source
# File lib/openapi_validator/response_validator.rb, line 16
def call
  validate_response
  self
end
valid?() click to toggle source
# File lib/openapi_validator/response_validator.rb, line 8
def valid?
  errors.empty?
end

Private Instance Methods

validate_response() click to toggle source
# File lib/openapi_validator/response_validator.rb, line 35
def validate_response
  @errors += validator.new(schema: schema, data: data, fragment: fragment, media_type: media_type, response: response).validate
end
validator() click to toggle source
# File lib/openapi_validator/response_validator.rb, line 39
def validator
  case media_type
  when %r{^image/[^/]*$}
    OpenapiValidator::ResponseValidator::ImageValidator
  else
    OpenapiValidator::ResponseValidator::JsonValidator
  end
end