Class: Swagger::Operation
- Inherits:
-
Object
- Object
- Swagger::Operation
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- lib/swagger/operation.rb
Constant Summary collapse
- HTTP_METHODS =
["GET","POST","PUT","DELETE"]
- ALLOWABLE_VALUES_VALUE_TYPES =
["LIST", "RANGE"]
- CONTAINERS =
['List', 'Set', 'Array']
- PRIMITIVES =
['byte', 'boolean', 'int', 'long', 'float', 'double', 'string', 'Date']
- PARAM_TYPES =
{ 'body' => {:types => ['complex', 'container'], :allowMultipleAllowed => false}, 'path' => {:types => PRIMITIVES, :allowMultipleAllowed => false}, 'query' => {:types => PRIMITIVES, :allowMultipleAllowed => true}, 'header' => {:types => PRIMITIVES, :allowMultipleAllowed => false} }
Instance Method Summary collapse
- #as_json(options) ⇒ Object
-
#initialize(api, http_method, opts = {}) ⇒ Operation
constructor
A new instance of Operation.
- #param(name, opts = {}) ⇒ Object
Constructor Details
#initialize(api, http_method, opts = {}) ⇒ Operation
Returns a new instance of Operation.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/swagger/operation.rb', line 19 def initialize api, http_method, opts = {} bomb("#{http_method} not valid. httpMethod must be one of: #{HTTP_METHODS}") unless HTTP_METHODS.include?(http_method) defaults = { :nickname => api.path.split('/').last, :httpMethod => http_method, :parameters => [], :summary => "" } values = defaults.merge opts values[:notes] = simple_format(values[:notes]) if values[:notes] @values = values end |
Instance Method Details
#as_json(options) ⇒ Object
57 58 59 |
# File 'lib/swagger/operation.rb', line 57 def as_json @values.as_json end |
#param(name, opts = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/swagger/operation.rb', line 32 def param name, opts = {} defaults = { :name => name, :description => name, :required => false, :allowMultiple => false, :dataType => "string", :paramType => "query" } if list = opts.delete(:list) defaults.merge!(:allowableValues => {:values => list, :valueType => "LIST"}) end if range = opts.delete(:range) defaults.merge!(:allowableValues => {:min => range.first, :max => range.last, :valueType => "RANGE"}) end result = defaults.merge(opts) bomb("#{result[:dataType]} not valid. dataType must be one of #{PRIMITIVES.inspect}") unless PRIMITIVES.include?(result[:dataType]) bomb("#{result[:paramType]} not valid. paramType must be one of #{PARAM_TYPES.keys.inspect}") unless PARAM_TYPES.keys.include?(result[:paramType]) bomb("allowMultiple not allowed for paramType #{result[:paramType]}") if result[:allowMultiple] && !PARAM_TYPES[result[:paramType]][:allowMultipleAllowed] @values[:parameters] << result end |