Sha256: 19b179215d609440a62f85a512e8015ad1edf0ad64dd91f28a0d010f095db339

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

require_relative 'base'

module Swaggard
  module Swagger
    module Parameters
      class List < Base

        def initialize(string)
          @in = 'query'
          parse(string)
        end

        def to_doc
          doc = super

          doc.merge(
            {
              'type'            => 'array',
              'items'           => { 'type' => @data_type },
              'enum'            => @list_values
            }
          )
        end

        private

        # Example: [String]    sort_order  Orders ownerships by fields. (e.g. sort_order=created_at)
        #          [List]      id
        #          [List]      begin_at
        #          [List]      end_at
        #          [List]      created_at
        def parse(string)
          data_type, name, required, description, set_string = string.match(/\A\[(\w*)\]\s*(\w*)(\(required\))?\s*(.*)\n([.\s\S]*)\Z/).captures

          @list_values = set_string.split('[List]').map(&:strip).reject { |string| string.empty? }

          @name = name
          @description = description
          @data_type = data_type.downcase
          @is_required = required.present?
        end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
swaggard-0.5.4 lib/swaggard/swagger/parameters/list.rb
swaggard-0.5.3 lib/swaggard/swagger/parameters/list.rb
swaggard-0.5.2 lib/swaggard/swagger/parameters/list.rb
swaggard-0.5.1 lib/swaggard/swagger/parameters/list.rb
swaggard-0.5.0 lib/swaggard/swagger/parameters/list.rb
swaggard-0.4.0 lib/swaggard/swagger/parameters/list.rb
swaggard-0.3.0 lib/swaggard/swagger/parameters/list.rb
swaggard-0.2.1 lib/swaggard/swagger/parameters/list.rb
swaggard-0.2.0 lib/swaggard/swagger/parameters/list.rb
swaggard-0.1.1 lib/swaggard/swagger/parameters/list.rb
swaggard-0.1.0 lib/swaggard/swagger/parameters/list.rb
swaggard-0.0.4 lib/swaggard/swagger/parameters/list.rb