Sha256: 9dee69e3f905464ffd7ce7295c3adc94e65714f3bac4a98b96d271839bea1d3e

Contents?: true

Size: 1.17 KB

Versions: 10

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

10 entries across 10 versions & 1 rubygems

Version Path
swaggard-1.5.1 lib/swaggard/swagger/parameters/list.rb
swaggard-1.5.0 lib/swaggard/swagger/parameters/list.rb
swaggard-1.4.0 lib/swaggard/swagger/parameters/list.rb
swaggard-1.3.0 lib/swaggard/swagger/parameters/list.rb
swaggard-1.2.0 lib/swaggard/swagger/parameters/list.rb
swaggard-1.1.1 lib/swaggard/swagger/parameters/list.rb
swaggard-1.1.0 lib/swaggard/swagger/parameters/list.rb
swaggard-1.0.2 lib/swaggard/swagger/parameters/list.rb
swaggard-1.0.1 lib/swaggard/swagger/parameters/list.rb
swaggard-1.0.0 lib/swaggard/swagger/parameters/list.rb