Class: Skooma::Objects::Parameter::Keywords::Content
- Inherits:
-
Header::Keywords::Content
- Object
- JSONSkooma::Keywords::Base
- Header::Keywords::Content
- Skooma::Objects::Parameter::Keywords::Content
- Defined in:
- lib/skooma/objects/parameter/keywords/content.rb
Instance Method Summary collapse
Instance Method Details
#evaluate(instance, result) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/skooma/objects/parameter/keywords/content.rb', line 13 def evaluate(instance, result) return if instance.value.nil? value = ValueParser.call(instance, result) return result.discard if value.nil? # A parameter's `content` declares the media type its value is # serialized in (typically exactly one entry). Parse the raw value # with the matching body parser, then validate the parsed value # against that media type's schema. (The header version picks the # media type from the response Content-Type, which is wrong here.) json.each do |media_type, media_type_object| parsed = Instance::Attribute.new( BodyParsers[media_type].call(value.value), key: value.key, parent: value.parent ) result.call(parsed, media_type) do |media_type_result| media_type_object.evaluate(parsed, media_type_result) result.failure("Invalid content for media type #{media_type}") unless media_type_result.passed? end end end |