Class: Swaggard::Swagger::Operation
- Inherits:
-
Object
- Object
- Swaggard::Swagger::Operation
- Defined in:
- lib/swaggard/swagger/operation.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#error_responses ⇒ Object
Returns the value of attribute error_responses.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#path ⇒ Object
Returns the value of attribute path.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #definitions ⇒ Object
-
#initialize(yard_object, tag, routes) ⇒ Operation
constructor
A new instance of Operation.
- #to_doc ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(yard_object, tag, routes) ⇒ Operation
Returns a new instance of Operation.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/swaggard/swagger/operation.rb', line 17 def initialize(yard_object, tag, routes) @name = yard_object.name @tag = tag @summary = yard_object.docstring.lines.first || '' @parameters = [] @responses = [] @description = (yard_object.docstring.lines[1..-1] || []).join("\n") @formats = Swaggard.configuration.api_formats yard_object..each do |yard_tag| value = yard_tag.text case yard_tag.tag_name when 'query_parameter' @parameters << Parameters::Query.new(value) when 'form_parameter' @parameters << Parameters::Form.new(value) when 'body_parameter' body_parameter.add_property(value) when 'parameter_list' @parameters << Parameters::List.new(value) when 'response_class' success_response.response_class = value when 'response_status' success_response.status_code = value when 'response_root' success_response.response_root = value end end build_path_parameters(routes) @parameters.sort_by { |parameter| parameter.name } @responses << success_response end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def description @description end |
#error_responses ⇒ Object
Returns the value of attribute error_responses.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def error_responses @error_responses end |
#http_method ⇒ Object
Returns the value of attribute http_method.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def http_method @http_method end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
13 14 15 |
# File 'lib/swaggard/swagger/operation.rb', line 13 def nickname @nickname end |
#notes ⇒ Object
Returns the value of attribute notes.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def notes @notes end |
#parameters ⇒ Object
Returns the value of attribute parameters.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def parameters @parameters end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def path @path end |
#summary ⇒ Object
Returns the value of attribute summary.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def summary @summary end |
#tag ⇒ Object
Returns the value of attribute tag.
14 15 16 |
# File 'lib/swaggard/swagger/operation.rb', line 14 def tag @tag end |
Instance Method Details
#definitions ⇒ Object
74 75 76 77 78 |
# File 'lib/swaggard/swagger/operation.rb', line 74 def definitions @responses.map(&:definition).compact.tap do |definitions| definitions << @body_parameter.definition if @body_parameter end end |
#to_doc ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/swaggard/swagger/operation.rb', line 58 def to_doc produces = @formats.map { |format| "application/#{format}" } consumes = @formats.map { |format| "application/#{format}" } { 'tags' => [@tag.name], 'summary' => @summary, 'description' => @description, 'operationId' => @name, 'consumes' => consumes, 'produces' => produces, 'parameters' => @parameters.map(&:to_doc), 'responses' => Hash[@responses.map { |response| [response.status_code, response.to_doc] }] } end |
#valid? ⇒ Boolean
54 55 56 |
# File 'lib/swaggard/swagger/operation.rb', line 54 def valid? @path.present? end |