Sha256: 2f98ccb032ceee6db8cb2192f500fdad4dabe2cd4a0e1d8849a51989a9d4179d

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

module OpenAPIParser::MediaTypeSelectable
  private

    # select media type by content_type (consider wild card definition)
    # @param [String] content_type
    # @param [Hash{String => OpenAPIParser::Schemas::MediaType}] content
    # @return [OpenAPIParser::Schemas::MediaType, nil]
    def select_media_type_from_content(content_type, content)
      return nil unless content_type

      if (media_type = content[content_type])
        return media_type
      end

      # application/json => [application, json]
      splited = content_type.split('/')

      if (media_type = content["#{splited.first}/*"])
        return media_type
      end

      if (media_type = content['*/*'])
        return media_type
      end

      nil
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openapi_parser-0.1.9 lib/openapi_parser/concerns/media_type_selectable.rb
openapi_parser-0.1.8 lib/openapi_parser/concerns/media_type_selectable.rb