Sha256: 0af53f70cd54aceee973454355c77a3429df374334b1da708dbd15d5c293c6bd

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

module OpenApi
  class Response
    prepend EquatableAsContent

    attr_accessor :description, :headers, :content, :links

    def initialize(description:, headers: nil, content: nil, links: nil)
      self.description = description
      self.headers = headers&.with_indifferent_access
      self.content = content&.with_indifferent_access
      self.links = links&.with_indifferent_access
    end

    def serializable_hash
      {
        "description" => description.to_s,
        "headers" => headers&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
        "content" => content&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
        "links" => links&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
      }.compact
    end

    def self.load(hash)
      return unless hash

      new(
        description: hash["description"].to_s,
        headers: hash["headers"]&.map { |k, v| [k, Header.load(v)] }&.to_h,
        content: hash["content"]&.map { |k, v| [k, MediaType.load(v)] }&.to_h,
        links: hash["links"]&.map { |k, v| [k, Reference.load(v) || Link.load(v)] }&.to_h,
      )
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
open_api-0.6.2 lib/open_api/response.rb
open_api-0.6.1 lib/open_api/response.rb
open_api-0.6.0 lib/open_api/response.rb
open_api-0.5.0 lib/open_api/response.rb
open_api-0.4.0 lib/open_api/response.rb
open_api-0.3.4 lib/open_api/response.rb
open_api-0.3.3 lib/open_api/response.rb
open_api-0.3.2 lib/open_api/response.rb
open_api-0.3.1 lib/open_api/response.rb
open_api-0.3.0 lib/open_api/response.rb
open_api-0.2.0 lib/open_api/response.rb
open_api-0.1.0 lib/open_api/response.rb