class OpenapiValidator::ResponseValidator::ImageValidator
Attributes
data[R]
fragment[R]
media_type[R]
property_name[R]
response[R]
schema[R]
Public Class Methods
new(schema:, data:, fragment:, media_type:, response:)
click to toggle source
# File lib/openapi_validator/response_validators/image_validator.rb, line 4 def initialize(schema:, data:, fragment:, media_type:, response:) @schema = schema @data = data @fragment = fragment @media_type = media_type @response = response @property_name = JSON::Schema::Attribute.build_fragment([fragment]) @errors = [] end
Public Instance Methods
validate()
click to toggle source
# File lib/openapi_validator/response_validators/image_validator.rb, line 14 def validate validate_media_type validate_schema @errors end
Private Instance Methods
validate_media_type()
click to toggle source
# File lib/openapi_validator/response_validators/image_validator.rb, line 25 def validate_media_type type, sub_type = media_type.split("/") content = MimeMagic.by_magic(data) if content&.mediatype != type && (content&.subtype == sub_type || sub_type == "*") @errors << "Content-type of property '#{property_name}' did not match the following content-type: #{media_type}" end end
validate_schema()
click to toggle source
# File lib/openapi_validator/response_validators/image_validator.rb, line 34 def validate_schema unless JSON::Schema::Attribute.data_valid_for_type?(data, "string") @errors << "The property '#{property_name}' did not match the following type: #{type}" end end