Sha256: bd36bbef0f002042b2ea18ae14be961cb6764371184b37e97ae6aa584682fe9f

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'oas_objs/media_type_obj'
require 'oas_objs/helpers'

module OpenApi
  module DSL
    # https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#responseObject
    class ResponseObj < Hash
      include Helpers

      attr_accessor :processed, :media_types
      def initialize(desc)
        self.media_types = [ ]
        self.processed   = { description: desc }
      end

      def absorb(desc, media_type, hash)
        self.processed[:description] = desc if desc.present?
        media_types << MediaTypeObj.new(media_type, hash)
        self
      end

      def process
        content = media_types.map(&:process).reduce({ }, &fusion)
        processed[:content] = content if content.present?
        processed
      end
    end
  end
end


__END__

Response Object Examples

Response of an array of a complex type:

{
  "description": "A complex object array response",
  "content": {
    "application/json": {
      "schema": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/VeryComplexType"
        }
      }
    }
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zero-rails_openapi-2.0.3 lib/oas_objs/response_obj.rb
zero-rails_openapi-2.0.2 lib/oas_objs/response_obj.rb
zero-rails_openapi-2.0.1 lib/oas_objs/response_obj.rb
zero-rails_openapi-2.0.0 lib/oas_objs/response_obj.rb