Class: Swagger::Blocks::ApiDeclarationNode
- Defined in:
- lib/swagger/blocks.rb
Overview
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
Methods inherited from Node
#as_json, call, #data, #is_swagger_1_2?, #is_swagger_2_0?, #key
Instance Method Details
#api(&block) ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/swagger/blocks.rb', line 450 def api(&block) self.data[:apis] ||= [] # Important: to conform with the Swagger spec, merge with any previous API declarations # that have the same :path key. This ensures that operations affecting the same resource # are all in the same operations node. # # http://goo.gl/PvwUXj#522-api-object # - The API Object describes one or more operations on a single path. In the apis array, # there MUST be only one API Object per path. temp_api_node = Swagger::Blocks::ApiNode.call(version: version, &block) api_node = self.data[:apis].select do |api| api.data[:path] == temp_api_node.data[:path] end[0] # Embrace Ruby wtfs. if api_node # Merge this block with the previous ApiNode by the same path key. api_node.instance_eval(&block) else # First time we've seen an api block with the given path key. self.data[:apis] << temp_api_node end end |