Module: RSpec::Rails::Swagger::Helpers::Parameters

Defined in:
lib/rspec/rails/swagger/helpers.rb

Instance Method Summary collapse

Instance Method Details

#parameter(name, attributes = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rspec/rails/swagger/helpers.rb', line 103

def parameter name, attributes = {}
  attributes.symbolize_keys!

  # Look for $refs
  if name.respond_to?(:has_key?)
    ref = name.delete(:ref) || name.delete('ref')
    full_param = resolve_document().resolve_ref(ref)

    validate_parameter! full_param

    param = { '$ref' => ref }
    key = parameter_key(full_param)
  else
    validate_parameter! attributes

    # Path attributes are always required
    attributes[:required] = true if attributes[:in] == :path

    param = { name: name.to_s }.merge(attributes)
    key = parameter_key(param)
  end

  parameters_for_object[key] = param
end

#resolve_document(metadata) ⇒ Object



128
129
130
131
132
133
# File 'lib/rspec/rails/swagger/helpers.rb', line 128

def resolve_document 
  # TODO: It's really inefficient to keep recreating this. It'd be nice
  # if we could cache them some place.
  name = [:swagger_doc]
  Document.new(RSpec.configuration.swagger_docs[name])
end