Sha256: 01a6297071cd01a7f1e166626ef614851b2016594c2685f118a8845fc8b49f77

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

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, :code, :media_type
      def initialize(desc, media_type, hash)
        @hash = hash
        @mt = media_type
        self.code       = code.to_s
        self.media_type = MediaTypeObj.new(media_type, hash)
        self.processed  = { description: desc }
      end

      def process
        assign(media_type.process).to_processed 'content'
        processed
      end

      def override(type_hash)
        @hash[:type].merge!(type_hash)
        self.media_type = MediaTypeObj.new(@mt, @hash)
        self
      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

3 entries across 3 versions & 1 rubygems

Version Path
zero-rails_openapi-1.4.2 lib/oas_objs/response_obj.rb
zero-rails_openapi-1.4.1 lib/oas_objs/response_obj.rb
zero-rails_openapi-1.4.0 lib/oas_objs/response_obj.rb