Class: Jellyfish::Swagger
- Inherits:
-
Object
- Object
- Jellyfish::Swagger
- Includes:
- Jellyfish
- Defined in:
- lib/jellyfish/swagger.rb
Constant Summary
Constants included from Jellyfish
Instance Attribute Summary collapse
-
#jellys ⇒ Object
readonly
Returns the value of attribute jellys.
-
#path_prefix ⇒ Object
readonly
Returns the value of attribute path_prefix.
Instance Method Summary collapse
-
#initialize(path_prefix = '', *apps) ⇒ Swagger
constructor
A new instance of Swagger.
- #jellyfish_apis ⇒ Object
- #swagger_apis ⇒ Object
-
#swagger_apiVersion ⇒ Object
The application should define the API version.
-
#swagger_info ⇒ Object
The application should define the API description.
Methods included from Jellyfish
Constructor Details
#initialize(path_prefix = '', *apps) ⇒ Swagger
Returns a new instance of Swagger.
63 64 65 66 67 |
# File 'lib/jellyfish/swagger.rb', line 63 def initialize path_prefix='', *apps super(apps.first) @jellys = apps @path_prefix = path_prefix end |
Instance Attribute Details
#jellys ⇒ Object (readonly)
Returns the value of attribute jellys.
62 63 64 |
# File 'lib/jellyfish/swagger.rb', line 62 def jellys @jellys end |
#path_prefix ⇒ Object (readonly)
Returns the value of attribute path_prefix.
62 63 64 |
# File 'lib/jellyfish/swagger.rb', line 62 def path_prefix @path_prefix end |
Instance Method Details
#jellyfish_apis ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jellyfish/swagger.rb', line 69 def jellyfish_apis @jellyfish_apis ||= jellys.flat_map{ |j| j.routes.flat_map{ |meth, routes| routes.map{ |(path, _, )| .merge(operation(meth, path, )) } } }.group_by{ |api| api[:path] }. inject(Hash.new{[]}){ |r, (path, operations)| r[path] = operations.group_by{ |op| op[:nickname] } r } end |
#swagger_apis ⇒ Object
56 57 58 59 60 |
# File 'lib/jellyfish/swagger.rb', line 56 def swagger_apis @swagger_apis ||= jellyfish_apis.keys.map do |name| {:path => name} end end |
#swagger_apiVersion ⇒ Object
The application should define the API version.
48 49 50 51 52 53 54 |
# File 'lib/jellyfish/swagger.rb', line 48 def swagger_apiVersion if app.respond_to?(:swagger_apiVersion) app.swagger_apiVersion else '0.1.0' end end |
#swagger_info ⇒ Object
The application should define the API description.
39 40 41 42 43 44 45 |
# File 'lib/jellyfish/swagger.rb', line 39 def swagger_info if app.respond_to?(:info) app.info else {} end end |