Class: OpenAPIParser::Schemas::Response

Inherits:
Base
  • Object
show all
Includes:
MediaTypeSelectable
Defined in:
lib/openapi_parser/schemas/classes.rb,
lib/openapi_parser/schemas/response.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#object_reference, #parent, #raw_schema, #root

Instance Method Summary collapse

Methods inherited from Base

#after_init, #initialize, #inspect

Methods included from Expandable

#expand_reference

Methods included from Findable

#find_object, #purge_object_cache

Methods included from Parser

#_openapi_all_child_objects, #_update_child_object, included, #load_data

Constructor Details

This class inherits a constructor from OpenAPIParser::Schemas::Base

Instance Attribute Details

#contentHash{String => MediaType}? (readonly)

Returns content_type to MediaType hash.

Returns:

  • (Hash{String => MediaType}, nil)

    content_type to MediaType hash



11
# File 'lib/openapi_parser/schemas/response.rb', line 11

openapi_attr_hash_object :content, MediaType, reference: false

#headersHash{String => Header}? (readonly)

Returns header string to Header.

Returns:

  • (Hash{String => Header}, nil)

    header string to Header



15
# File 'lib/openapi_parser/schemas/response.rb', line 15

openapi_attr_hash_object :headers, Header, reference: true

Instance Method Details

#select_media_type(content_type) ⇒ OpenAPIParser::Schemas::MediaType?

select media type by content_type (consider wild card definition)

Parameters:

  • content_type (String)

Returns:



38
39
40
# File 'lib/openapi_parser/schemas/response.rb', line 38

def select_media_type(content_type)
  select_media_type_from_content(content_type, content)
end

#validate(response_body, response_validate_options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/openapi_parser/schemas/response.rb', line 19

def validate(response_body, response_validate_options)
  validate_header(response_body.headers) if response_validate_options.validate_header

  media_type = select_media_type(response_body.content_type)
  unless media_type
    if response_validate_options.strict && response_body_not_blank(response_body)
      raise ::OpenAPIParser::NotExistContentTypeDefinition, object_reference
    end

    return true
  end

  options = ::OpenAPIParser::SchemaValidator::Options.new # response validator not support any options
  media_type.validate_parameter(response_body.response_data, options)
end