Sha256: 8ad26d3d7cd2c2239832b57f0ceb349e26750e4b8a85b342e82cfc17ad35fc9f

Contents?: true

Size: 994 Bytes

Versions: 7

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

# :reek:InstanceVariableAssumption
# :reek:NilCheck

module SwaggerDocsGenerator
  module Actions
    # Write parameter type :header
    class Header < Parameter
      FIELDS = %w[description format default enum].freeze

      def to_hash
        {
          in:               :header,
          name:             @name,
          required:         @required.nil? ? true : @required,
          type:             @type
        }.merge(no_mandatory_field)
      end

      private

      def type(text)
        @type = text
      end

      def default(text)
        @default = text
      end

      def enum(array)
        @enum = array
      end

      def format(text)
        @format = text
      end

      def no_mandatory_field
        hash = {}
        FIELDS.each do |parameter|
          value = instance_variable_get("@#{parameter}")
          hash.merge!(parameter.to_sym => value) if value.present?
        end
        hash
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
swagger_docs_generator-0.5.1 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.5.0.pre.42 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.4.0 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.3.6 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.3.6.pre.34 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.3.5 lib/swagger_docs_generator/parser/actions/parameters/header.rb
swagger_docs_generator-0.3.5.pre.31 lib/swagger_docs_generator/parser/actions/parameters/header.rb