Sha256: 0c35f48e0f8e7dfb52824bf40958dc0d0b25deebf9a5a939ad3a7e765e1c912e

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module WeakSwaggerParameters
  module Definitions
    class Response
      def initialize(status_code, description, &block)
        @status_code = status_code
        @description = description
        @content_schema = nil

        instance_eval(&block) if block.present?
      end

      def hash(&block)
        @content_schema = WeakSwaggerParameters::Definitions::HashRef.new(&block)
      end

      def model(model_class)
        @content_schema = WeakSwaggerParameters::Definitions::ModelRef.new(model_class)
      end

      def collection(model_class)
        @content_schema = WeakSwaggerParameters::Definitions::CollectionRef.new(model_class)
      end

      def apply_docs(parent_node)
        status_code = @status_code
        response_options = { description: @description }
        content_schema = @content_schema

        parent_node.instance_eval do
          response status_code, response_options do
            response_node = self

            content_schema.apply_docs(response_node) if content_schema.present?
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weak_swagger_parameters-0.6.0 lib/weak_swagger_parameters/definitions/response.rb
weak_swagger_parameters-0.5.0 lib/weak_swagger_parameters/definitions/response.rb